@actions/cache path exclude pattern doesn't work
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.9k
- Forks
- 1.8k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
Accroding to C# - NuGet example in actions/cache, @actions/cache should support exclude pattern like this:
['~/.nuget/packages', '!~/.nuget/packages/unwanted']
But saveCacheV2() use resolvePaths() here:
https://github.com/actions/toolkit/blob/ddc5fa4ae84a892bfa8431c353db3cf628f1235d/packages/cache/src/cache.ts#L533
and resolvePaths() simply ignore all exclude pattern.
https://github.com/actions/toolkit/blob/ddc5fa4ae84a892bfa8431c353db3cf628f1235d/packages/cache/src/internal/cacheUtils.ts#L51-L53
To Reproduce
import cache from '@actions/cache/lib/internal/cacheUtils.js'
console.log(await cache.resolvePaths(['~/.nuget/packages', '!~/.nuget/packages/unwanted']))
// [ '~/.nuget/packages' ]
or run an actions (example from actions/cache):
- uses: actions/cache@v4
with:
path: |
~/.nuget/packages
!~/.nuget/packages/unwanted
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
Expected behavior
Respect exclude patterns and ignore ~/.nuget/packages/unwanted.
Screenshots
Desktop (please complete the following information):
- OS: Ubuntu 24.04 (GitHub-hosted runners)
- Browser irrelevant
- Version irrelevant
Smartphone (please complete the following information):
- Device: irrelevant
- OS: irrelevant
- Browser irrelevant
- Version irrelevant
Additional context
Here is a real world example:
workflows file
actions debug log
you can see pattern !/tmp/.xmake/**/.git was ignored and actions tried to cache .git file which it doesn't have proper permission to read.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with saveCacheV2() in packages/cache/src/cache.ts and resolvePaths() in packages/cache/src/internal/cacheUtils.ts, then run the reproduction using the NuGet paths from the issue. Done means resolvePaths() and the cache action respect the !~/.nuget/packages/unwanted pattern instead of returning or attempting to cache the excluded path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- github-actions, typescript
- Domain
- devops, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100