on:
  push:
    tags: ["*"]

jobs:
  docker_build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        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 DockerHub
        uses: docker/login-action@v1
        with:
          registry: gitea.le-memese.com
          username: ${{ gitea.actor }}
          password: ${{ secrets.PACKAGE_PAT }}
      - name: Build and push
        uses: docker/build-push-action@v6
        with:
          context: .
          push: true
          file: ./Dockerfile
          platforms: linux/amd64
          target: prod
          tags: |
            gitea.le-memese.com/s3rius/zangramru:latest
            gitea.le-memese.com/s3rius/zangramru:${{ gitea.ref_name }}
  helm_deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Setup helm
        uses: azure/setup-helm@v4.3.0
      - name: Deploy
        run: |
          echo "${{secrets.KUBE_CONFIG}}" > /tmp/kubeconfig
          helm upgrade \
            zangramru \
            'oci://gitea.le-memese.com/common/charts/py-app' \
            --install \
            --wait \
            --create-namespace \
            --rollback-on-failure \
            --kubeconfig "/tmp/kubeconfig" \
            --namespace=zangramru \
            --values=./values.yaml \
            --version "0.1.0" \
            --set "image.tag=${{ gitea.ref_name }}" \
            --set "env.ZANGRAMRU_DB_PASS=${{secrets.DB_PASSWORD}}"
