I want to build a docker image using a GitHub action, migrating from TeamCity.
In the build script, I want to tag the image with a combination of branch and commit, e.g.
A handy way to get the currrent branch and commit sha on the workflow could be getting it and saving on a "variable".
- name: Declare some variables
id: vars
shell: bash
run: |
echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: Another step
run: |
echo "Branch: ${{ steps.vars.outputs.branch }}"
echo "Sha: ${{ steps.vars.outputs.sha_short }}"
Maybe your docker-build.sh
could receive the branch and she as parameter, os the full version as parameter.
- name: Create docker image
run: ./docker-build.sh "${{ steps.vars.outputs.branch }}.${{ steps.vars.outputs.sha_short }}"
OR JUST
- name: Create docker image
run: ./docker-build.sh "${GITHUB_REF#refs/heads/}.${GITHUB_SHA}"
On this action you can see many tests I done to see what works, what don't.