.github/workflows/ci.yml

name: CI
on:
  pull_request:
  push:
    branches: [main]
permissions:
  contents: read
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true
jobs:
  lefthook:
    if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
    runs-on: ${{ fromJSON('["self-hosted", "homelab"]') }}
    timeout-minutes: 10
    steps:
      - name: Start timer
        run: echo "START_EPOCH=$(date +%s)" >> "$GITHUB_ENV"
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          fetch-depth: 0
          clean: false
      - run: |
          git clean -fd
          if [ -L target ]; then rm target; fi
          mkdir -p target
          echo "MBX_DISABLE=1" >> "$GITHUB_ENV"
          mise trust --quiet
          mise install --yes
          mise bin-paths >> "$GITHUB_PATH"
          mise env --dotenv >> "$GITHUB_ENV"
      - run: lefthook run pre-commit --all-files --force --no-auto-install
      - run: node examples/verify_post_edit_hook.mjs target/debug/xpd
      - run: git diff --exit-code HEAD
      - run: lefthook run pre-push --force --no-auto-install
      - name: Enforce CI performance budget
        run: |
          RUNNER_ENVIRONMENT=self-hosted python3 .github/scripts/check_ci_budget.py --enforce --workflow ci \
            --start-epoch "$START_EPOCH" \
            --self-hosted-max-seconds 120 \
            --hosted-max-seconds 240