Observe the following, noting that inputs.root-path
is set to env
.
- name: DEBUG
run: |
set -x
ls -l repo/${{ inputs.root-path }}/package-lock.json
echo "HASH: ${{ hashFiles('repo/${{ inputs.root-path }}/package-lock.json') }}"
echo "HASH: ${{ hashFiles('repo/env/package-lock.json') }}"
Output when run via GHA ubuntu-22.04
runner:
-rw-r--r-- 1 runner docker 474757 Nov 15 16:37 repo/env/package-lock.json
HASH:
HASH: faedfd4f973187a14d71ddedb368bb5d6b76c22cf03838fe3e5e5a0335b7ab35
Note that the first call to hashFiles
does not seem to correctly "intepret" the argument 'repo/${{ inputs.root-path }}/package-lock.json'
. Is this "just how it works"? How can I call hashFiles
with a variable input?
2
Answers
You can use the
format
function.See also:
Note: The solution is not tested
Currently, such nesting of expressions is not supported.
However,
hashFiles
function can be provided its input in different ways e.g.:*
glob pattern if there’s only one intermediate directory and only one such file exists depending on your use case:**
glob pattern for multiple intermediate directories:format
function as answered before:or, using an intermediate env var:
glob.hashFiles
: