#!/usr/bin/env bash
# .github/ci/ gate — the-hcma/repository-helpers convention; run by pre-pr-checks
# and ci.yml (see CONTRIBUTING.md "Governance tooling from repository-helpers").
set -euo pipefail
# Temp files and caches follow $TMPDIR/<project>/<branch>/<tool> (repository-helpers#832).
# CI exports REPOSITORY_HELPERS_DIR through the setup-tmp-layout action; without a clone, run unchanged.
layout_bin="${REPOSITORY_HELPERS_DIR:-$HOME/work/ai/repository-helpers}/scripts/dev/with-tmp-layout"
if [[ -z "${CI_TMP_LAYOUT:-}" ]]; then
  if [[ -x "$layout_bin" ]]; then
    CI_TMP_LAYOUT=1 exec "$layout_bin" uv -- bash "$0" "$@"
  elif [[ "${GITHUB_ACTIONS:-}" == true ]]; then
    echo 'ERROR: with-tmp-layout missing; add the setup-tmp-layout action step before this one' >&2
    exit 1
  fi
fi
# One sync for ruff + pyright (shared venv). Prefer this in CI over separate jobs.
# Assert against the committed lock before setup-python's `uv sync` — sync can
# rewrite uv.lock from pyproject and would hide release-please extra-files misses.
# assert-uv-lock-version uses uv-managed Python (no sync); requires setup-uv first.
bash .github/ci/assert-uv-lock-version
bash .github/ci/setup-python
uv run ruff check src tests
uv run ruff format --check src tests
uv run pyright
