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.

hashFiles() function should accept multiple patterns

See original GitHub issue

Describe the enhancement

I’m using actions/cache with the hashFiles() function as documented. But when multiple match patterns are required for an adequate cache key, it’s gets tedious to write all the functions and I end up with a very long key:

    - name: Restore NuGet package cache
      uses: actions/cache@v1
      with:
        path: ${{ github.workspace }}/.nuget/packages
        key: ${{ runner.os }}-nuget-${{ hashFiles('global.json') }}-${{ hashFiles('**/nuget.config') }}-${{ hashFiles('**/*proj') }}-${{ hashFiles('**/*.props') }}-${{ hashFiles('**/*.targets') }}

What I’d like instead is to simplify the key to just:

key: ${{ runner.os }}-nuget-${{ hashFiles('global.json;**/nuget.config;**/*proj;**/*.props;**/*.targets') }}

Notice how I only have to call hashFiles once and the result is a single hash in the key instead of many hyphenated hashes.

Additional information

Jamie Cansdale from GitHub support looked this up for me and reported:

I’ve managed to turn up some documentation for the hashFiles function here: https://github.com/actions/runner/blob/master/docs/adrs/0279-hashFiles-expression-function.md

Unfortunately it includes the following note:

Question: Do we need to support more than one match patterns? Ex: hashFiles(‘**/package-lock.json’, ‘!toolkit/core/package-lock.json’, ‘!toolkit/io/package-lock.json’) Answer: Only support single match pattern for GA, we can always add later.

I looks like the globber uses newlines as a delimiter 😢 https://github.com/actions/toolkit/blob/master/packages/glob/src/glob.ts#L9

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
ericsciplecommented, Jul 21, 2020

@sagikazarmark hashFiles accepts multiple parameters now. I forgot to update the issue.

4reactions
ericsciplecommented, Jan 24, 2020

We’re planning to add as separate parameters: hashFiles('**/package-lock.json', '!toolkit/core/package-lock.json', ...). Hopefully will get to this soon

Read more comments on GitHub >

github_iconTop Results From Across the Web

Expressions
hashFiles. Returns a single hash for the set of files that matches the path pattern. You can provide a single path pattern or...
Read more >
C# Threading - Reading and hashing multiple files ...
Pipeline pattern implementation: three stages: calculate hash, match, ... 1) CalculateHashesImpl() should store all calculated hashes here ...
Read more >
hashFiles in github action displays incorrect hash
So everything that happens in that script is not being considered, because all hashFiles() calls are resolved before everything is being ...
Read more >
7 Github Actions Tricks I Wish I Knew Before I Started
Here are 7 tricks with github actions that changed my life (or at least my CI/CD pipeline). These tricks helped me create a...
Read more >
Compare two files using Hashing in Python
hashfile() returns the hash of the file in base16 (hexadecimal format). We call the same function for both the files and store their...
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