Skip to content

Commit c4baf99

Browse files
committed
Cache downloaded fonts
1 parent 3c145ce commit c4baf99

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

.github/actions/setup-image-env/action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ runs:
2121
with:
2222
version: ${{ inputs.uv-version }}
2323

24+
- name: Cache apt font packages
25+
uses: actions/cache@v4
26+
id: apt-cache
27+
with:
28+
path: ~/.cache/apt-fonts
29+
key: apt-fonts-${{ runner.os }}-${{ hashFiles('.github/scripts/env_image.sh') }}
30+
2431
- name: Install Kaleido, plotly.io and required fonts
2532
run: .github/scripts/env_image.sh
2633
shell: bash
34+
env:
35+
APT_CACHE_HIT: ${{ steps.apt-cache.outputs.cache-hit }}

.github/scripts/env_image.sh

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
11
#!/bin/sh
22
set -e
3-
# install required fonts
4-
sudo apt-get install fonts-liberation2 fonts-open-sans fonts-noto-cjk fonts-noto-color-emoji
53

6-
# install additional fonts (committed in .github/fonts/)
4+
APT_PACKAGES="fonts-liberation2 fonts-open-sans fonts-noto-cjk fonts-noto-color-emoji fontconfig"
5+
APT_CACHE_DIR="${HOME}/.cache/apt-fonts"
6+
7+
if [ "$APT_CACHE_HIT" = "true" ] && [ -d "$APT_CACHE_DIR" ]; then
8+
echo "Installing font packages from cache..."
9+
sudo dpkg -i "$APT_CACHE_DIR"/*.deb 2>/dev/null || sudo apt-get install -yf
10+
else
11+
echo "Downloading and installing font packages..."
12+
sudo apt-get update -q
13+
sudo apt-get install -y --no-install-recommends $APT_PACKAGES
14+
# Save debs for future cache
15+
mkdir -p "$APT_CACHE_DIR"
16+
for pkg in $APT_PACKAGES; do
17+
cp /var/cache/apt/archives/${pkg}_*.deb "$APT_CACHE_DIR/" 2>/dev/null || true
18+
done
19+
fi
20+
21+
# Rebuild font cache
22+
sudo fc-cache -f
23+
24+
# Install additional fonts (committed in .github/fonts/)
725
sudo cp -r .github/fonts/ /usr/share/
8-
sudo apt install fontconfig
926
sudo fc-cache -f
1027

11-
# install Kaleido & Plotly
28+
# Install Kaleido & Plotly
1229
uv pip install --system kaleido==1.2 plotly==6.6.0 --no-progress
1330

14-
# install numpy i.e. to convert arrays to typed arrays
31+
# Install numpy i.e. to convert arrays to typed arrays
1532
uv pip install --system numpy==2.4.3
1633

17-
# verify version of python and versions of installed python packages
34+
# Verify version of python and versions of installed python packages
1835
python --version
1936
uv pip freeze --system

0 commit comments

Comments
 (0)