Update Latest Docker Tag #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Latest Docker Tag | |
| on: | |
| workflow_dispatch: # Allows manual triggering from GitHub UI | |
| env: | |
| IMAGE_NAME: ghcr.io/${{ github.repository }} | |
| jobs: | |
| update-latest: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 1️⃣ Checkout the repository code | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 # Ensure we fetch all tags | |
| # 2️⃣ Get the latest version tag | |
| - name: Get latest Git tag | |
| run: | | |
| # Sort tags in descending order and take the first one | |
| LATEST_TAG=$(git tag --sort=-v:refname | head -n1) | |
| echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV | |
| echo "Latest tag detected: $LATEST_TAG" | |
| # 3️⃣ Log in to GitHub Container Registry | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # 4️⃣ Tag the image as latest | |
| - name: Update Docker latest tag | |
| run: | | |
| echo "Tagging Docker image $IMAGE_NAME:$LATEST_TAG as latest..." | |
| docker pull $IMAGE_NAME:$LATEST_TAG | |
| docker tag $IMAGE_NAME:$LATEST_TAG $IMAGE_NAME:latest | |
| docker push $IMAGE_NAME:latest |