Skip to content

Cache miss for existing keys when merging PRs #1561

Open
@hammzj

Description

@hammzj

I have a workflow that is saving a cached file from the head branch to the base branch on a pull request merge. The file keys exists on the head branch, but when it attempts to find it using a restore-keys basic path, it is failing to hit. I see the key exists in my GitHub cache for the head branch, so not sure why it's showing as missing.

Here is an example workflow:

name: Cache file on base branch
on:
  pull_request:
    types: [closed]

env:
  node-version: 20.18.x

jobs:
  cache_file:
    # this job will only run if the PR has been merged
    if: github.event.pull_request.merged == true
    runs-on: ubuntu-latest
    steps:
      - run: |
          echo PR #${{ github.event.number }} has been merged

      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ env.node-version }}

      - name: Restore file from head branch

        uses: actions/cache/restore@v4
        with:
          fail-on-cache-miss: true
          path: main.json
          key:  file-${{ github.head_ref }}-${{ github.run_id }}-${{ github.run_attempt }}
          restore-keys: |
            file-${{ github.head_ref }}-
 
      - name: Save file to base ref
        uses: actions/cache/save@v4
        with:
          path: main.json
          key: file-${{ github.base_ref }}-${{ github.run_id }}-${{ github.run_attempt }}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions