question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Glob patterns should work for excludes

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

1reaction
mlopatkincommented, Dec 25, 2021

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.

1reaction
vlsicommented, Aug 21, 2020

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 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

glob exclude pattern - python - Stack Overflow
You can't exclude patterns with the glob function, globs only allow for inclusion patterns. Globbing syntax is very limited (even a [!.
Read more >
Tips for writing glob patterns in DeepSource configuration
exclude_patterns are a list of glob patterns that should be excluded when the analyses are run. These patterns should be relative to the ......
Read more >
Exclude one pattern from glob match - Unix Stack Exchange
Suppose that you have some file foo.sh that you want exclude from your operation, yet you want to add csv to every other...
Read more >
How to use --exclude glob patterns? #1928 - GitHub
Background I've been reading through issues like #759 and it seems that Universal Ctags does support some globbing patterns for --exclude.
Read more >
glob() - Buck
exclude (defaults to [] ) A list of patterns that identify files that should be removed from the set specified by the first...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found