Skip to content

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

Closed
@stuller-adriahuertascaparros

Description

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions