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
3 changes: 3 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ The specific rules in this file implement a few governing principles. Read these
- `develop` -> `main` is **merge-commit only** (no squash, no rebase). Merge commits preserve develop's commit list as a real second-parent reference on main, which lets the release model attribute releases to the develop commits that produced them (relevant both for the weekly publish and the opt-in `PUBLISH_ON_MERGE` mode - see "Release Model" below). Branch protection enforces this: the develop ruleset allows only `squash`, the main ruleset allows only `merge`.
- All commits on both branches must be cryptographically signed (SSH or GPG). Squash and merge commits created via the GitHub UI are signed by GitHub's web-flow key.
- **`develop` is forward-only - no `main -> develop` back-merges.** The develop ruleset's squash-only setting physically blocks merge commits on develop. Historical back-merge commits visible in `git log` (`b9b0447`, `410ba56`, `ffb9e64`, `5ce95cf`, etc.) predate this rule and must not be repeated.
- **Executing a `develop -> main` promotion safely - two traps, both learned the hard way:**
- **Never delete `develop`.** A promotion PR's head *is* `develop`, so `gh pr merge --delete-branch` (and the repo's "Automatically delete head branches" toggle, which is why that toggle is [kept off](./repo-config/settings.json)) deletes `develop` itself. Merge a promotion with a plain `gh pr merge --merge`, no `--delete-branch`. If `develop` is ever lost this way, restore it to the merged PR's head SHA - the SHA is still reachable as the merge commit's second parent: `gh api -X POST "repos/<owner>/<repo>/git/refs" -f ref=refs/heads/develop -f sha="$(gh pr view <n> --json headRefOid --jq .headRefOid)"`.
- **Spurious EOL-only conflicts resolve by taking `develop`.** When develop declared workflow YAML as LF while main is still CRLF, `develop -> main` conflicts *whole-file* on those paths. develop's `required_linear_history` + PR rulesets forbid resolving on `develop` (no merge commit, no force-push), so resolve on a throwaway branch off `main`: `git checkout -b promote/develop-to-main origin/main && git merge origin/develop`, take develop's side for the EOL-conflicted files (`git checkout --theirs <file>`) **after confirming each is content-identical modulo EOL or that develop is a strict superset** (`diff <(git show :2:f|tr -d '\r') <(git show :3:f|tr -d '\r')`), then open that branch -> `main`. Verify no genuine main-only content is dropped (build/test where the repo supports it).
- **Both rulesets intentionally omit "Require branches to be up to date before merging".** The flag is off on `main` and on `develop`, for related but distinct reasons.
- *Main:* the check is graph-based - it asks whether main's tip commit is reachable from develop, not whether the two branches have the same content. After any develop -> main release, main's tip is a brand-new merge commit that develop's history doesn't contain. Forward-only develop never adds it (no back-merge of main into develop), so the check would fail on every subsequent release. Other technical workarounds - rebasing develop onto main, or rewriting develop's history - exist but contradict the squash-only develop ruleset and the linearity invariant.
- *Develop:* the check stalls bot auto-merge when two bot PRs against develop land within the same window. As soon as the first merges, the second flips to `mergeStateStatus: BEHIND` and GitHub's auto-merge will not fire while strict is on. The merge-bot only *enables* auto-merge on `opened`/`reopened` (see below) and never auto-updates bot branches, and Dependabot's rebase isn't real-time, so the second PR sits OPEN with all checks green indefinitely. Squash mechanics still rebase the diff onto develop's tip on merge, `required_linear_history` still enforces linearity, textual conflicts still block `mergeable: CONFLICTING`, and the required `Check pull request workflow status job` still gates merges - the only thing lost is pre-merge detection of *semantic-but-not-textual* conflicts, which the post-merge develop CI run catches anyway.
Expand Down
11 changes: 10 additions & 1 deletion AUDIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ A check with `intentRef`/`workflowRef` points at the prose section that owns the

Run [`WORKFLOW.md`][workflow]'s methodology against the repo's **own** Actions: the 5A static audit (structural facts per applicable D-guarantee, each with a `file:line` citation) and the 5B trace scenarios (predicted run/skip + version + release + artifact-end-state vs expected). The contract in WORKFLOW.md section 4 is satisfied by **outcome**, not by matching the catalog snippets in [`catalog/snippets/workflows/`][workflows] byte for byte - those are the reference implementation, not required bytes.

## 6. Validate Rulesets and Secrets
## 6. Validate Settings, Rulesets, and Secrets

- **General settings** - diff the live repository settings against [`repo-config/settings.json`][repo-config-settings], and confirm the two state-dependent settings: `has_discussions` follows visibility (public on / private off) and `default_branch` is `main`.

```sh
live=$(gh api "repos/<owner>/<repo>" --jq '{has_wiki,has_projects,allow_merge_commit,allow_squash_merge,allow_rebase_merge,allow_auto_merge,allow_update_branch,delete_branch_on_merge}')
diff <(jq -S . repo-config/settings.json) <(jq -S . <<<"$live") \
&& echo "settings: in sync" || echo "settings: DRIFT"
```

- **Rulesets** - diff each live ruleset against the committed expected payload with a normalized comparison (sort the order-insensitive `rules[]` and `bypass_actors[]` before diffing so a reordered but equivalent ruleset does not read as drift):

Expand Down Expand Up @@ -104,6 +112,7 @@ The convergence model: the hub audits and the agent **applies** the fixes via ta
[project-types]: ./spec/project-types.json
[readme-structure]: ./spec/readme-structure.md
[repo-config]: ./repo-config/
[repo-config-settings]: ./repo-config/settings.json
[reports]: ./reports/
[repos]: ./registry/repos.json
[secrets]: ./spec/secrets.json
Expand Down
248 changes: 125 additions & 123 deletions cspell.json
Original file line number Diff line number Diff line change
@@ -1,125 +1,127 @@
{
"version": "0.2",
"language": "en-US",
"ignorePaths": [
".git/**",
"reports/*/**",
"**/*.min.*"
],
"ignoreRegExpList": [
"/```mermaid[\\s\\S]*?```/g"
],
"words": [
"accessibilities",
"Allman",
"apikey",
"arahata",
"astral",
"autoremove",
"buildcache",
"buildmetadata",
"buildtransitive",
"Buildx",
"charliermarsh",
"chowned",
"chowns",
"codegen",
"commitish",
"conftest",
"contentfiles",
"cref",
"crefs",
"csdevkit",
"datebadge",
"davidanson",
"debuglevel",
"devcontainer",
"distros",
"dockerbuild",
"Dockerfiles",
"dockerhub",
"Docstrings",
"dogfoods",
"dorny",
"dotnettools",
"downstreams",
"dryrun",
"Emby",
"envsubst",
"extensionless",
"fanaticpythoner",
"finalizers",
"Genericize",
"gpgsign",
"gruntfuggly",
"HACS",
"hatchling",
"heredocs",
"homeassistant",
"isort",
"Jellyfin",
"Keychain",
"kicad",
"lastbuild",
"libsecret",
"LINQ",
"logfile",
"mktemp",
"mypy",
"nameof",
"nbgv",
"nektos",
"Nerdbank",
"noninteractive",
"noqa",
"nuget",
"nugetlibrary",
"onCreateCommand",
"Optix",
"othercommand",
"paramref",
"Pieter",
"pipefail",
"postCreateCommand",
"prerelease",
"ProjectTemplate",
"purpleair",
"pydantic",
"pypa",
"pypi",
"pypilibrary",
"pyproject",
"pyright",
"pyrightconfig",
"pytest",
"quoteoftheday",
"resharper",
"rhysd",
"Rubba",
"ruff",
"sdist",
"semver",
"Serilog",
"settingsfile",
"shellcheck",
"signingkey",
"slnx",
"snupkg",
"softprops",
"somecommand",
"sshconfig",
"subsetting",
"timonwong",
"Triaging",
"tzdata",
"unbuilt",
"unvalidated",
"USERPROFILE",
"venv",
"Viljoen",
"winget",
"Xsession",
"xunit",
"yzhang"
]
"version": "0.2",
"language": "en-US",
"ignorePaths": [
".git/**",
"reports/*/**",
"**/*.min.*"
],
"ignoreRegExpList": [
"/```mermaid[\\s\\S]*?```/g"
],
"words": [
"accessibilities",
"Allman",
"apikey",
"arahata",
"astral",
"autoremove",
"buildcache",
"buildmetadata",
"buildtransitive",
"Buildx",
"charliermarsh",
"chowned",
"chowns",
"codegen",
"commitish",
"conftest",
"contentfiles",
"cref",
"crefs",
"csdevkit",
"datebadge",
"davidanson",
"debuglevel",
"devcontainer",
"distros",
"dockerbuild",
"Dockerfiles",
"dockerhub",
"Docstrings",
"dogfoods",
"dorny",
"dotnettools",
"downstreams",
"dryrun",
"Emby",
"envsubst",
"extensionless",
"fanaticpythoner",
"finalizers",
"Genericize",
"gpgsign",
"gruntfuggly",
"HACS",
"hatchling",
"heredocs",
"homeassistant",
"idempotent",
"idempotently",
"isort",
"Jellyfin",
"Keychain",
"kicad",
"lastbuild",
"libsecret",
"LINQ",
"logfile",
"mktemp",
"mypy",
"nameof",
"nbgv",
"nektos",
"Nerdbank",
"noninteractive",
"noqa",
"nuget",
"nugetlibrary",
"onCreateCommand",
"Optix",
"othercommand",
"paramref",
"Pieter",
"pipefail",
"postCreateCommand",
"prerelease",
"ProjectTemplate",
"purpleair",
"pydantic",
"pypa",
"pypi",
"pypilibrary",
"pyproject",
"pyright",
"pyrightconfig",
"pytest",
"quoteoftheday",
"resharper",
"rhysd",
"Rubba",
"ruff",
"sdist",
"semver",
"Serilog",
"settingsfile",
"shellcheck",
"signingkey",
"slnx",
"snupkg",
"softprops",
"somecommand",
"sshconfig",
"subsetting",
"timonwong",
"Triaging",
"tzdata",
"unbuilt",
"unvalidated",
"USERPROFILE",
"venv",
"Viljoen",
"winget",
"Xsession",
"xunit",
"yzhang"
]
}
11 changes: 9 additions & 2 deletions repo-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,22 @@ Publish credentials required per mechanism are enumerated in [spec/secrets.json]

## Repo Settings

- Default branch `main`. Enable both `Allow merge commits` and `Allow squash merging` at the repo level so each branch ruleset can pick its method; leave rebase disabled. Enable auto-merge.
- Actions / General: allow GitHub Actions to create and approve pull requests (for the bots).
The fleet-standard general settings live in [`settings.json`][settings-json] and are applied idempotently by `configure.sh` alongside the rulesets (`gh api PATCH /repos/{owner}/{repo}`). The two settings that depend on per-repo state - `has_discussions` (visibility) and `default_branch` (main-must-exist) - are computed by the script, not stored in the file.

- **Default branch `main`** (the script sets it only when a `main` branch exists, never pointing the default at a missing branch).
- **Merge methods**: `Allow merge commits` and `Allow squash merging` on, **rebase off** - each branch ruleset then picks its method (merge on `main`, squash on `develop`).
- **Auto-merge on** (the merge-bot needs it) and **`Always suggest updating pull request branches` on**.
- **`Automatically delete head branches` OFF - deliberately.** With it on, a `develop -> main` promotion (whose PR head is `develop`) would delete `develop`. There is no per-branch exemption, so the repo-wide toggle stays off to protect `develop`. **The CLI has the same trap: never `gh pr merge --delete-branch` a promotion PR whose head is `develop`** - the explicit flag deletes `develop` regardless of this setting (see [AGENTS.md "Branching Model"][agents-branching-model]).
- **Wikis and Projects off. Discussions on public repos only** (off on private). **Sponsorships off** - the button is driven by `.github/FUNDING.yml`, not a REST toggle, and the fleet ships none.
- **Actions / General**: allow GitHub Actions to create and approve pull requests (for the bots).

## Brownfield Migration (Maintainer Only)

`Require signed commits` rejects any pre-existing unsigned commit, so the first `develop -> main` release on a repo with unsigned history is blocked. Re-signing that history is a non-fast-forward that the `Block force pushes` rule rejects, **and the admin bypass does not cover `git push --force`**. Completing it requires temporarily disabling the ruleset and a maintainer force-push. This is a one-time, maintainer-performed migration that deliberately uses the force-push [AGENTS.md "Git and Commit Rules"][agents-git-and-commit-rules] forbids agents from running - **an agent must never execute it; surface it to the maintainer**. Greenfield repos where signing is live before the first commit never hit this.

<!-- Repo -->

[settings-json]: ./settings.json
[agents-branching-model]: ../AGENTS.md#branching-model
[agents-git-and-commit-rules]: ../AGENTS.md#git-and-commit-rules
[audit]: ../AUDIT.md
Expand Down
36 changes: 30 additions & 6 deletions repo-config/configure.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
#!/usr/bin/env bash
# Apply the committed branch rulesets in this directory to the repository via the GitHub API.
# Each <name>.json holds the writable ruleset subset {name, target, enforcement, bypass_actors,
# conditions, rules}. An existing ruleset (matched by name) is updated with a full-payload PUT
# (partial PUTs 422); a missing one is created with POST. Rerunning is idempotent.
# Apply the committed fleet configuration in this directory to the repository via the GitHub API:
# 1. General repository settings from settings.json (PATCH /repos/{owner}/{repo}), plus the two settings that depend on
# per-repo state - has_discussions (public repos only) and default_branch (main, only if it exists).
# 2. The branch rulesets develop.json and main.json. Each <name>.json holds the writable ruleset subset
Comment thread
ptr727 marked this conversation as resolved.
Resolved
# {name, target, enforcement, bypass_actors, conditions, rules}. An existing ruleset (matched by name) is
# updated with a full-payload PUT (partial PUTs 422); a missing one is created with POST.
# Rerunning is idempotent.
#
# Usage: repo-config/configure.sh [owner/repo] (defaults to the current repo via gh)
set -euo pipefail

repo="${1:-$(gh repo view --json nameWithOwner --jq '.nameWithOwner')}"
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# ----- General repository settings -----
settings_file="$script_dir/settings.json"
if [ -e "$settings_file" ]; then
# has_discussions: enabled on public repos only (fleet policy); never on private.
private="$(gh api "repos/$repo" --jq '.private')"
disc=false; [ "$private" = "false" ] && disc=true
# default_branch main, but only point it at main when main exists - never set the default to a missing
# branch (e.g. a repo still on a rework branch).
if gh api "repos/$repo/branches/main" --jq '.name' >/dev/null 2>&1; then
payload="$(jq --argjson d "$disc" '. + {has_discussions: $d, default_branch: "main"}' "$settings_file")"
else
payload="$(jq --argjson d "$disc" '. + {has_discussions: $d}' "$settings_file")"
echo "Warning: $repo has no 'main' branch; leaving default_branch unchanged." >&2
fi
echo "Applying general settings to $repo (has_discussions=$disc)"
printf '%s' "$payload" | gh api --method PATCH "repos/$repo" --input - >/dev/null
fi

# ----- Branch rulesets -----
for file in "$script_dir"/*.json; do
[ -e "$file" ] || continue
name="$(jq -r '.name' "$file")"
# settings.json is not a ruleset - it has no .name; skip it here (applied above).
name="$(jq -r '.name // empty' "$file")"
[ -n "$name" ] || continue
# Paginate so a name match on a later page is never missed (which would create a duplicate ruleset), and
# fail loudly if the API call itself fails (auth/404/network) rather than treating it as "not found".
if ! ids="$(gh api --paginate "repos/$repo/rulesets" --jq ".[] | select(.name==\"$name\") | .id")"; then
Expand All @@ -38,4 +62,4 @@ for file in "$script_dir"/*.json; do
fi
done

echo "Rulesets applied to $repo"
echo "Configuration applied to $repo"
10 changes: 10 additions & 0 deletions repo-config/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"has_wiki": false,
"has_projects": false,
"allow_merge_commit": true,
"allow_squash_merge": true,
"allow_rebase_merge": false,
"allow_auto_merge": true,
"allow_update_branch": true,
"delete_branch_on_merge": false
}