Skip to content

Commit

Permalink
Use a different cache key in workflow runs.
Browse files Browse the repository at this point in the history
Related #33
  • Loading branch information
aholmes committed Jan 12, 2024
1 parent df53785 commit e5e2f7f
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions .github/workflows/CICD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ jobs:
Checkout:
name: Checkout and Setup
runs-on: ubuntu-latest

outputs:
repository-build-cache-key: ${{ steps.repository-build-cache-key.outputs.cache_key }}

strategy:
matrix:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
Expand All @@ -53,12 +57,20 @@ jobs:
source .github-venv/bin/activate
./install_all.sh -e
- uses: actions/cache@v3
- id: repository-build-cache-key
run: |
cache_key='${{ runner.os }}-${{ github.event_name != 'workflow_dispatch' || github.run_attempt }}-${{ hashFiles('pyproject.toml', 'src/*/pyproject.toml') }}'
echo "cache_key=$cache_key" >> $GITHUB_OUTPUT
- uses: actions/cache/save@v3
name: Cache repository build
id: cache-repository-build
id: repository-build-cache
with:
path: ${{ github.workspace }}
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
# Use the same cache between Workflow runs _except_ when the event is a workflow_dispatch.
# This should result in cache keys like "Linux-true-abc123" for all runs _except_ workflow_dispatch,
# and cache keys like "linux-123-abc123" for workflow_dispatch.
key: ${{ steps.repository-build-cache-key.outputs.cache_key }}

Pyright:
name: Static type checking
Expand All @@ -71,12 +83,14 @@ jobs:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v4

- uses: actions/cache/restore@v3
name: Restore repository build
id: restore-repository-build
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
key: ${{ needs.Checkout.outputs.repository-build-cache-key }}

- name: Test with pyright
run: |
Expand All @@ -95,12 +109,14 @@ jobs:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v4

- uses: actions/cache/restore@v3
name: Restore repository build
id: restore-repository-build
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
key: ${{ needs.Checkout.outputs.repository-build-cache-key }}

- name: Test with pytest and generate reports
run: |
Expand Down Expand Up @@ -134,12 +150,14 @@ jobs:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v4

- uses: actions/cache/restore@v3
name: Restore repository build
id: restore-repository-build
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
key: ${{ needs.Checkout.outputs.repository-build-cache-key }}

- name: Check code style
run: |
Expand Down

0 comments on commit e5e2f7f

Please sign in to comment.