2828 components : >
2929 ${{ steps.arrange-components.outputs.for_all == 'true' && env.ALL_COMPONENTS
3030 || format('["{0}"]', steps.arrange-components.outputs.component) }}
31+ latest : ${{ steps.check-latest.outputs.latest }}
3132 steps :
33+ # Do not decide by branch name. This file is shared with
34+ # maintenance branches (e.g. v1.19), so compare with all release tags.
35+ - id : check-latest
36+ env :
37+ GH_TOKEN : ${{ github.token }}
38+ REF_NAME : ${{ github.ref_name }}
39+ run : |
40+ # Fail loudly if listing tags fails: silently falling back to
41+ # latest=false would skip latest, v1 and edge tags without any error.
42+ set -o pipefail
43+ normalize() {
44+ sed --regexp-extended 's/-debian(-(amd64|arm64|armhf))?-/-/' | grep --extended-regexp '^v1\.[0-9]+\.[0-9]+-[0-9]+\.[0-9]+$'
45+ }
46+ current=$(echo "$REF_NAME" | normalize || true)
47+ newest=$(gh api --paginate "repos/${GITHUB_REPOSITORY}/tags?per_page=100" --jq '.[].name' \
48+ | normalize | sort --version-sort | tail --lines=1)
49+ if [ -z "$newest" ]; then
50+ echo "::error::failed to get the newest release tag from the tag list"
51+ exit 1
52+ fi
53+ echo "current=$current newest=$newest"
54+ if [ -n "$current" ] && [ "$current" = "$newest" ]; then
55+ echo "latest=true" >> "$GITHUB_OUTPUT"
56+ else
57+ echo "latest=false" >> "$GITHUB_OUTPUT"
58+ fi
3259 - id : arrange-components
3360 run : |
3461 echo "for_all=true" >> "$GITHUB_OUTPUT"
6693 username : ${{ secrets.DOCKER_HUB_USERNAME }}
6794 password : ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
6895 - name : Setup tags
96+ env :
97+ IS_LATEST : ${{ needs.define-matrix.outputs.latest }}
6998 run : |
7099 set -x
71100 component=${{ matrix.component }}
@@ -81,6 +110,13 @@ jobs:
81110 tags=$(echo $target | cut -d':' -f2-)
82111 push_tags=""
83112 for tag in $(echo "$tags" | tr , ' '); do
113+ if [ "$IS_LATEST" != "true" ]; then
114+ case $tag in
115+ edge-*)
116+ continue
117+ ;;
118+ esac
119+ fi
84120 if [ -z "$push_tags" ]; then
85121 push_tags="${{ env.REPOSITORY }}:$tag"
86122 else
@@ -158,6 +194,8 @@ jobs:
158194 username : ${{ secrets.DOCKER_HUB_USERNAME }}
159195 password : ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
160196 - name : Create manifest
197+ env :
198+ IS_LATEST : ${{ needs.define-matrix.outputs.latest }}
161199 run : |
162200 component=${{ matrix.component }}
163201 for target in $(make echo-all-images); do
@@ -212,16 +250,18 @@ jobs:
212250 ${{ env.REPOSITORY }}:${AMD64TAG} \
213251 ${{ env.REPOSITORY }}:${ARM64TAG} \
214252 ${{ env.REPOSITORY }}:${ARMHFTAG}
215- # latest
216- docker buildx imagetools create -t ${{ env.REPOSITORY }}:latest \
217- ${{ env.REPOSITORY }}:${AMD64TAG} \
218- ${{ env.REPOSITORY }}:${ARM64TAG} \
219- ${{ env.REPOSITORY }}:${ARMHFTAG}
220- # v1
221- docker buildx imagetools create -t ${{ env.REPOSITORY }}:v1 \
222- ${{ env.REPOSITORY }}:${AMD64TAG} \
223- ${{ env.REPOSITORY }}:${ARM64TAG} \
224- ${{ env.REPOSITORY }}:${ARMHFTAG}
253+ if [ "$IS_LATEST" = "true" ]; then
254+ # latest
255+ docker buildx imagetools create -t ${{ env.REPOSITORY }}:latest \
256+ ${{ env.REPOSITORY }}:${AMD64TAG} \
257+ ${{ env.REPOSITORY }}:${ARM64TAG} \
258+ ${{ env.REPOSITORY }}:${ARMHFTAG}
259+ # v1
260+ docker buildx imagetools create -t ${{ env.REPOSITORY }}:v1 \
261+ ${{ env.REPOSITORY }}:${AMD64TAG} \
262+ ${{ env.REPOSITORY }}:${ARM64TAG} \
263+ ${{ env.REPOSITORY }}:${ARMHFTAG}
264+ fi
225265 fi
226266 # v1.xx-debian-n.m
227267 if [ ${MULTIARCH_AMD64_SHORT_TAG} != ${MULTIARCH_ARM64_SHORT_TAG} -o ${MULTIARCH_AMD64_SHORT_TAG} != ${MULTIARCH_ARMHF_SHORT_TAG} -o ${MULTIARCH_ARM64_SHORT_TAG} != ${MULTIARCH_ARMHF_SHORT_TAG} ]; then
@@ -238,11 +278,13 @@ jobs:
238278 ${{ env.REPOSITORY }}:${SHORT_ARM64TAG} \
239279 ${{ env.REPOSITORY }}:${SHORT_ARMHFTAG}
240280 fi
241- # edge-debian
242- docker buildx imagetools create -t ${{ env.REPOSITORY }}:edge-debian \
243- ${{ env.REPOSITORY }}:edge-debian-amd64 \
244- ${{ env.REPOSITORY }}:edge-debian-arm64 \
245- ${{ env.REPOSITORY }}:edge-debian-armhf
281+ if [ "$IS_LATEST" = "true" ]; then
282+ # edge-debian
283+ docker buildx imagetools create -t ${{ env.REPOSITORY }}:edge-debian \
284+ ${{ env.REPOSITORY }}:edge-debian-amd64 \
285+ ${{ env.REPOSITORY }}:edge-debian-arm64 \
286+ ${{ env.REPOSITORY }}:edge-debian-armhf
287+ fi
246288 echo "MULTIARCH_AMD64_TAG=${MULTIARCH_AMD64_TAG}" >> ${GITHUB_ENV}
247289 echo "MULTIARCH_AMD64_SHORT_TAG=${MULTIARCH_AMD64_SHORT_TAG}" >> ${GITHUB_ENV}
248290 echo "AMD64TAG=${AMD64TAG}" >> ${GITHUB_ENV}
0 commit comments