version: "1"
name: Publish Docker Image

on:
  push:
    tags:
      - "*"

jobs:
  build:
    name: Publish Docker Image
    runs-on: ubuntu-latest

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

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

      - name: Login to Registry
        run: echo "${{ secrets.ACCESS_TOKEN }}" \
          | docker login git.altaiar.dev -u "${{ secrets.USERNAME }}" --password-stdin

      - name: Build & Tag Image
        run: |
          docker build \
            --build-arg APP_VERSION=${{ gitea.ref_name }} \
            --label org.opencontainers.image.version=${{ gitea.ref_name }} \
            -t git.altaiar.dev/${{ gitea.repository }}:${{ gitea.ref_name }} .
          docker tag \
            git.altaiar.dev/${{ gitea.repository }}:${{ gitea.ref_name }} \
            git.altaiar.dev/${{ gitea.repository }}:latest

      - name: Push Images
        run: |
          docker push git.altaiar.dev/${{ gitea.repository }}:${{ gitea.ref_name }}
          docker push git.altaiar.dev/${{ gitea.repository }}:latest
