# Runs the local gate (lean/Regula/DiagnosticsGate.lean) on a machine of GitHub's: for each pull # request, when called by another workflow (workflow_call), and when someone starts it by hand. It # is the command that the no-mistakes validation runs as its Test step # (.no-mistakes.yaml, `commands.test`). Beyond the local gate, this file checks the toolchain # archive's SHA-256 digest and runs one conditional fetch step that checks whether # `refs/remotes/origin/main` exists as a commit and, when absent, verifies `origin`'s unique exact # `refs/heads/main` ref via `git ls-remote`, fetches `refs/heads/main` (`--no-tags`), verifies that # `FETCH_HEAD` came from exact `branch 'main' of ` with the same OID and resolves to a commit, and # writes `refs/remotes/origin/main` via `git update-ref --no-deref` (stopping the job before # installing Lean if any check or fetch fails), deciding nothing else: its job has a checkout, that # conditional fetch, one step that installs Lean, and one that runs the gate. # # Why it is here: the gate starts with `lean --run` of a file of the change, so running it on a # change from outside the repository runs that change's code. Here it can run on a runner that # GitHub hosts, which GitHub documents as a new virtual machine for each job, before it runs on a # contributor's machine. # # The runner image is `ubuntu-24.04`, the image on which Ubuntu 24.04.5 LTS on x86-64 was observed as # a named platform (specification/README.md, "Ubuntu"). GitHub documents that it updates that image, # so a run is a run of the gate on the image version that its log states, and is no observation of # the platform. # # The toolchain is the archive of the release that `lean-toolchain` names, from Lean's releases on # GitHub, and the step fails unless that archive has the SHA-256 written in it. So a change of the # release that `lean-toolchain` names fails the step until the digest is that of the new release's # archive. No elan is installed: `lean-toolchain` gives only the version in the archive's address. # The digest is that of the archive as downloaded on 2026-11-20, whose Lean reports the release and # the commit that the checker reads (`Regula.Closed.pinnedLean`). # # The job fetches full history (`fetch-depth: 0`) and, when `refs/remotes/origin/main` is absent or # not a commit, populates `refs/remotes/origin/main` from `origin`'s verified exact `refs/heads/main` # ref so `lean/Regula/DiagnosticsGate.lean` can pass `--base-ref refs/remotes/origin/main` to # `no-comments check` for `git merge-base HEAD refs/remotes/origin/main` on pull requests, # tag-triggered `workflow_call` runs, and other non-`main` checkouts. # The job sets no time limit of its own, as the gate sets none, so GitHub's limit for a job applies. # The token can only read the repository (`permissions`), and the checkout keeps no credential # (`persist-credentials`). For direct pull-request runs, the event is `pull_request` and never # `pull_request_target`, which GitHub documents as running with the base repository's token and # secrets (other triggers are `workflow_call` and `workflow_dispatch`). The action is pinned by its # commit. name: gate on: pull_request: workflow_call: workflow_dispatch: permissions: contents: read jobs: gate: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false fetch-depth: 0 - name: Ensure refs/remotes/origin/main exists for merge-base check shell: bash run: | set -euo pipefail if ! git show-ref --verify --quiet refs/remotes/origin/main || ! git rev-parse --verify --quiet 'refs/remotes/origin/main^{commit}' >/dev/null; then LS_REMOTE_OUT="$(git ls-remote --heads --refs origin refs/heads/main)" MAIN_OID="" MAIN_COUNT=0 while IFS=$'\t' read -r oid ref; do if [ "$ref" = "refs/heads/main" ]; then MAIN_OID="$oid" MAIN_COUNT=$((MAIN_COUNT + 1)) fi done <<< "$LS_REMOTE_OUT" if [ "$MAIN_COUNT" -ne 1 ] || [ -z "$MAIN_OID" ]; then echo "Expected unique refs/heads/main on origin" >&2 exit 1 fi git fetch --no-tags origin refs/heads/main FETCH_HEAD_PATH="$(git rev-parse --git-path FETCH_HEAD)" if [ "$(wc -l < "$FETCH_HEAD_PATH")" -ne 1 ]; then echo "Expected single entry in FETCH_HEAD for refs/heads/main" >&2 exit 1 fi IFS= read -r FETCH_HEAD_LINE < "$FETCH_HEAD_PATH" FETCH_OID="$(git rev-parse --verify FETCH_HEAD)" EXPECTED_FETCH_PREFIX="${MAIN_OID}"$'\t\t'"branch 'main' of " if [ "$FETCH_OID" != "$MAIN_OID" ] || [ "${FETCH_HEAD_LINE:0:${#EXPECTED_FETCH_PREFIX}}" != "$EXPECTED_FETCH_PREFIX" ]; then echo "Fetched object did not resolve from exact refs/heads/main" >&2 exit 1 fi MAIN_COMMIT="$(git rev-parse --verify 'FETCH_HEAD^{commit}')" git update-ref --no-deref refs/remotes/origin/main "$MAIN_COMMIT" fi - name: Install the Lean that lean-toolchain names, by the SHA-256 of its archive run: | v="$(sed 's/^.*:v//' lean-toolchain)" curl -sSfL -o "$RUNNER_TEMP/lean.zip" "https://github.com/leanprover/lean4/releases/download/v$v/lean-$v-linux.zip" echo "92a996be487b48e1c2f2985be6b150490475c94d02f5a5e26665a9dab780902a $RUNNER_TEMP/lean.zip" | sha256sum --check unzip -q "$RUNNER_TEMP/lean.zip" -d "$RUNNER_TEMP" echo "$RUNNER_TEMP/lean-$v-linux/bin" >> "$GITHUB_PATH" - name: Run the local gate run: lean --run lean/Regula/DiagnosticsGate.lean local