I am running the following code in github actions
- name: Verify Workflow integrity
run: |
echo "some text" > test/apps/test/test.yml
cat test/apps/test/test.yml
echo "${{ hashFiles('test/apps/test/*.yml') }}"
echo "alter text" > test/apps/test/test.yml
cat test/apps/test/test.yml
echo "${{ hashFiles('test/apps/test/*.yml') }}"
It produces the following output
| some text
| e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
| alter text
| e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Since the text in the file has changed, I am expecting a different hash. However, it produces the same hash. Am I missing something?
basically, I want to find the hash of all the files in test/apps/test directory
The whole "script" in your run section is executed at once. Before execution, the "script" is being evaluated and all variables and/or function calls are resolved.
So before the "script" is being executed, hashFiles('test/apps/test/*.yml') is being evaluated (twice) with the result being e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855. Then the following resolved version of your "script" is being executed:
echo "some text" > test/apps/test/test.yml
cat test/apps/test/test.yml
echo "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
echo "alter text" > test/apps/test/test.yml
cat test/apps/test/test.yml
echo "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
So everything that happens in that script is not being considered, because all hashFiles() calls are resolved before everything is being executed.
A solution would be to split things up in multiple runs:
- name: Verify Workflow integrity
run: |
echo "some text" > test/apps/test/test.yml
cat test/apps/test/test.yml
- run: echo "${{ hashFiles('test/apps/test/*.yml') }}"
- run: |
echo "alter text" > test/apps/test/test.yml
cat test/apps/test/test.yml
- run: echo "${{ hashFiles('test/apps/test/*.yml') }}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With