Skip to content

Commit

Permalink
Tag image as latest only when releasing the latest tag
Browse files Browse the repository at this point in the history
Signed-off-by: dwertent <[email protected]>
  • Loading branch information
dwertent committed Aug 28, 2024
1 parent a983877 commit 802dd18
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion .github/workflows/docker_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 802dd18

Please sign in to comment.