Runner: hashFiles() function should accept multiple patterns

Created on 23 Jan 2020  路  8Comments  路  Source: actions/runner

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

Runner Feature papercut

Most helpful comment

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

All 8 comments

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

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

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

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

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

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

Awesome, thanks!

I receive this error today when providing multiple arguments

Error: Key Validation Error: cache-{{ hashFiles('./paket.lock', './yarn.lock') }} cannot contain commas.
Was this page helpful?
0 / 5 - 0 ratings