GitHub's action actions/cache@v3
only saves data in the cache, if the job succeeds. There has been much interest in letting actions/cache
save data in the cache even if the job fails, see its issue #92.
Note that GitHub has provided an alternative solution by releasing two new actions actions/cache/save
and actions/cache/restore
in December 2022, but this requires significant changes to extant workflows which use GitHub's classic actions/cache
, plus all three actions continue to be maintained by GitHub (so it was indicated in this "Conclusion"). Still this extension of the original "action cache
, which is structurally analog to actions/cache/save
and actions/cache/restore
, continues to provide a larger feature set!
Rather than forking and adapting GitHub's actions/cache
, which creates a maintenance burden, this repository demonstrates "live patching" of the original actions/cache@v3
on every job run to accomplish this goal, see .github//actions/cache-always/action.yml. It does …
- … check out
actions/cache@v3
to./.github/.tmp/actions/always-cache
- … patch
post-if: success()
topost-if: ${{ success() || failure() }}
to let the patched action cache data, even if the job fails, but not when it is cancelled. - … transparently map the "live patched" action to the patching action
.github/actions/cache-always/action.yml
by passing through all parameters, so the latter can be called.
Ultimately one simply substitutes all occurrences of actions/cache@v3
with Olf0/cache-always@v3
.
Alternatively one copies .github/actions/cache-always/action.yml from this repository directly to the same location of one's own repository and uses it in one's own workflows in .github/workflows
instead of the original actions/cache@v3
.
For an example of a workflow using the "live patched" actions/cache@v3
in .github/actions/cache-always
see .github/workflows/demo-cache-always.yml.
P.S.: Special thanks to user DrJume for the enhancements of the original version here: These have been integrated and further improved.