Skip to content

v4.0 save always not working #1315

Closed
Closed

Description

@DanMawdsleyBA

I have setup the save always to true such that the cache step should always fail even if one of the tasks fail. See screenshots below:
Save always set to true in step:
image

Then further in the job a step fails but the post cache step is not run unlike the post repositry setup:
image

Related to
#1242

Activity

  1. DanMawdsleyBA commented on Jan 30, 2024

    @DanMawdsleyBA
    Author

    For context this is how I did save cache in v3:

    image

    I think we can also optimise like this to not attempt to save cache when there was a cache hit

  2. added a commit that references this issue on Feb 7, 2024
  3. SukkaW commented on Feb 8, 2024

    @SukkaW

    I am also facing this issue. With save-always: true, the Post Cache is still skipped if the previous build step has failed:

    image
  4. sascha-wolf commented on Feb 27, 2024

    @sascha-wolf

    We're observing the same issue. It just doesn't seem to work as documented.
    image

  5. added a commit that references this issue on May 2, 2024
  6. self-assigned this
    on Jun 12, 2024
  7. joshmgross commented on Jun 12, 2024

    @joshmgross
    Contributor

    👋 Thank you for the bug report and apologies for the lack of a timely response.

    As I shared in #1325 (comment), I do not believe this is a feature we can support in this action today due to limitations in what's possible in post-if expressions.

    As @DanMawdsleyBA shared above, if you want to override the post-if behavior of the default cache action you can utilize the separate actions/cache/save and actions/cache/restore. This sort of granularity is what these actions were originally intended for - #1035.

    That might look something like:

    name: Always Caching Primes
    
    on: push
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
        - uses: actions/checkout@v4
    
        - name: Restore cached Primes
          id: cache-primes-restore
          uses: actions/cache/restore@v4
          with:
            path: |
              path/to/dependencies
              some/other/dependencies
            key: ${{ runner.os }}-primes
    
        # Intermediate workflow steps
    
        - name: Always Save Primes 
          id: cache-primes-save
          if: always() && steps.cache-primes-restore.outputs.cache-hit != 'true'
          uses: actions/cache/save@v4
          with:
            path: |
              path/to/dependencies
              some/other/dependencies
            key: ${{ steps.cache-primes-restore.outputs.cache-primary-key }}

    Given that save-always never worked, I believe it would make the most sense to deprecate that action input and remove it in a future version release. It's not something we can confidently support long term with the current features of post-if - any workarounds we implement today are likely to break in the future if they're relying on undocumented behavior. #1242 should not have been approved or merged without sufficient testing from us to validate that it was working as intended.

    My current plan is to:

    1. Deprecate save-always in the current major version to indicate to users that it's not working as intended
    2. Document in the README how to support this scenario with actions/cache/save
    3. Remove save-always in the next major version

    I realize this won't likely won't be a popular course of action, but I believe it's best for the long term maintainability of this action. I'd appreciate any and all feedback here, especially around the propose workaround if scenarios where it might not work.

  8. ruffsl commented on Jun 18, 2024

    @ruffsl

    Document in the README how to support this scenario with actions/cache/save

    @joshmgross , is there more that should be added to specified here?

  9. joshmgross commented on Jun 18, 2024

    @joshmgross
    Contributor

    Document in the README how to support this scenario with actions/cache/save

    @joshmgross , is there more that should be added to specified here?

    I was thinking it'd make sense to include the cache-hit output in that if conditional. The dedicated save cache action won't have access to the intra action state used by the restore step to indicate if the save is necessary.

    cache/src/saveImpl.ts

    Lines 46 to 48 in 0c45773

    // If matched restore key is same as primary key, then do not save cache
    // NO-OP in case of SaveOnly action
    const restoredKey = stateProvider.getCacheState();

  10. added a commit that references this issue on Aug 12, 2024
  11. added a commit that references this issue on Aug 14, 2024
  12. added a commit that references this issue on Aug 22, 2024
  13. fulldecent commented on Sep 9, 2024

    @fulldecent

    Here is the current documentation with the workaround.

    And it does NOT recommend using save-always

    https://github.com/actions/cache/blob/main/caching-strategies.md#saving-cache-even-if-the-build-fails

  14. added a commit that references this issue on Sep 13, 2024
  15. added a commit that references this issue on Oct 3, 2024
  16. joshmgross commented on Oct 7, 2024

    @joshmgross
    Contributor

    save-always has been deprecated as it's not something we can support at this time. #1452

    See #1315 (comment) for more details.

  17. added a commit that references this issue on Jul 23, 2025
  18. added a commit that references this issue on Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions