@@ -3,6 +3,8 @@ name: Build and push container image
33# Configures this workflow to run every time a tag is created
44on :
55 push :
6+ tags-ignore :
7+ - operator/*
68 paths :
79 - agent/**
810 - containers/agent.Dockerfile
2022# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
2123jobs :
2224 build-and-push-agent :
25+ # only run for tags on the main branch
26+ if : ${{ github.ref == 'refs/heads/main' }}
2327 runs-on : ubuntu-latest
2428 # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
2529 permissions :
@@ -51,10 +55,25 @@ jobs:
5155 run : |
5256 apt-get update && apt-get install -y make git jq
5357 cd agent
54- export TAGS="-t ${REGISTRY@L}/${{env.IMAGE_NAME}}/agent:${{ github.sha }}"
58+ # if this is a tag build, use the tag as the version, otherwise use the sha
59+ TAGS="-t ${REGISTRY@L}/${{env.IMAGE_NAME}}/agent:${{ github.sha }}
60+ case ${{ github.ref_type }} in
61+ branch)
62+ # The last tag + current git sha
63+ export AGENT_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0")+${{ github.sha }}
64+ ;;
65+ tag)
66+ # The version part of the tag
67+ export AGENT_VERSION=$(echo "${{ github.ref_name }}" | cut -f 2 -d /)
68+ TAGS="$TAGS -t ${REGISTRY@L}/${{env.IMAGE_NAME}}/agent:${AGENT_VERSION}"
69+ ;;
70+ *)
71+ echo "Unkown type ${{ github.ref_type }}"
72+ exit 1
73+ ;;
74+ esac
75+ export TAGS=$TAGS
5576 export REGISTRY=${REGISTRY@L}
56- # Get the last tag and use it as the env var AGENT_VERSION if it doesn't exist use 0.0.0+{github.sha}
57- export AGENT_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0+${{ github.sha }}")
5877 make docker-build-only agent_version=${AGENT_VERSION}
5978 cat metadata.json
6079 echo "digest=$(cat metadata.json | jq -r .\"containerimage.digest\")" >> $GITHUB_OUTPUT
0 commit comments