@@ -138,46 +138,81 @@ jobs:
138138 runs-on : ubuntu-latest
139139 needs : [setup, build, unit-test, codeql-scan, container-scanning]
140140 steps :
141- - name : Log in to registry
142- uses : docker/login-action@v3
143- with :
144- registry : ${{ env.REGISTRY }}
145- username : ${{ github.actor }}
146- password : ${{ secrets.GITHUB_TOKEN }}
147- - name : Build latest image
141+ - name : Tag image with 'latest'
142+ shell : bash
148143 run : |
149- docker pull ${{ needs.setup.outputs.image_base }}:${{ needs.setup.outputs.commit_sha_short }}
150- docker tag ${{ needs.setup.outputs.image_base }}:${{ needs.setup.outputs.commit_sha_short }} ${{ needs.setup.outputs.image_base }}:latest
151- docker push ${{ needs.setup.outputs.image_base }}:latest
144+ set -euo pipefail
145+ IMAGE_BASE="${{ needs.setup.outputs.image_base }}"
146+ SHORT_SHA="${{ needs.setup.outputs.commit_sha_short }}"
147+
148+ # ensure skopeo is available
149+ if ! command -v skopeo >/dev/null 2>&1; then
150+ sudo apt-get update -y
151+ sudo apt-get install -y --no-install-recommends skopeo
152+ fi
153+
154+ skopeo copy \
155+ --src-creds "${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}" \
156+ --dest-creds "${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}" \
157+ docker://"${IMAGE_BASE}:${SHORT_SHA}" docker://"${IMAGE_BASE}:latest"
152158
153159 release :
154160 name : release
155161 if : github.event_name == 'release' && github.event.action == 'published'
156162 runs-on : ubuntu-latest
157163 needs : setup
158164 steps :
159- - name : Log in to registry
160- uses : docker/login-action@v3
161- with :
162- registry : ${{ env.REGISTRY }}
163- username : ${{ github.actor }}
164- password : ${{ secrets.GITHUB_TOKEN }}
165-
166- - name : Check out the release tag
167- uses : actions/checkout@v4
168- with :
169- ref : ${{ github.event.release.tag_name }}
170- fetch-depth : 0
171-
172- - name : Resolve commit sha for the tag
165+ - name : Get commit sha for the tag
173166 id : rev
174167 shell : bash
168+ env :
169+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
175170 run : |
176- SHORT_SHA="$(git rev-parse --short=12 HEAD)"
171+ set -euo pipefail
172+ TAG="${{ github.event.release.tag_name }}"
173+ REPO="${{ github.repository }}"
174+
175+ # ensure jq is available
176+ if ! command -v jq >/dev/null 2>&1; then
177+ sudo apt-get update -y
178+ sudo apt-get install -y --no-install-recommends jq
179+ fi
180+
181+ # ensure gh cli is available
182+ if ! command -v gh >/dev/null 2>&1; then
183+ sudo apt-get update -y
184+ sudo apt-get install -y --no-install-recommends gh
185+ fi
186+
187+ REF_JSON="$(gh api "repos/${REPO}/git/refs/tags/${TAG}")"
188+ OBJ_SHA="$(jq -r '.object.sha' <<<"$REF_JSON")"
189+ OBJ_TYPE="$(jq -r '.object.type' <<<"$REF_JSON")"
190+
191+ if [ "$OBJ_TYPE" = "tag" ]; then
192+ TAG_OBJ="$(gh api "repos/${REPO}/git/tags/${OBJ_SHA}")"
193+ COMMIT_SHA="$(jq -r '.object.sha' <<<"$TAG_OBJ")"
194+ else
195+ COMMIT_SHA="$OBJ_SHA"
196+ fi
197+
198+ SHORT_SHA="${COMMIT_SHA:0:12}"
177199 echo "short_sha=${SHORT_SHA}" >> "$GITHUB_OUTPUT"
178200
179201 - name : Tag image with release tag
202+ shell : bash
180203 run : |
181- docker pull ${{ needs.setup.outputs.image_base }}:${{ steps.rev.outputs.short_sha }}
182- docker tag ${{ needs.setup.outputs.image_base }}:${{ steps.rev.outputs.short_sha }} ${{ needs.setup.outputs.image_base }}:${{ github.event.release.tag_name }}
183- docker push ${{ needs.setup.outputs.image_base }}:${{ github.event.release.tag_name }}
204+ set -euo pipefail
205+ IMAGE_BASE="${{ needs.setup.outputs.image_base }}"
206+ SHORT_SHA="${{ steps.rev.outputs.short_sha }}"
207+ RELEASE_TAG="${{ github.event.release.tag_name }}"
208+
209+ # ensure skopeo is available
210+ if ! command -v skopeo >/dev/null 2>&1; then
211+ sudo apt-get update -y
212+ sudo apt-get install -y --no-install-recommends skopeo
213+ fi
214+
215+ skopeo copy \
216+ --src-creds "${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}" \
217+ --dest-creds "${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}" \
218+ docker://"${IMAGE_BASE}:${SHORT_SHA}" docker://"${IMAGE_BASE}:${RELEASE_TAG}"
0 commit comments