Skip to content

If I create the cache in the first job, the second can't found it #1261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 of 5 tasks
stuller-adriahuertascaparros opened this issue Mar 27, 2025 · 1 comment
Closed
2 of 5 tasks
Labels
bug Something isn't working needs triage

Comments

@stuller-adriahuertascaparros
Copy link

stuller-adriahuertascaparros commented Mar 27, 2025

Description:
A cache created in the first job of an action is not available in the second job. My idea was to create a separate github action with inputs to be called as the first job in every other github action to manage the cache and then just restore the cache in the second job (knowing that it will always exist), but this issue doesn't allow me to use this strategy

Action version:
actions/cache@v4

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Tools version:

Node 20

Repro steps:

name: Proof of Concept

on:
  workflow_dispatch:
    
jobs:
  manage-cache:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Node Setup
        uses: actions/setup-node@v4
        with:
          node-version: 20.x
      - name: Restore Main Cache
        id: main-cache
        uses: actions/cache@v4
        with:
          path: ./x/node_modules
          key: cart-cache-${{ hashFiles('x/package-lock.json') }}
      - name: Install dependencies if cache miss
        if: steps.main-cache.outputs.cache-hit != 'true'
        working-directory: ./x
        run: npm ci
    
  react-build:
      runs-on: ubuntu-latest
      steps:
        - name: Checkout
          uses: actions/checkout@v4
        - name: Node Setup
          uses: actions/setup-node@v4
          with:
            node-version: 20.x
        # Next step should always be able to restore the cache but the first time always fails
        - name: Restore cache
          uses: actions/cache@v4
          with:
            path: ./x/node_modules
            key: cart-cache-${{ hashFiles(x/package-lock.json') }}

Expected behavior:
The second job should be able to restore cache

Actual behavior:
The second job says can't found cache with key "y" (being "y" the key created in the first job that I can see that exists)

@stuller-adriahuertascaparros
Copy link
Author

I think I was only missing needs 🤦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant