Reputation: 73
Would like to generate a checksum via Github Actions and set to env variable CHECKSUM like so:
- name: Create checksum
run: echo CHECKSUM=$(shasum -a 1 foo.zip | awk '{ print $1 }') >> $CHECKSUM
but it returns an error:
/home/runner/work/_temp/b6f2fd2a-359b-4052-a439-4f5b0a629a85.sh: line 1: $CHECKSUM: ambiguous redirect
Upvotes: 2
Views: 2410
Reputation: 4759
Below git hub action generates md5
of the file result.json using md5sum
and generates and output named original_md5
- name: MD5 of result json file
id: original_md5_results
shell: bash
run: |
set -e
echo "original_md5=$(md5sum result.json | awk '{ print $1 }')" >> $GITHUB_OUTPUT
Now in subsequent step where we need this value.
- name: Compare MD5 post processing
shell: bash
run: |
set -e
originalMD5="${{steps.original_md5_results.outputs.original_md5}}"
updatedMD5="$(md5sum result.json | awk '{ print $1 }')"
echo "Original MD5 :: $originalMD5"
echo "Updated MD5 :: $updatedMD5"
if [ "$originalMD5" = "$updatedMD5" ]; then
echo "No change results."
else
echo 1>&2 "ERROR:: result.json compromised. Please re-check
exit 1
fi
Importan Steps:
id: original_md5_results
$GITHUB_OUTPUT
in key=value
pattern in our case "original_md5=md5valueofthefile"
${{steps.original_md5_results.outputs.original_md5}}
Upvotes: 0
Reputation: 52132
Setting environment variables works differently: you append to a file whose name is stored in the $GITHUB_ENV
variable, i.e., something like
run: |
echo CHECKSUM="$(shasum foo.zip | awk '{ print $1 }')" >> "$GITHUB_ENV"
Upvotes: 2