name: Server - Mark docker image as latest

on:
  release:
    types: [published]

env:
  REGISTRY: ghcr.io

jobs:
  tag-latest:
    runs-on: ubuntu-latest

    steps:
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Log in to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Extract version from tag
        run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV

      - name: Tag as latest the version image
        run: |
          docker buildx imagetools create --tag ${{ env.REGISTRY }}/${{ vars.SERVER_IMAGE_NAME }}:latest ${{ env.REGISTRY }}/${{ vars.SERVER_IMAGE_NAME }}:${{ env.VERSION }}
