name: ci

on:
  push:
    branches:
      - main
      - staging
    tags:
      - '*'

jobs:
  docker:
    runs-on: ubuntu-latest

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

      - name: Login to Docker Registry
        uses: docker/login-action@v2
        with:
          registry: ${{ vars.REGISTRY_URL }}
          username: ${{ vars.REGISTRY_USER }}
          password: ${{ secrets.REGISTRY_PASSWORD }}

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
        with:
          driver: remote
          endpoint: ${{ env.BUILDKIT_ARM64_ENDPOINT }}

      # The image contains both the Rust backend (server + worker binaries)
      # and the built frontend — see the multi-stage Dockerfile.
      - name: Build and Push Docker Image
        uses: docker/build-push-action@v6
        with:
          context: .
          platforms: linux/arm64
          push: true
          provenance: false
          tags: |
            ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${{ gitea.ref_type == 'tag' && gitea.ref_name || (gitea.ref_name == 'main' && 'latest' || gitea.ref_name) }}
            ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${{ gitea.sha }}
