actions / actions/cache

Cache miss for existing keys when merging PRs

Open
#1,561 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
5.6k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

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 }}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the shown pull_request closed workflow with actions/cache/restore@v4 and actions/cache/save@v4, using the head and base refs in the cache keys. Check the cache action’s restore scope and restore-keys behavior for merged pull requests. Done means the head-branch cache is reliably restored or the limitation and required workflow change are documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions
Domain
ci-cd
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.