cache icon indicating copy to clipboard operation
cache copied to clipboard

Glob patterns should work for excludes

Open oehme opened this issue 5 years ago • 5 comments

I was just trying to optimize the cache archive size in a project by excluding some unnecessary files like so:

path: |
  ~/.gradle/wrapper/dists
  !~/.gradle/wrapper/dists/**/gradle*.zip

The zip files still get included, so glob patterns don't seem to work for excludes.

oehme avatar Jul 07 '20 07:07 oehme

In practice, glob patterns do work for excludes, however, the semantics might be non-trivial.

cache package resolves the patterns as follows: https://github.com/actions/toolkit/blob/9ad01e4fd30025e8858650d38e95cfe9193a3222/packages/cache/src/internal/cacheUtils.ts#L42-L53

  const globber = await glob.create(patterns.join('\n'), {
    implicitDescendants: false
  })

I believe the intention was like "prepare the list of directories to be added to the archive" to avoid having long list of the files.

In practice, the glob from description resolves to ~/.gradle/wrapper/dists directory. In that case, the negative pattern has nothing to exclude, because, well, the first positive pattern does not really descend to the directory, and the full directory is added to the tar manifest.

The fix could be a) Use implicitDescendants=true and ignore all the directories (== resolve the glob to the exact files, and pass them to tar). That would require code change in toolkit/packages/cache. b) Workaround the behavior. In other words, avoid including the directory which might have excluded files. One could include the relevant subdirs explicitly.

In other words, instead of

  ~/.gradle/wrapper/dists
  !~/.gradle/wrapper/dists/**/gradle*.zip

one could use

  ~/.gradle/wrapper/dists/*/*/*
  !~/.gradle/wrapper/dists/*/*/gradle*.zip

That pattern would work because the first one would enumerate all the files, it would get names like gradle-6.6, gradle-6.6-bin.zip, gradle-6.6-bin.zip.lck, gradle-6.6-bin.zip.ok. Then the second negative would trigger and it would exclude the zip file.

In practice, the only useful directory in that folder is like wrapper/dists/gradle-6.6-bin/dflktxzwamd4bv66q00iv4ga9/gradle-6.6, so the pattern could be

  ~/.gradle/wrapper/dists/*/*/gradle-*/

The trailing slash would select directories only which is exactly what the original pattern supposed to do.

PS. All of the above is not really needed in case https://github.com/burrunan/gradle-cache-action is used for caching or Gradle execution 😉

vlsi avatar Aug 21 '20 08:08 vlsi

This issue is stale because it has been open for 365 days with no activity. Leave a comment to avoid closing this issue in 5 days.

github-actions[bot] avatar Dec 23 '21 08:12 github-actions[bot]

This issue is stale because it has been open for 365 days with no activity. Leave a comment to avoid closing this issue in 5 days

The issue is still reproducible.

mlopatkin avatar Dec 25 '21 17:12 mlopatkin

@vlsi see https://github.com/actions/toolkit/issues/713#issuecomment-1030692990 - passing matchDirectories: false might just work.

robinp avatar Feb 05 '22 20:02 robinp

Note: https://github.com/actions/cache/issues/494 seems to be a dup.

robinp avatar Feb 05 '22 20:02 robinp

This issue is stale because it has been open for 200 days with no activity. Leave a comment to avoid closing this issue in 5 days.

github-actions[bot] avatar Mar 06 '23 08:03 github-actions[bot]

This issue was closed because it has been inactive for 5 days since being marked as stale.

github-actions[bot] avatar Mar 12 '23 08:03 github-actions[bot]