actions / actions/cache

Bug: cannot update cache in Cargo project

Open
#1,539 6 comments 2 reactions 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 made a minimal example of bug.

I have setup a Cargo workspace and want to cache the ~/.cargo and target directories. Calling save explicitly at the end of the script does not overwrite the existing cache after the cache is stored on the first time.

Deleting the previous version of the cache fixes it

Run actions/cache/save@v4
/usr/bin/tar --posix -cf cache.tzst --exclude cache.tzst -P -C /home/runner/work/cargo-ci/cargo-ci --files-from manifest.txt --use-compress-program zstdmt
Failed to save: Unable to reserve cache with key Linux-restore-build, another job may be creating this cache. More details: Cache already exists. Scope: refs/heads/main, Key: Linux-restore-build, Version: cd36736238095b30d245e37cee3eada29643d39d68cc49be99ecf89155bdc73a
Warning: Cache save failed.

The core of the message seems to be another job may be creating this cache. More details: Cache already exists.

The YAML workflow file I am using is

name: Rust test workflow
on:
  push:
    branches:
      - 'main' 
jobs:
  test-restore-build:
    name: Test restore compile and store
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v4

      - name: Update APT package index
        run: sudo apt-get update
        
      - name: Install and download required APT packages
        run: sudo apt-get install -y rustup

      - name: Restore Cargo cache
        uses: actions/cache/restore@v4
        with:
          path: |
            ~/.cargo
            target
          key: ${{ runner.os }}-restore-build

      - name: Write to target
        run: cargo build

      - name: Save Cargo cache
        uses: actions/cache/save@v4
        with:
          path: |
            ~/.cargo
            target
          key: ${{ runner.os }}-restore-build

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 running the linked minimal Cargo workspace and reviewing the provided workflow, especially the actions/cache/restore and actions/cache/save steps and their log output. Trace why saving with the existing key is rejected; done means a subsequent workflow run can update the Cargo and target cache without requiring manual deletion.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions, rust
Domain
build-system, ci-cd
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.