Skip to content

Output cache-paths and cache-key as well#169

Merged
IanButterworth merged 1 commit intojulia-actions:mainfrom
penelopeysm:main
Apr 1, 2025
Merged

Output cache-paths and cache-key as well#169
IanButterworth merged 1 commit intojulia-actions:mainfrom
penelopeysm:main

Conversation

@penelopeysm
Copy link
Copy Markdown
Contributor

@penelopeysm penelopeysm commented Mar 23, 2025

Hello! I've been looking for a way to save the cache even if an intermediate step fails (#79). (Context: on Turing.jl docs it takes 10 mins to instantiate the environment and 2 hours to build the docs, so having this would save a lot of time on PRs)

I understand that a 'nicer' solution to this would depend on upstream fixes to GitHub Actions, but this PR seems like a good enough way to do it. The gist is that as long as we know the cache paths and the key, we can manually call actions/cache/save to save the cache at the bottom of the workflow. (That's also the workflow that GitHub said to use.)

So if julia-actions/cache outputs these as variables, it becomes easy to write something like

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Load Julia packages from cache
        id: julia-cache
        uses: julia-actions/cache@v2
        with:
          cache-name: foo

      # do whatever you want here (that might fail)

      - name: Save Julia depot cache
        id: julia-cache-save
        if: always() && steps.julia-cache.outputs.cache-hit != 'true'
        uses: actions/cache/save@v4
        with: 
          path: |
            ${{ steps.julia-cache.outputs.cache-paths }}
          key: ${{ steps.julia-cache.outputs.cache-key }}

I've tested this using a playground repo and a workflow pointing to my fork, and it seems to work perfectly as far as I can tell. You can see the first time the action runs here (no cache hit, and an intermediate step fails, but the cache is still saved):

https://github.com/penelopeysm/Shaymin.jl/actions/runs/14022967403/job/39257320572

and a subsequent run where the cache is then correctly loaded:

https://github.com/penelopeysm/Shaymin.jl/actions/runs/14022985223/job/39257363646

If you think this approach is sensible, then I can add some documentation explaining this too.

@IanButterworth
Copy link
Copy Markdown
Member

Sounds good, at least adding these outputs seems harmless.

If you end up happy with this design, it's definitely worth documenting here.

@IanButterworth IanButterworth merged commit c231b4e into julia-actions:main Apr 1, 2025
19 checks passed
@penelopeysm
Copy link
Copy Markdown
Contributor Author

Thanks! Sure, I'll do a followup PR on the readme :)

@IanButterworth
Copy link
Copy Markdown
Member

Released https://github.com/julia-actions/cache/releases/tag/v2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants