diff --git a/AGENTS.md b/AGENTS.md index 6166a11ba..53a8930df 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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///git/refs" -f ref=refs/heads/develop -f sha="$(gh pr view --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 `) **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. diff --git a/AUDIT.md b/AUDIT.md index cebd4be81..be68626fe 100644 --- a/AUDIT.md +++ b/AUDIT.md @@ -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//" --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): @@ -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 diff --git a/cspell.json b/cspell.json index 78d771d01..039f5d898 100644 --- a/cspell.json +++ b/cspell.json @@ -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" + ] } diff --git a/repo-config/README.md b/repo-config/README.md index 252dcaf64..ff07b8811 100644 --- a/repo-config/README.md +++ b/repo-config/README.md @@ -28,8 +28,14 @@ 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) @@ -37,6 +43,7 @@ Publish credentials required per mechanism are enumerated in [spec/secrets.json] +[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 diff --git a/repo-config/configure.sh b/repo-config/configure.sh index 790bce58d..ab460fd65 100755 --- a/repo-config/configure.sh +++ b/repo-config/configure.sh @@ -1,8 +1,11 @@ #!/usr/bin/env bash -# Apply the committed branch rulesets in this directory to the repository via the GitHub API. -# Each .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 .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. # # Usage: repo-config/configure.sh [owner/repo] (defaults to the current repo via gh) set -euo pipefail @@ -10,9 +13,30 @@ 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 @@ -38,4 +62,4 @@ for file in "$script_dir"/*.json; do fi done -echo "Rulesets applied to $repo" +echo "Configuration applied to $repo" diff --git a/repo-config/settings.json b/repo-config/settings.json new file mode 100644 index 000000000..b7f1608ba --- /dev/null +++ b/repo-config/settings.json @@ -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 +}