diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4f1d7d4..434fe9b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,13 +25,40 @@ jobs: python -m pip install -v ".[dev]" mypy neat_ml ruff check neat_ml - - name: install fonts + - name: cache fonts + id: cache-fonts if: runner.os == 'Linux' + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae #v5.0.5 + with: + path: ~/.cache/msttcorefonts/ + key: ${{ runner.os }}-msttcorefonts-v1 + - name: install fonts + if: runner.os == 'Linux' && steps.cache-fonts.outputs.cache-hit != 'true' 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 + # before making the user storage directory, check if the font(s) we need + # (i.e. `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/ + fi + - name: install fonts from cache + if: runner.os == 'Linux' && steps.cache-fonts.outputs.cache-hit == 'true' + run: | + sudo mkdir -p /usr/share/fonts/truetype/msttcorefonts/ + sudo cp ~/.cache/msttcorefonts/*.ttf /usr/share/fonts/truetype/msttcorefonts/ + - name: refresh font cache + if: runner.os == 'Linux' + run: sudo fc-cache -f -v - name: test run: | cd /tmp && python -m pytest --pyargs neat_ml --cov=neat_ml --cov-report=term-missing