Skip to content

Commit

Permalink
Use -partial key to no-op after full cache-hit
Browse files Browse the repository at this point in the history
Saves the set of build artifacts after a build failure with a `-partial` suffix on the cache key. A full cache-hit will therefore only occur when restoring the cache saved after a successful build, allowing for the subsequent `stack build` and cache-save steps to be skipped.
  • Loading branch information
stackptr committed Jan 22, 2024
1 parent ffa7c66 commit 629a6a9
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ runs:
done
- name: Restore dependencies cache
id: restore-deps
uses: actions/cache/restore@v3
with:
path: |
Expand All @@ -205,10 +206,12 @@ runs:
${{ steps.setup.outputs.stack-works }}
key: ${{ inputs.cache-prefix }}${{ runner.os }}-stack-deps-${{ steps.stack-query.outputs.compiler }}-${{ steps.setup.outputs.snapshot-hash }}-${{ steps.setup.outputs.package-hash }}
restore-keys: |
${{ inputs.cache-prefix }}${{ runner.os }}-stack-deps-${{ steps.stack-query.outputs.compiler }}-${{ steps.setup.outputs.snapshot-hash }}-${{ steps.setup.outputs.package-hash }}-partial
${{ inputs.cache-prefix }}${{ runner.os }}-stack-deps-${{ steps.stack-query.outputs.compiler }}-${{ steps.setup.outputs.snapshot-hash }}-
${{ inputs.cache-prefix }}${{ runner.os }}-stack-deps-${{ steps.stack-query.outputs.compiler }}-
- name: Dependencies
if: steps.restore-deps.outputs.cache-hit != 'true'
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
Expand All @@ -221,25 +224,30 @@ runs:
${{ inputs.stack-arguments }}
- name: Save dependencies cache
if: success() || (failure() && inputs.cache-save-always == 'true')
if: |
(success() && steps.restore-deps.outputs.cache-hit != 'true') ||
(failure() && inputs.cache-save-always == 'true')
uses: actions/cache/save@v3
with:
path: |
${{ steps.stack-path.outputs.stack-root }}
${{ steps.stack-path.outputs.programs }}
${{ steps.setup.outputs.stack-works }}
key: ${{ inputs.cache-prefix }}${{ runner.os }}-stack-deps-${{ steps.stack-query.outputs.compiler }}-${{ steps.setup.outputs.snapshot-hash }}-${{ steps.setup.outputs.package-hash }}
key: ${{ inputs.cache-prefix }}${{ runner.os }}-stack-deps-${{ steps.stack-query.outputs.compiler }}-${{ steps.setup.outputs.snapshot-hash }}-${{ steps.setup.outputs.package-hash }}${{ failure() && '-partial' }}

- name: Restore build cache
id: restore-build
uses: actions/cache/restore@v3
with:
path: ${{ steps.setup.outputs.stack-works }}
key: ${{ inputs.cache-prefix }}${{ runner.os }}-stack-build-${{ steps.setup.outputs.snapshot-hash }}-${{ steps.setup.outputs.package-hash }}-${{ steps.setup.outputs.sources-hash }}
restore-keys: |
${{ inputs.cache-prefix }}${{ runner.os }}-stack-build-${{ steps.setup.outputs.snapshot-hash }}-${{ steps.setup.outputs.package-hash }}-${{ steps.setup.outputs.sources-hash }}-partial
${{ inputs.cache-prefix }}${{ runner.os }}-stack-build-${{ steps.setup.outputs.snapshot-hash }}-${{ steps.setup.outputs.package-hash }}-
${{ inputs.cache-prefix }}${{ runner.os }}-stack-build-${{ steps.setup.outputs.snapshot-hash }}-
- name: Build
if: steps.restore-build.outputs.cache-hit != 'true'
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
Expand All @@ -250,11 +258,13 @@ runs:
${{ inputs.stack-arguments }}
- name: Save build cache
if: success() || (failure() && inputs.cache-save-always == 'true')
if: |
(success() && steps.restore-deps.outputs.cache-hit != 'true') ||
(failure() && inputs.cache-save-always == 'true')
uses: actions/cache/save@v3
with:
path: ${{ steps.setup.outputs.stack-works }}
key: ${{ inputs.cache-prefix }}${{ runner.os }}-stack-build-${{ steps.setup.outputs.snapshot-hash }}-${{ steps.setup.outputs.package-hash }}-${{ steps.setup.outputs.sources-hash }}
key: ${{ inputs.cache-prefix }}${{ runner.os }}-stack-build-${{ steps.setup.outputs.snapshot-hash }}-${{ steps.setup.outputs.package-hash }}-${{ steps.setup.outputs.sources-hash }}${{ failure() && '-partial' }}

- name: Test
if: ${{ inputs.test == 'true' }}
Expand Down

0 comments on commit 629a6a9

Please sign in to comment.