Skip to content
Merged
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
5 changes: 2 additions & 3 deletions .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ repository:
has_wiki: true

# main's protection lives in unbound-force/.github's safe-settings
# (repos/replicator.yml: "CI OK" and "Standardized CI / Run linters",
# not strict; the org code-repos ruleset requires the code owner's
# approval). protection: null has the Settings app remove the classic
# (repos/replicator.yml: "CI OK", not strict; the org code-repos

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LOW | operational-documentation | divisor-sre] The required-check transition is not atomic with this merge — the live safe-settings required set still includes Standardized CI / Run linters while this comment asserts repos/replicator.yml: "CI OK" as if live. After merge, a chore PR skips call-reusable-ci, so the still-required check never reports and the PR blocks until the safe-settings change lands. Spelling out the merge → safe-settings sequencing in this comment or the PR body makes the blocking window discoverable.

# ruleset requires the code owner's approval). protection: null has the Settings app remove the classic
# branch protection, whose strict: true left every open PR behind after
# each auto-merge.
branches:
Expand Down
224 changes: 98 additions & 126 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# CI
# --
# Continuous integration pipeline. Runs on push to main and
# pull requests. A changes job detects whether a pull request
# touches files outside .uf/dewey/learnings/ and gates the
# expensive jobs; pushes to main always run everything. The
# CI OK aggregate fails when any needed job fails or is
# cancelled. Validates code quality (vet, govulncheck), runs
# tests with race detection, enforces per-package coverage
# ratchets, and verifies the binary builds.
# Continuous integration pipeline. Runs on push to main and pull
# requests. A scope job (jflowers/ship's pr-scope.yml) decides whether
# the expensive jobs run: chore pull requests -- Dewey learnings and
# gh-hud toolkit rollouts -- skip them and get a gitleaks scan instead;
# pushes to main always run everything. Validates code quality (vet,
# govulncheck), runs tests with race detection, enforces per-package
# coverage ratchets, verifies the binary builds, and runs the org's
# Standardized CI (MegaLinter, PR title validation, pinact). The CI OK
# aggregate is the only required check.

name: CI

Expand All @@ -25,109 +26,17 @@ concurrency:
cancel-in-progress: true

jobs:
changes:
name: Detect code changes
runs-on: ubuntu-latest
outputs:
code: ${{ steps.detect.outputs.code }}
steps:
# Pushes never diff (see the push short-circuit below), so they
# skip the checkout.
- if: github.event_name == 'pull_request'
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# On pull_request the checkout is refs/pull/N/merge; depth 2
# fetches the merge commit and both of its parents.
fetch-depth: 2

- name: Detect code changes
id: detect
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
# Pushes to main always run full CI (CLS-FR-001).
if [ "$GITHUB_EVENT_NAME" = "push" ]; then
echo "Push event — setting code=true unconditionally."
echo "code=true" >> "$GITHUB_OUTPUT"
exit 0
fi

# HEAD is GitHub's merge of the PR head (HEAD^2) into the current
# main (HEAD^1), so HEAD^1..HEAD is exactly what merging the PR
# would change on main today. Unlike a diff against the event's
# base SHA, it does not count main's own changes when
# base.sha is older than the main merged into the branch.
# Fail closed: anything unexpected fails the job rather than guessing.
if ! PR_PARENT="$(git rev-parse --verify --quiet 'HEAD^2^{commit}')"; then
echo "::error::HEAD is not the pull request merge commit — failing closed (CLS-FR-001)"
exit 1
fi
if [ "$PR_PARENT" != "$HEAD_SHA" ]; then
echo "::error::merge commit's second parent $PR_PARENT is not the PR head $HEAD_SHA — failing closed (CLS-FR-001)"
exit 1
fi
if ! CHANGED_FILES="$(git diff --raw --no-renames 'HEAD^1' HEAD)"; then
echo "::error::git diff of the pull request merge commit failed — failing closed (CLS-FR-001)"
exit 1
fi

# Learnings-only means every change is a regular .md file under
# .uf/dewey/learnings/ (added, edited or deleted), the same rule
# as the sibling repos. --no-renames lists both sides of a
# rename, so a file moved into learnings still counts its source
# path. --raw adds file modes: symlinks (120000) and submodules
# (160000) can point anywhere, so they count as code. An empty
# diff, a path git had to quote, or a line that does not parse
# also counts as code.
code="false"
reason=""
if [ -z "$CHANGED_FILES" ]; then
code="true"
reason="no changed files"
fi
while IFS= read -r line; do
[ "$code" = "true" ] && break
[ -z "$line" ] && continue
# ":<old mode> <new mode> <old sha> <new sha> <status><TAB><path>"
meta="${line%%$'\t'*}"
file="${line#*$'\t'}"
if [ "$meta" = "$line" ] || [ "${meta#:}" = "$meta" ]; then
code="true"
reason="unparsable diff line: $line"
break
fi
read -r old_mode new_mode _ <<< "${meta#:}"
for mode in "$old_mode" "$new_mode"; do
case "$mode" in
000000|100644|100755) ;;
*)
code="true"
reason="mode $mode (symlink or submodule): $file"
;;
esac
done
[ "$code" = "true" ] && break
case "$file" in
.uf/dewey/learnings/?*.md) ;;
*)
code="true"
reason="not a .md file under .uf/dewey/learnings/: $file"
;;
esac
done <<< "$CHANGED_FILES"

if [ "$code" = "true" ]; then
echo "Full CI required — $reason"
else
echo "All changed files are learnings under .uf/dewey/learnings/ — expensive jobs may skip."
fi
echo "code=$code" >> "$GITHUB_OUTPUT"
# code == 'false' only for pull requests whose files are all Dewey
# learnings, or a gh-hud toolkit rollout; 'true' for everything else.
scope:
uses: jflowers/ship/.github/workflows/pr-scope.yml@3b0ce8bf47183be402df9eaec16644c213eee5f7 # main, after v0.11.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MEDIUM | release-pipeline-integrity | divisor-sre] Deleting the in-repo changes job moves the CLS-FR-001 push guarantee (pushes to main always run everything) entirely onto ship's pr-scope.yml push path, and the PR also removes the executed push event regression case that asserted code=true. TestCIGatingWorkflows_StructureEnforcesChoreSkip pins the SHA but not push behavior. release.yml's preflight gates on Build and Test and Standardized CI / Run linters, which exist on main HEAD only if call-reusable-ci runs on push; CI OK passes a push only when scope returns code=true. A ship push-path regression reddens main CI and blocks releases with no in-repo signal.

permissions:
contents: read

build-and-test:
name: Build and Test
needs: [changes]
if: needs.changes.outputs.code == 'true'
needs: [scope]
if: needs.scope.outputs.code == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand Down Expand Up @@ -224,9 +133,55 @@ jobs:
- name: Build
run: go build -o bin/replicator ./cmd/replicator

# The org's reusable CI: MegaLinter ("Run linters", which includes
# betterleaks and KICS), PR title validation and pinact. It lives in
# this workflow so CI OK can need it; its check names are unchanged.
call-reusable-ci:
name: Standardized CI
needs: [scope]
if: needs.scope.outputs.code == 'true'
uses: complytime/org-infra/.github/workflows/reusable_ci.yml@8f347ba1aa2c7e9eb3b70e69c1709ddb456cd64a # v0.9.0
permissions:
contents: read
issues: read
pull-requests: read

# Chore PRs skip Standardized CI, and with it the secret scan: scan
# their commits here instead, since learnings can carry leaked secrets.
gitleaks:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MEDIUM | release-pipeline-integrity | divisor-sre] The new Gitleaks job never runs on this PR — if: needs.scope.outputs.code == 'false' is false for a code PR — so the pinned artifact URL, the hardcoded GITLEAKS_SHA256, and the HEAD^1..HEAD^2 scan range unique to this repo's merge-commit checkout are unvalidated at merge time. The first chore/learnings PR is the first execution, and CI OK requires gitleaks == success for chores, so a wrong checksum, asset name, or range blocks every chore PR until a fix-up lands. Exercising the job out-of-band (a scratch chore branch or a temporary unconditional run) before the first real chore PR closes the gap.

name: Gitleaks
needs: [scope]
if: needs.scope.outputs.code == 'false'
runs-on: ubuntu-latest
timeout-minutes: 5
env:
GITLEAKS_VERSION: 8.30.1
GITLEAKS_SHA256: 551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false

- name: Install gitleaks
run: |
set -euo pipefail
tarball="gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz"
curl -fsSL -o "$RUNNER_TEMP/$tarball" \
"https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/${tarball}"
echo "${GITLEAKS_SHA256} $RUNNER_TEMP/$tarball" | sha256sum -c -
tar -xzf "$RUNNER_TEMP/$tarball" -C "$RUNNER_TEMP" gitleaks

# HEAD is the PR merge commit: HEAD^1 is main, HEAD^2 the PR head.
- name: Scan the pull request's commits
run: |
"$RUNNER_TEMP/gitleaks" git . \
--log-opts='HEAD^1..HEAD^2' \
--redact --verbose --no-banner

ci-ok:
name: CI OK
needs: [changes, build-and-test]
needs: [scope, build-and-test, call-reusable-ci, gitleaks]
# Always run, so a failed or cancelled job fails the check -- except
# for a push run that was itself cancelled (superseded by a newer
# push to main). That run is not a verdict, so the check is skipped
Expand All @@ -237,25 +192,42 @@ jobs:
runs-on: ubuntu-latest
steps:
# The verdict is plain shell over the needed jobs' results, so
# ci_gating_test.go can run it against every combination. Anything
# but success or skipped -- failure, cancelled, or a result GitHub
# adds later -- fails, and so does an empty result list.
# ci_gating_test.go can run it against every combination. It passes
# only when scope succeeded and the jobs it chose concluded as
# chosen: Build and Test and Standardized CI for code (gitleaks
# skipped), gitleaks for chores (the others skipped).
- name: Check needed job results
env:
RESULTS: ${{ join(needs.*.result, ' ') }}
SCOPE: ${{ needs.scope.result }}
CODE: ${{ needs.scope.outputs.code }}
BUILD: ${{ needs.build-and-test.result }}
LINT: ${{ needs.call-reusable-ci.result }}
GITLEAKS: ${{ needs.gitleaks.result }}
run: |
echo "Needed job results: ${RESULTS:-<none>}"
if [ -z "$RESULTS" ]; then
echo "::error::No needed job results — CI did not pass."
echo "scope=$SCOPE code=$CODE build-and-test=$BUILD call-reusable-ci=$LINT gitleaks=$GITLEAKS"
if [ "$SCOPE" != "success" ]; then
echo "::error::scope ended '$SCOPE' — CI did not pass."
exit 1
fi
for result in $RESULTS; do
case "$result" in
success|skipped) ;;
*)
echo "::error::A needed job ended '$result' — CI did not pass."
exit 1
;;
esac
done
echo "All needed jobs succeeded or were skipped."
case "$CODE" in
true) want_code=success want_chore=skipped ;;
false) want_code=skipped want_chore=success ;;
*)
echo "::error::scope code output '$CODE' — CI did not pass."
exit 1
;;
esac
fail=0
expect() {
if [ "$2" != "$3" ]; then
echo "::error::$1 ended '${2:-<none>}', want '$3' — CI did not pass."
fail=1
fi
}
expect build-and-test "$BUILD" "$want_code"
expect call-reusable-ci "$LINT" "$want_code"
expect gitleaks "$GITLEAKS" "$want_chore"
if [ "$fail" -ne 0 ]; then
exit 1
fi
echo "All needed jobs ended as scope chose."
38 changes: 0 additions & 38 deletions .github/workflows/ci_checks.yml

This file was deleted.

17 changes: 17 additions & 0 deletions .pinact.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# pinact configuration, read by Standardized CI's "Verify action versions"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LOW | dependency-health | divisor-sre] The scope job pins an untagged commit on ship's main (# main, after v0.11.0), so the pin has no released tag to audit against and no version-comment provenance — an auditability gap rather than a reproducibility break (the SHA is immutable). Bumping to a ship release tag once one is cut, which lets this ignore rule stop matching, closes the gap.

# job (complytime/org-infra reusable_ci.yml, which runs pinact).
#
# ci.yml's scope job pins jflowers/ship's pr-scope.yml to a pre-release
# commit on ship's main; the workflow has no released tag yet, so the
# pin's comment cannot name a tag for pinact's --verify to cross-check.
# pinact's documented resolution for legitimate untagged SHAs
# (docs/codes/005, "pre-release pins") is an ignore rule scoped to
# exactly this action and commit. When the pin is later bumped to a
# released tag with a "# vX.Y.Z" comment, this rule stops matching and
# normal verification resumes.
version: 3
rules:
- ignore: true
conditions:
- expr: |
ActionName == "jflowers/ship/.github/workflows/pr-scope.yml" && ActionVersion == "3b0ce8bf47183be402df9eaec16644c213eee5f7"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LOW | coverage-gap | divisor-gaze-testing + divisor-testing] No test in internal/workflowtest/ reads .pinact.yaml, so the two-file invariant this rule creates — ci.yml's scope pin must match this rule's ActionVersion exactly — has no local pinning. A ship-pin bump that forgets the rule, widens it, or leaves a stale dead rule behind after moving to a released tag passes make check and fails only in Standardized CI's "Verify action versions" after push. Extending TestCIGatingWorkflows_StructureEnforcesChoreSkip to assert the rule's ActionVersion equals the SHA captured by shipScopeRE moves that failure to make check time.

28 changes: 15 additions & 13 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,25 @@ non-negotiable.
the CI-equivalent checks locally. Read
`.github/workflows/` for the exact commands -- do not
rely on memory. Any failure blocks the task. `main`
requires `CI OK` (an aggregate in `ci.yml` that fails
when any needed job failed or was cancelled) and
`Standardized CI / Run linters`, through a ruleset in
unbound-force/.github's safe-settings
requires only `CI OK`, an aggregate in `ci.yml`, through a
ruleset in unbound-force/.github's safe-settings
(`safe-settings/repos/replicator.yml`), not strict;
`.github/settings.yml` sets no branch protection. Pull requests
changing only `.md` files under `.uf/dewey/learnings/` skip
the `Build and Test` job (a `changes` job in `ci.yml`
detects this, counts symlinks, submodules and empty
diffs as code, and fails closed on diff errors); the
Standardized CI check is never skipped, so secret
scanning and PR title validation run on every PR; pushes
to `main` always run everything. The `Build and Test` job includes
`.github/settings.yml` sets no branch protection. A `scope`
job calls `jflowers/ship`'s `pr-scope.yml`, whose `code`
output is `'false'` only for chore pull requests: every
changed file a `.md` under `.uf/dewey/learnings/`, or a
gh-hud toolkit rollout (author `jflowers`, branch
`chore/toolkit-*`, every file under `.opencode/`). Those
skip `Build and Test` and `Standardized CI` and get a
`Gitleaks` scan of their commits instead; pushes to `main`
always run everything. `CI OK` fails unless `scope`
succeeded and each job ended as it chose (success when
run, skipped when not). The `Build and Test` job includes
`govulncheck` for vulnerability scanning of Go
dependencies. The `Standardized CI / Run linters` check
runs MegaLinter (via `complytime/org-infra` reusable
workflow) with linters configured in `.mega-linter.yml`
workflow, called from `ci.yml`) with linters configured in
`.mega-linter.yml`
and PR title validation. Note: MegaLinter runs in CI only;
there is no local equivalent. Use `mega-linter-runner` if
local linting is needed (requires Docker).
Expand Down
Loading
Loading