Skip to content

@actions/cache path exclude pattern doesn't work #2155

@ProgramRipper

Description

@ProgramRipper

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:

const cachePaths = await utils.resolvePaths(paths)

and resolvePaths() simply ignore all exclude pattern.
const globber = await glob.create(patterns.join('\n'), {
implicitDescendants: false
})

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions