# Credits: https://www.vanmeeuwen.dev/blog/automating-docker-builds-with-gitea-actions
# https://gitea.com/gitea/runner-images/src/branch/main/.gitea/workflows/release.yaml

name: Build and push Docker image
run-name: Build ${{  github.ref_name }} image

on:
  push:
    tags:
      - "*"

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

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

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

      - name: Login to registry
        uses: docker/login-action@v2
        with:
          registry: gitea.7o7.cx
          username: ${{ secrets.REGISTRY_USER }}
          password: ${{ secrets.REGISTRY_PASSWORD }}

      - name: Set outputs
        id: vars
        env:
          BRANCH_NAME: ${{ github.ref_name }}
        run: |
          #echo branch_name="$BRANCH_NAME" | tee -a $GITHUB_OUTPUT
          #echo short_hash=$(git rev-parse --short HEAD) | tee -a $GITHUB_OUTPUT
          echo current_tag=$GITHUB_REF_NAME | tee -a $GITHUB_OUTPUT

      - name: Build and push
        uses: docker/build-push-action@v6
        with:
          context: .
          platforms: |
            linux/amd64
            linux/arm64
          pull: true
          push: true
          # Change when working on a different branch!
          tags: |
            gitea.7o7.cx/kittyteam/kittyfe:${{ steps.vars.outputs.current_tag }}
            gitea.7o7.cx/kittyteam/kittyfe:latest

      - name: Log out from registry
        if: always()
        run: docker logout gitea.7o7.cx
