runner icon indicating copy to clipboard operation
runner copied to clipboard

hashFiles() function should accept multiple patterns

Open AArnott opened this issue 6 years ago • 9 comments

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 :cry: https://github.com/actions/toolkit/blob/master/packages/glob/src/glob.ts#L9

AArnott avatar Jan 23 '20 17:01 AArnott

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

ericsciple avatar Jan 24 '20 15:01 ericsciple

reassigning to @TingluoHuang since i think he fixed this recently? likely not rolled out to all accounts yet though.

ericsciple avatar Mar 04 '20 04:03 ericsciple

we haven't added support for multiple patterns, we just start using @actions/glob which is a prereq for supporting multiple patterns

TingluoHuang avatar Mar 04 '20 16:03 TingluoHuang

oh ok. I am making changes next to fix the display name bug. Will investigate this a bit more at that time.

ericsciple avatar Mar 04 '20 17:03 ericsciple

Any updates on this? I would love to use this feature.

sagikazarmark avatar Jul 20 '20 23:07 sagikazarmark

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

ericsciple avatar Jul 21 '20 13:07 ericsciple

Awesome, thanks!

sagikazarmark avatar Jul 21 '20 14:07 sagikazarmark

I receive this error today when providing multiple arguments

Error: Key Validation Error: cache-{{ hashFiles('./paket.lock', './yarn.lock') }} cannot contain commas.

blair55 avatar Dec 30 '20 23:12 blair55

In case this helps someone, @blair55, you were missing the $; it should say ${{.

Kurt-von-Laven avatar May 07 '22 19:05 Kurt-von-Laven