Skip to content

Commit

Permalink
Handle the fact the github actions cache does not allows updates
Browse files Browse the repository at this point in the history
If there is a cache hit, there is never a save. Therefore, we need to
always miss on the first run attempt, falling back hopefully to the
previous run.
  • Loading branch information
pjk25 committed Apr 24, 2024
1 parent f129eac commit ba5c595
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/test-make.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,10 @@ jobs:
uses: actions/cache@v4.0.2
with:
path: /home/runner/test-result-cache/
key: ${{ runner.os }}-test-result-cache-${{ steps.hash.outputs.hash }}
key: ${{ runner.os }}-test-result-cache-${{ steps.hash.outputs.hash }}-${{ github.run_number }}-${{ github.run_attempt - 1 }}
restore-keys: |
${{ runner.os }}-test-result-cache-
${{ runner.os }}-test-result-cache-${{ steps.hash.outputs.hash }}-${{ github.run_number }}-
${{ runner.os }}-test-result-cache-${{ steps.hash.outputs.hash }}-
- name: PREP CACHE DIR
run: |
mkdir -p /home/runner/test-result-cache/${{ steps.hash.outputs.hash }}
Expand Down Expand Up @@ -250,10 +251,7 @@ jobs:
uses: actions/cache@v4.0.2
with:
path: /home/runner/test-result-cache/
key: ${{ runner.os }}-test-result-cache-${{ needs.load-test-result-cache.outputs.hash }}
restore-keys: |
${{ runner.os }}-test-result-cache-
fail-on-cache-miss: true
key: ${{ runner.os }}-test-result-cache-${{ needs.load-test-result-cache.outputs.hash }}-${{ github.run_number }}-${{ github.run_attempt }}
save-always: true
- name: UPDATE CACHE
uses: actions/download-artifact@v4
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/test-make.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@ jobs:
id: hash
run: |
echo "hash=${{ hashFiles('**/*', '!.github/**/*', '!*.bazel', '!*.bzl', '!BUILD.*') }}" | tee -a $GITHUB_OUTPUT
- name: COMPUTE PREVIOUS RUN ATTEPMT
id: previous-attempt
run: |
PREVIOUS_ATTEMPT=$((${{ fromJSON(github.run_attempt) }} - 1))
echo "number=$PREVIOUS_ATTEMPT" | tee -a $GITHUB_OUTPUT
- name: MOUNT TEST RESULT CACHE
uses: actions/cache@v4.0.2
with:
path: /home/runner/test-result-cache/
key: ${{ runner.os }}-test-result-cache-${{ steps.hash.outputs.hash }}
key: ${{ runner.os }}-test-result-cache-${{ steps.hash.outputs.hash }}-${{ github.run_number }}-${{ steps.previous-attempt.outputs.number }}
restore-keys: |
${{ runner.os }}-test-result-cache-
${{ runner.os }}-test-result-cache-${{ steps.hash.outputs.hash }}-${{ github.run_number }}-
${{ runner.os }}-test-result-cache-${{ steps.hash.outputs.hash }}-
- name: PREP CACHE DIR
run: |
mkdir -p /home/runner/test-result-cache/${{ steps.hash.outputs.hash }}
Expand Down Expand Up @@ -6937,10 +6943,7 @@ jobs:
uses: actions/cache@v4.0.2
with:
path: /home/runner/test-result-cache/
key: ${{ runner.os }}-test-result-cache-${{ needs.load-test-result-cache.outputs.hash }}
restore-keys: |
${{ runner.os }}-test-result-cache-
fail-on-cache-miss: true
key: ${{ runner.os }}-test-result-cache-${{ needs.load-test-result-cache.outputs.hash }}-${{ github.run_number }}-${{ github.run_attempt }}
save-always: true
- name: UPDATE CACHE
uses: actions/download-artifact@v4
Expand Down

0 comments on commit ba5c595

Please sign in to comment.