@@ -18,10 +18,32 @@ jobs:
1818 - uses : docker/setup-qemu-action@v3
1919 - uses : docker/setup-buildx-action@v3
2020
21- - run : echo "IMAGE_TAG=latest" >> $GITHUB_ENV
22- if : github.ref_name == 'main'
23- - run : echo "IMAGE_TAG=${GITHUB_REF##*/}" >> $GITHUB_ENV
24- if : startsWith(github.ref, 'refs/tags/v')
21+ - name : Set ALL_TAGS
22+ env :
23+ REPOSITORY : ' ${{ github.repository }}'
24+ run : |
25+ # tag main if main branch
26+ if [[ "${{ github.ref_name }}" == "main" ]]; then
27+ image_tags=("main")
28+ # tag with tag name if tag
29+ elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then
30+ image_tags=("${{ github.ref_name }}")
31+ # tag with latest if tag is a new major, minor or patch version
32+ if [[ "${{ github.ref_name}}" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
33+ image_tags+=("latest")
34+ fi
35+ fi
36+
37+ lc_repo=${REPOSITORY,,}
38+
39+ image_paths=()
40+ for tag in ${image_tags[@]}; do
41+ image_paths+=("ghcr.io/$lc_repo/go-client:$tag")
42+ done
43+
44+ # join with ',' and then skip first character
45+ ALL_TAGS=$(printf ',%s' "${image_paths[@]}")
46+ echo "ALL_TAGS=${ALL_TAGS:1}" >>$GITHUB_ENV
2547
2648 - name : Login to ghcr.io
2749 uses : docker/login-action@v3
@@ -30,18 +52,11 @@ jobs:
3052 username : ${{ github.actor }}
3153 password : ${{ secrets.GITHUB_TOKEN }}
3254
33- - name : set lower case repository
34- run : |
35- echo "REPOSITORY_LC=${REPOSITORY,,}" >>${GITHUB_ENV}
36- env :
37- REPOSITORY : ' ${{ github.repository }}'
38-
3955 - name : Build and push default image
4056 uses : docker/build-push-action@v5
4157 with :
4258 context : go-client # Because GH actions are for kids and put protection on everything; https://stackoverflow.com/a/71159809/11276254
4359 file : go-client/Dockerfile
4460 platforms : linux/amd64,linux/arm64
4561 push : true
46- tags : |
47- ghcr.io/${{ env.REPOSITORY_LC }}/go-client:${{ env.IMAGE_TAG }}
62+ tags : ${{ env.ALL_TAGS }}
0 commit comments