name: PR Check

on:
  pull_request:

jobs:
  pr_check:
    name: Project PR check (linux-amd64)
    runs-on: linux-amd64
    steps:
      - name: Checkout repository
        shell: bash
        env:
          CI_MATCHA_GITEA_TOKEN: ${{ secrets.CI_MATCHA_GITEA_TOKEN }}
        run: |
          set -euo pipefail
          if [ -z "${CI_MATCHA_GITEA_TOKEN:-}" ]; then
            echo "Missing secrets.CI_MATCHA_GITEA_TOKEN" >&2
            exit 1
          fi
          basic=$(python3 -c 'import base64, os; print(base64.b64encode(("matcha:" + os.environ["CI_MATCHA_GITEA_TOKEN"]).encode()).decode())')
          git init .
          git remote add origin "https://git.hiabuto.net/${{ github.repository }}.git"
          git config --global http.https://git.hiabuto.net/.extraheader "AUTHORIZATION: basic ${basic}"
          git fetch --depth=1 origin "${{ github.event.pull_request.head.ref }}"
          git checkout --force FETCH_HEAD

      - name: Load central CI templates
        shell: bash
        run: |
          set -euo pipefail
          git submodule sync --recursive
          git submodule update --init --remote ci-templates
          git -C ci-templates rev-parse --short HEAD

      - name: Run config-driven PR check
        uses: ./ci-templates/actions/ci-runner
        with:
          command: pr-check
          config: ci-config.yaml
