From 802dd1881bdbcbc9c5ffa182a2669984d8988f55 Mon Sep 17 00:00:00 2001 From: dwertent Date: Wed, 28 Aug 2024 16:30:30 -0400 Subject: [PATCH] Tag image as latest only when releasing the latest tag Signed-off-by: dwertent --- .github/workflows/docker_release.yml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker_release.yml b/.github/workflows/docker_release.yml index 2a068b1f6..d8b2313ce 100644 --- a/.github/workflows/docker_release.yml +++ b/.github/workflows/docker_release.yml @@ -5,8 +5,28 @@ on: types: [released, prereleased] jobs: + fetch-latest-tag: + runs-on: ubuntu-latest + outputs: + latest_tag: ${{ steps.get_latest_tag.outputs.latest_tag }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Fetch all tags + run: git fetch --tags + + - name: Get the latest tag + id: get_latest_tag + run: | + latest_tag=$(git tag -l | sort -V | tail -n 1) + echo "::set-output name=latest_tag::${latest_tag}" + docker: runs-on: ubuntu-latest + needs: fetch-latest-tag permissions: contents: read packages: write @@ -30,7 +50,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Set latest tag - if: github.event.action == 'released' + if: github.event.action == 'released' && github.ref_name == needs.fetch-latest-tag.outputs.latest_tag run: | echo "DOCKER_TAGS=${{ env.DOCKER_TAGS }},ghcr.io/${{ github.repository }}:latest" >> $GITHUB_ENV