name: Release Docker Image
on:
  push:
    tags:
      - v*

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Login to Gitea
        uses: docker/login-action@v3
        with:
          registry: ${{ vars._CI_REGISTRY }}
          username: ${{ vars._CI_REGISTRY_USER }}
          password: ${{ secrets._CI_REGISTRY_ACCESS_TOKEN }}

      # Remarks: Setting up QEMU and Buildx are useful for cross-platform build but it will slow the CI pipeline.

      # - name: Set up QEMU
      #   uses: docker/setup-qemu-action@v3

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

      - name: Build and push
        uses: docker/build-push-action@v6
        with:
          secrets: JIG_SOFTWARE_GITEA_DEPLOYMENT_TOKEN=${{ secrets._CI_REGISTRY_ACCESS_TOKEN }}
          push: true
          tags: ${{ vars._CI_REGISTRY }}/${{ gitea.repository }}:${{ gitea.ref_name }},${{ vars._CI_REGISTRY }}/${{ gitea.repository }}:latest
