Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 34 additions & 19 deletions .github/workflows/ci-gate-caller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@
# ./.github/workflows/ci-gate.yml (so the gate runs at the suite's own default-branch commit, with no
# second pin to drift), and the context is "CI / gate", the one this repository's `main` ruleset requires.
#
# workflow_run, schedule and workflow_dispatch all run from the DEFAULT branch, so a pull request cannot
# edit this file or the profile (profiles/ci-gate/hyperpolymath/proven-cicd-and-workflows.json) that
# judges it. The pull request that first adds this file therefore never receives `CI / gate` itself and
# is merged past the gate once (docs/CI-GATE.adoc, "Bootstrap"); the gate-pr job at the end removes that need.
# workflow_run and schedule run from the DEFAULT branch, so a pull request cannot edit this file or the
# profile (profiles/ci-gate/hyperpolymath/proven-cicd-and-workflows.json) that judges it on those paths.
# workflow_dispatch runs the file of the ref it is started from; the `gate` job does nothing for a
# workflow_dispatch from a ref other than the default branch (its `if:`). The pull request that first
# adds this file never receives `CI / gate` from the default-branch paths and is merged past the gate
# once (docs/CI-GATE.adoc, "Bootstrap"); the gate-pr job at the end removes that need.
#
# TAMPER GUARD: folded into the gate's verdict (docs/CI-GATE.adoc, "Tamper guard"). A pull request
# (a fork's included) that touches a gate file or a workflow named in the profile fails `CI / gate` until the
# OWNER applies `gate-change-approved` after the newest commit. AGENTS MUST NEVER APPLY THAT LABEL.
# Only the default-branch paths are trusted; gate-pr runs the pull request's own copy of this file.
#
# The job id MUST stay `gate` and the workflow name MUST stay `CI gate`: the reusable drops runs of
# that name from the evaluation, and the `if:` below keeps the gate from triggering itself.
# There is deliberately NO `concurrency:` block. The pull_request job at the end is permanent
# (docs/CI-GATE.adoc, "The pull_request start"); tests/ci-gate.sh pins its shape.
# Permissions: none at workflow level; each job grants exactly what the reusable asks for.
# No `secrets:` line: the reusable consumes none.
name: CI gate

Expand All @@ -27,29 +35,36 @@ on:
- cron: "7,22,37,52 * * * *"
workflow_dispatch: {}

permissions:
statuses: write
actions: read
contents: read
pull-requests: read
permissions: {}

jobs:
gate:
if: github.event_name != 'pull_request' && (github.event_name != 'workflow_run' || github.event.workflow_run.name != 'CI gate')
if: github.event_name != 'pull_request' && (github.event_name != 'workflow_run' || github.event.workflow_run.name != 'CI gate') && (github.event_name != 'workflow_dispatch' || github.ref == format('refs/heads/{0}', github.event.repository.default_branch))
permissions:
statuses: write
actions: read
contents: read
pull-requests: read
uses: ./.github/workflows/ci-gate.yml
with:
context: "CI / gate"

# The pull_request start. workflow_run, schedule and workflow_dispatch run only from the default
# branch, so without this job the pull request that adds or changes the gate never gets the status
# and a ruleset requiring it blocks that very pull request. This job runs from the pull request's own
# branch and posts the same verdict, waiting (bounded) for the checks named in the profile to report.
# Same-repository branches only: a fork's or Dependabot's pull_request token cannot write statuses,
# and those are covered by the workflow_run job. No trust decision uses github.actor.
# Because a pull request can edit this file, the Gate tamper guard (ci-gate-tamper-guard.yml, run from
# the default branch) fails a pull request that touches gate files unless the owner has approved it.
# The pull_request start. workflow_run and schedule run only from the default branch, so without this
# job the pull request that adds or changes the gate never gets the status and a ruleset requiring it
# blocks that very pull request. This job runs from the pull request's own branch and posts the same
# verdict, waiting (bounded) for the checks named in the profile to report.
# Same-repository branches only, and not Dependabot's: a fork's or Dependabot's pull_request token is
# read-only and cannot write statuses; the workflow_run job covers both. The Dependabot test only
# EXCLUDES a run (it can never grant anything), so it is not a trust decision; none uses github.actor.
# Because a pull request can edit this file, this path is PR-controlled: it runs the tamper guard for
# early feedback only. The trusted guard is the default-branch `gate` job above.
gate-pr:
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.user.login != 'dependabot[bot]'
permissions:
statuses: write
actions: read
contents: read
pull-requests: read
uses: ./.github/workflows/ci-gate.yml
with:
context: "CI / gate"
20 changes: 0 additions & 20 deletions .github/workflows/ci-gate-tamper-guard-caller.yml

This file was deleted.

8 changes: 8 additions & 0 deletions .github/workflows/ci-gate-tamper-guard.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# SPDX-License-Identifier: MPL-2.0
# ⚠ DEPRECATED (2026-11-23). This guard has NEVER started: every run ends in startup_failure because
# the account Actions policy refuses its trigger with
# "Event 'pull_request_target' is not allowed to trigger Actions workflows."
# (rsr-template-repo 30/30, resource-algebra 50/50, this suite 30/30). The guard now runs INSIDE the
# gate's own verdict (ci-gate.yml -> scripts/ci-gate-publish.sh -> scripts/ci-gate-tamper-guard.sh;
# docs/CI-GATE.adoc, "Tamper guard"). Do not install it anywhere new. It is kept only while consumers
# still reference it; a later pass removes their pull_request_target caller, then this file.
#
#
# ci-gate-tamper-guard.yml (reusable) - fail a pull request that touches the gate's own files
# unless the owner approved the change with the label `gate-change-approved`.
Expand Down
27 changes: 24 additions & 3 deletions .github/workflows/ci-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
# publisher on each distinct head SHA (scripts/ci-gate-sweep.sh), with no early pending. That bounds
# nothing by itself: a sweep is one more last-writer-wins evaluator (docs/CI-GATE.adoc, "Residual limit").
#
# TAMPER GUARD: before the verdict, the publisher runs scripts/ci-gate-tamper-guard.sh (fetched with the
# other scripts) for every open pull request into the repository, FORKS INCLUDED, whose head is the
# evaluated SHA (workflow_run: the event's pull_requests, else a fork run's head branch, else
# commits/<sha>/pulls; sweep: the pull requests it lists; pull_request: its own number).
# A pull request that touches a gate file or a workflow named in the profile without the owner's
# `gate-change-approved` label makes the verdict `failure` ("gate files changed without owner
# approval: <paths>"); a guard error is "no verdict". Only the default-branch paths (workflow_run, sweep)
# are trusted; the pull_request path runs the pull request's own caller (docs/CI-GATE.adoc, "Tamper guard").
#
# FAIL CLOSED: a missing or invalid profile, an empty `job.workflow_sha`, any API error, or
# any event other than workflow_run, schedule or workflow_dispatch is a failure, never a pass or a pending.
#
Expand All @@ -45,7 +54,8 @@
# "**" (docs/CI-GATE.adoc, "API budget").
#
# The caller must grant: statuses: write, actions: read, contents: read, pull-requests: read
# (the last one is read only by the sweep, to list open pull requests).
# (the last one is read by the sweep, to list open pull requests, and by the tamper guard). Grant them at
# JOB level, with `permissions: {}` at workflow level (templates/ci-gate-caller.yml).
# No `secrets:` — the reusable consumes none.

name: CI gate (reusable)
Expand Down Expand Up @@ -300,6 +310,7 @@ jobs:
fetch scripts/validate-ci-gate-profile.sh
fetch scripts/ci-gate-publish.sh
fetch scripts/ci-gate-sweep.sh
fetch scripts/ci-gate-tamper-guard.sh
fetch profiles/ci-gate/validate.jq
fetch profiles/ci-gate/select-runs.jq
mkdir -p "$suite/profiles/ci-gate/${REPO%%/*}"
Expand All @@ -314,17 +325,27 @@ jobs:
env:
WF_REPO: ${{ job.workflow_repository }}
WF_SHA: ${{ job.workflow_sha }}
PR_NUMBER: ${{ github.event.pull_request.number }}
WORKFLOW_RUN_PRS: ${{ toJSON(github.event.workflow_run.pull_requests) }}
WORKFLOW_RUN_HEAD_REPO: ${{ github.event.workflow_run.head_repository.full_name }}
WORKFLOW_RUN_HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
# All of the reading, the settle guard and the publishing is scripts/ci-gate-publish.sh
# (fetched from the suite above), so a stub `gh` can test it offline. On schedule and
# workflow_dispatch scripts/ci-gate-sweep.sh runs that same publisher once per open pull
# request head and the default branch head. The workflow only hands them values through env.
run: |
set -euo pipefail
if [[ "$EVENT_NAME" == workflow_run ]]; then
SUITE="$suite" WORK="$RUNNER_TEMP/ci-gate-work" WAIT_SECONDS=0 bash "$suite/scripts/ci-gate-publish.sh"
# tamper guard: the pull requests this run names; for a fork's run (which names none) the head
# repository and branch; else the publisher looks them up by commit.
GUARD_EVENT_PRS="$WORKFLOW_RUN_PRS" GUARD_HEAD_REPO="$WORKFLOW_RUN_HEAD_REPO" GUARD_HEAD_BRANCH="$WORKFLOW_RUN_HEAD_BRANCH" \
SUITE="$suite" WORK="$RUNNER_TEMP/ci-gate-work" WAIT_SECONDS=0 \
bash "$suite/scripts/ci-gate-publish.sh"
elif [[ "$EVENT_NAME" == pull_request ]]; then
# pull_request path: one evaluation, so wait (bounded) for the required checks to report.
SUITE="$suite" WORK="$RUNNER_TEMP/ci-gate-work" WAIT_SECONDS=$((WAIT_MINUTES * 60)) \
# tamper guard for this pull request too: early feedback only, since this path runs the
# pull request's own caller (docs/CI-GATE.adoc, "Tamper guard").
GUARD_PRS="$PR_NUMBER" SUITE="$suite" WORK="$RUNNER_TEMP/ci-gate-work" WAIT_SECONDS=$((WAIT_MINUTES * 60)) \
bash "$suite/scripts/ci-gate-publish.sh"
else
SUITE="$suite" WORK="$RUNNER_TEMP/ci-gate-sweep" bash "$suite/scripts/ci-gate-sweep.sh"
Expand Down
7 changes: 1 addition & 6 deletions config/workflow-lock-scope.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@
{
"path": ".github/workflows/ci-gate-tamper-guard.yml",
"mode": "immutable",
"reason": "Reusable tamper guard: uses no actions, never checks out or runs pull request code; reads changed files, label events and commit dates through the API."
},
{
"path": ".github/workflows/ci-gate-tamper-guard-caller.yml",
"mode": "immutable",
"reason": "The suite guards its own gate files: pull_request_target caller of the local reusable guard; runs from the default branch, no checkout, minimal permissions."
"reason": "DEPRECATED reusable tamper guard (pull_request_target is refused by the account Actions policy; the guard now runs inside ci-gate.yml). Kept while consumers still reference it: uses no actions, never checks out or runs pull request code."
},
{
"path": ".github/workflows/ci-gate-caller.yml",
Expand Down
Loading
Loading