Skip to content

Commit

Permalink
fix(actions): change cache-key approach
Browse files Browse the repository at this point in the history
Previous approach was broken on macOS due to missing sha256sum command.
This adopts the same cache-key approach as is used in Poetry pipelines.

Closes #1389
  • Loading branch information
kenibrewer committed Oct 29, 2023
1 parent 5cc7f67 commit 1fe34b7
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,29 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: generate cache key PY
shell: bash
- name: Get full Python version
id: full-python-version
run:
echo "PY=$((python -VV; pip freeze) | sha256sum | cut -d' ' -f1)" >>
$GITHUB_ENV
echo version=$(python -c "import sys; print('-'.join(str(v) for v in
sys.version_info))") >> $GITHUB_OUTPUT
- uses: actions/cache@v3
id: cache
with:
path: |
.cache
.venv
key:
cache|${{ runner.os }}|${{ env.PY }}|${{ hashFiles('pyproject.toml') }}|${{
hashFiles('poetry.lock') }}|${{ hashFiles('.pre-commit-config.yaml') }}
cache|${{ runner.os }}|${{ steps.full-python-version.outputs.version }}|${{
hashFiles('pyproject.toml') }}|${{ hashFiles('poetry.lock') }}|${{
hashFiles('.pre-commit-config.yaml') }}
- name: Ensure cache is healthy
if: steps.cache.outputs.cache-hit == 'true'
run: |
# `timeout` is not available on macOS, so we define a custom function.
[ "$(command -v timeout)" ] || function timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; }
# Using `timeout` is a safeguard against the Poetry command hanging for some reason.
timeout 10s poetry run pip --version || rm -rf .cache/.venv
- name: Install dependencies
run: |
python -m pip install poetry poetry-dynamic-versioning
Expand Down Expand Up @@ -139,18 +149,29 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: generate cache key PY
- name: Get full Python version
id: full-python-version
run:
echo "PY=$((python -VV; pip freeze) | sha256sum | cut -d' ' -f1)" >>
$GITHUB_ENV
echo version=$(python -c "import sys; print('-'.join(str(v) for v in
sys.version_info))") >> $GITHUB_OUTPUT
- uses: actions/cache@v3
id: cache
with:
path: |
.cache
.venv
key:
cache|${{ runner.os }}|${{ env.PY }}|${{ hashFiles('pyproject.toml') }}|${{
hashFiles('poetry.lock') }}|${{ hashFiles('.pre-commit-config.yaml') }}
cache|${{ runner.os }}|${{ steps.full-python-version.outputs.version }}|${{
hashFiles('pyproject.toml') }}|${{ hashFiles('poetry.lock') }}|${{
hashFiles('.pre-commit-config.yaml') }}
- name: Ensure cache is healthy
if: steps.cache.outputs.cache-hit == 'true'
run: |
# `timeout` is not available on macOS, so we define a custom function.
[ "$(command -v timeout)" ] || function timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; }
# Using `timeout` is a safeguard against the Poetry command hanging for some reason.
timeout 10s poetry run pip --version || rm -rf .cache/.venv
- name: Install dependencies
shell: bash
run: |
Expand Down

0 comments on commit 1fe34b7

Please sign in to comment.