CI: cache microsoft fonts#35
Conversation
|
Reviews (1): Last reviewed commit: "CI: cache microsoft fonts" | Re-trigger Greptile |
* store cached files in user-writable path and copy to root-owned directory * add step to separate font install via download vs. from cache
|
Reviews (2): Last reviewed commit: "MAINT, CI: address AI reviewer comment" | Re-trigger Greptile |
|
If you use AI in your original commit(s), please disclose (i.e., AI/no AI), thanks. |
Should give a little more detail -- like "Claude wrote most of the code in this PR and I checked it myself by doing X" or something like that. |
|
The point is that you're responsible for understanding the code and not just dumping it on the reviewer, so I'll use those statements to make sure the LLM code isn't just being thrown at me without understanding (otherwise it'll be sent back for revision/closed). |
|
Maybe communicate how you know this is working--did you test it on your fork? It is clear from the log that it is working? Make that clear to the reviewer, otherwise mark it as WIP until it is confidently ready for review. |
|
To check that this is working, I allowed the CI to run here for the intial cache fonts: Run actions/cache@v5
Cache hit for: Linux-msttcorefonts-v1
Received 5088242 of 5088242 (100.0%), 31.5 MBs/sec
Cache Size: ~5 MB (5088242 B)
/usr/bin/tar -xf /home/runner/work/_temp/0c3dcb1f-0add-4aab-b5d0-0b742e9476ad/cache.tzst -P -C /home/runner/work/ldrd_neat_ml/ldrd_neat_ml --use-compress-program unzstd
Cache restored successfully
Cache restored from key: Linux-msttcorefonts-v1install fonts from cache: sudo mkdir -p /usr/share/fonts/truetype/msttcorefonts/
sudo cp ~/.cache/msttcorefonts/*.ttf /usr/share/fonts/truetype/msttcorefonts/
shell: /usr/bin/bash -e {0}
env:
pythonLocation: /opt/hostedtoolcache/Python/3.14.5/x64
PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.14.5/x64/lib/pkgconfig
Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.14.5/x64
Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.14.5/x64
Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.14.5/x64
LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.14.5/x64/lib |
| - name: cache fonts | ||
| id: cache-fonts | ||
| if: runner.os == 'Linux' | ||
| uses: actions/cache@v5 |
There was a problem hiding this comment.
It is best practice to use the hash rather than the release tag for security reasons (tags are often mutable), followed by a short comment with the tag/version number.
As an example of how to do this, see pandas CI config here:
https://github.com/pandas-dev/pandas/blob/main/.github/workflows/wheels.yml#L70
The rest of this seems "ok" now.
There was a problem hiding this comment.
I modified the cache fonts step to use the github/actions/cache hash instead of the version tag. I cloned the github actions repo and checked out v5.0.5 to find the commit hash associated with the version.
There was a problem hiding this comment.
As noted during in person conversation, I didnt check that the version tag and hash number were aligned in the CI file. I have updated the comment to reference the correct tag (v5.0.5).
|
Reviews (3): Last reviewed commit: "CI: use github actions cache hash" | Re-trigger Greptile |
* change from incorrect `v5` to correct hash `v5.0.5`
|
Reviews (4): Last reviewed commit: "MAINT: fix hash version comment" | Re-trigger Greptile |
| run: | | ||
| echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections | ||
| sudo apt-get update | ||
| sudo apt-get install -y ttf-mscorefonts-installer || true | ||
| sudo fc-cache -f -v | ||
| mkdir -p ~/.cache/msttcorefonts/ | ||
| cp /usr/share/fonts/truetype/msttcorefonts/*.ttf ~/.cache/msttcorefonts/ |
There was a problem hiding this comment.
Empty cache saved on apt install failure creates persistent failure loop
If ttf-mscorefonts-installer fails to download fonts (exactly the intermittent failure this PR is fixing), mkdir -p ~/.cache/msttcorefonts/ still succeeds and creates an empty directory. The subsequent cp then fails, but actions/cache's post-job step runs regardless of job status and saves the empty ~/.cache/msttcorefonts/ directory under the key runner.os-msttcorefonts-v1. On every subsequent run the cache is a hit and the "install fonts from cache" step runs — sudo cp ~/.cache/msttcorefonts/*.ttf ... glob-expands to nothing, the step fails, and tests never run. The only recovery is a manual cache key bump.
A minimal fix is to guard the cp so it either exits cleanly without saving an empty cache (e.g. check that .ttf files exist first) or to avoid caching on failure.
|
I suppose the LLM comment at #35 (comment) is valid. GitHub evicts unused caches after 7 days (based on official docs: #35 (comment)), so you could get stuck in a failure loop for the Linux jobs if you don't submit PRs for a while. I wonder how much better your solution is vs. i.e., https://github.com/lanl/ldrd_neat_ml_images approach to reliable asset downloads. This logic is getting a bit complex, but on the other hand perhaps there are licensing issues to public hosting of the Microsoft font assets. |
|
I tested the following diff on my forked branch to see if we can gate the cache dir generation on checking that the required fonts (Arial and Arial Bold) are downloaded correctly (I based this solution off of the response here: https://stackoverflow.com/a/75948306): diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 86885da..6492f33 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -38,8 +38,18 @@ jobs:
echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections
sudo apt-get update
sudo apt-get install -y ttf-mscorefonts-installer || true
- mkdir -p ~/.cache/msttcorefonts/
- cp /usr/share/fonts/truetype/msttcorefonts/*.ttf ~/.cache/msttcorefonts/
+ # before making the user storage directory, check if the font(s) we need (`Arial.ttf` and `Arial_Bold.ttf`)
+ # exist/were successfully downloaded to the root directory to avoid loading an empty directory on a successful
+ # ``cache-hit``
+ if [[ ! -f "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf" || \
+ ! -f "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf" ]]; then
+ echo "Fonts not downloaded successfully."
+ exit 1
+ else
+ echo "Fonts downloaded successfully. Caching fonts..."
+ mkdir -p ~/.cache/msttcorefonts/
+ cp /usr/share/fonts/truetype/msttcorefonts/*.ttf ~/.cache/msttcorefonts/
+ fiI performed the following steps to test the CI logic:
|
|
seems sensible |
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
|
ok, this looks fine now, thanks |
install fonts#22GitHubcaching for font installation to reduce intermittent errors in downloading fonts that cause CI failure because of absence of Arial type font for plot generationAI Disclosure: AI was used to help write the changes in this PR, specifically Claude prototyped the code for me based on the prompt to cache the downloaded fonts and then helped revised the code to avoid the bug that greptile found. I read docs such as https://github.com/marketplace/actions/cache and watched this video (https://www.youtube.com/watch?v=BDQivAobxKA) to better understand how the github actions performs caching