From e5550a006e6a7c7f923a248f05663461b35c01ab Mon Sep 17 00:00:00 2001 From: Matej Janezic Date: Sat, 7 Dec 2024 17:34:49 +0000 Subject: [PATCH] feat: update github workflow --- .github/workflows/build-docker.yml | 39 +++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index a23467c..41b1f96 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -18,10 +18,32 @@ jobs: - uses: docker/setup-qemu-action@v3 - uses: docker/setup-buildx-action@v3 - - run: echo "IMAGE_TAG=latest" >> $GITHUB_ENV - if: github.ref_name == 'main' - - run: echo "IMAGE_TAG=${GITHUB_REF##*/}" >> $GITHUB_ENV - if: startsWith(github.ref, 'refs/tags/v') + - name: Set ALL_TAGS + env: + REPOSITORY: '${{ github.repository }}' + run: | + # tag main if main branch + if [[ "${{ github.ref_name }}" == "main" ]]; then + image_tags=("main") + # tag with tag name if tag + elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then + image_tags=("${{ github.ref_name }}") + # tag with latest if tag is a new major, minor or patch version + if [[ "${{ github.ref_name}}" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then + image_tags+=("latest") + fi + fi + + lc_repo=${REPOSITORY,,} + + image_paths=() + for tag in ${image_tags[@]}; do + image_paths+=("ghcr.io/$lc_repo/go-client:$tag") + done + + # join with ',' and then skip first character + ALL_TAGS=$(printf ',%s' "${image_paths[@]}") + echo "ALL_TAGS=${ALL_TAGS:1}" >>$GITHUB_ENV - name: Login to ghcr.io uses: docker/login-action@v3 @@ -30,12 +52,6 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: set lower case repository - run: | - echo "REPOSITORY_LC=${REPOSITORY,,}" >>${GITHUB_ENV} - env: - REPOSITORY: '${{ github.repository }}' - - name: Build and push default image uses: docker/build-push-action@v5 with: @@ -43,5 +59,4 @@ jobs: file: go-client/Dockerfile platforms: linux/amd64,linux/arm64 push: true - tags: | - ghcr.io/${{ env.REPOSITORY_LC }}/go-client:${{ env.IMAGE_TAG }} + tags: ${{ env.ALL_TAGS }}