Skip to content

Commit

Permalink
Add inputs.cache-save-always
Browse files Browse the repository at this point in the history
Adds an input that borrows the `save-always` input from [v4 of `actions/cache`][0], which will run the post step to save the cache even if a failure occurs. Using the added `cache-save-always` input saves the cache when a build fails, which will speed up subsequent runs which restore the partial build. This comes at the cost of requiring a build when there is an exact `key` match, since the cache from a failed build will have the same `key` as a completed build.

[0]: https://github.com/actions/cache/tree/main#v4
  • Loading branch information
stackptr committed Jan 18, 2024
1 parent ac0dd8d commit 60924a3
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ inputs:
cache-prefix:
required: true
default: ""
cache-save-always:
description: "Save the dependencies and build cache even if a build fails"
default: false
outputs:
compiler:
description: "compiler.actual value from stack query"
Expand Down Expand Up @@ -194,7 +197,6 @@ runs:
done
- name: Restore dependencies cache
id: restore-deps
uses: actions/cache/restore@v3
with:
path: |
Expand All @@ -207,7 +209,6 @@ runs:
${{ 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 @@ -220,7 +221,7 @@ runs:
${{ inputs.stack-arguments }}
- name: Save dependencies cache
if: steps.restore-deps.outputs.cache-hit != 'true'
if: success() || (failure() && inputs.cache-save-always)
uses: actions/cache/save@v3
with:
path: |
Expand All @@ -230,7 +231,6 @@ runs:
key: ${{ inputs.cache-prefix }}${{ runner.os }}-stack-deps-${{ steps.stack-query.outputs.compiler }}-${{ steps.setup.outputs.snapshot-hash }}-${{ steps.setup.outputs.package-hash }}

- name: Restore build cache
id: restore-build
uses: actions/cache/restore@v3
with:
path: ${{ steps.setup.outputs.stack-works }}
Expand All @@ -240,7 +240,6 @@ runs:
${{ 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 @@ -251,7 +250,7 @@ runs:
${{ inputs.stack-arguments }}
- name: Save build cache
if: steps.restore-build.outputs.cache-hit != 'true'
if: success() || (failure() && inputs.cache-save-always)
uses: actions/cache/save@v3
with:
path: ${{ steps.setup.outputs.stack-works }}
Expand Down

0 comments on commit 60924a3

Please sign in to comment.