How to get the short sha for the github workflow?
You can also set an environment variable with the short sha:
- name: Add SHORT_SHA env property with commit short sha
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
SHORT_SHA
can then be used like any other environment variable, e.g. like this:
- name: My step
run: myscript ${SHORT_SHA}
Found a possible solution here, using bash's parameter substitution
- name: Step
run: echo ${GITHUB_SHA::7}
As VonC mentioned, you can just compute the string yourself in a previous step.
- name: Set outputs
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: Check outputs
run: echo ${{ steps.vars.outputs.sha_short }}