44 push :
55 branches :
66 - ' master'
7+ workflow_dispatch :
8+ inputs :
9+ ref :
10+ description : ' Git ref (branch or tag) to build'
11+ required : false
12+ default : ' master'
13+ image_tag :
14+ description : ' Docker image tag to push (defaults to <branch>-<short-sha>)'
15+ required : false
16+ default : ' '
717
818jobs :
919 build-docker-image :
2232 - uses : actions/checkout@v2
2333
2434 - name : Set up JDK 21
25- uses : actions/setup-java@v2
35+ uses : actions/setup-java@v4
2636 with :
2737 java-version : ' 21'
2838 distribution : ' temurin'
@@ -43,10 +53,42 @@ jobs:
4353 username : ${{ github.actor }}
4454 password : ${{ secrets.GITHUB_TOKEN }}
4555
56+ - name : Compute image tag
57+ id : meta
58+ shell : bash
59+ run : |
60+ REF_INPUT='${{ inputs.ref }}'
61+ if [ -n "$REF_INPUT" ]; then
62+ REF="$REF_INPUT"
63+ else
64+ REF='${{ github.ref }}'
65+ fi
66+ # normalize to short branch/tag name
67+ REF_NAME="${REF##*/}"
68+ SHORT_SHA="${GITHUB_SHA::7}"
69+ if [ -n '${{ inputs.image_tag }}' ]; then
70+ TAG='${{ inputs.image_tag }}'
71+ else
72+ TAG="${REF_NAME}-${SHORT_SHA}"
73+ fi
74+ echo "IMAGE_TAG=$TAG" >> "$GITHUB_ENV"
75+ echo "REF_NAME=$REF_NAME" >> "$GITHUB_ENV"
76+
4677 - name : Build and push
4778 uses : docker/build-push-action@v4
4879 with :
4980 context : ' .'
5081 file : deploy/qyoga/Dockerfile
5182 push : true
52- tags : ghcr.io/ergonomic-code/trainer-advisor:latest
83+ tags : |
84+ ghcr.io/ergonomic-code/trainer-advisor:${{ env.IMAGE_TAG }}
85+
86+ - name : Also tag as latest (master only)
87+ if : github.event_name == 'push' && github.ref == 'refs/heads/master'
88+ uses : docker/build-push-action@v4
89+ with :
90+ context : ' .'
91+ file : deploy/qyoga/Dockerfile
92+ push : true
93+ tags : |
94+ ghcr.io/ergonomic-code/trainer-advisor:latest
0 commit comments