# Tier 3 gate and publication. The act-runner registration is stored in an
# emptyDir: after a runner pod restart, re-register it before debugging CI.
name: verify-and-publish

on:
  push:
    branches: [main]
  pull_request:

jobs:
  gate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm
      - run: npm install --package-lock=false --prefer-offline
      - run: npm run lint
      - run: ./.agents/scripts/gate.sh
      - name: visual regression
        run: |
          npx playwright install --with-deps chromium
          node .agents/scripts/visual-regression.mjs
      - uses: actions/upload-artifact@v4
        if: failure()
        with:
          name: screenshots
          path: .agents/snapshots/diff/

  publish:
    if: github.ref == 'refs/heads/main'
    needs: gate
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm
      - run: npm install --package-lock=false --prefer-offline
      - run: npm run build
      - name: Publish generated site to pages
        run: |
          git config user.name 'gitea-actions[bot]'
          git config user.email 'gitea-actions[bot]@users.noreply.local'
          git switch --orphan pages
          git rm -rf .
          cp -a dist/. .
          git add --all
          git commit -m 'chore: publish site'
          git push --force origin HEAD:pages
