From 58e89c9ecee4c8f7cf00abd0b03f2176e4d406b3 Mon Sep 17 00:00:00 2001 From: Christopher Horrell Date: Fri, 13 Nov 2026 10:40:17 -0500 Subject: [PATCH 1/3] feat: manage horrell-consulting repositories with Terraform on HCP --- .github/dependabot.yml | 18 ++++ .github/workflows/new-repos.yml | 142 ++++++++++++++++++++++++++ .github/workflows/pre-commit.yml | 3 + .github/workflows/terraform.yml | 47 +++++++++ .gitignore | 21 ++++ .pre-commit-config.yaml | 18 ++++ .terraform.lock.hcl | 25 +++++ AGENTS.md | 143 ++++++++++++++++---------- README.md | 170 ++++++++++++++++++++++--------- imports.tf | 7 ++ main.tf | 35 +++++++ modules/repository/main.tf | 142 ++++++++++++++++++++++++++ modules/repository/outputs.tf | 4 + modules/repository/variables.tf | 62 +++++++++++ modules/repository/versions.tf | 10 ++ outputs.tf | 11 ++ providers.tf | 8 ++ repos.yaml | 30 ++++++ ruff.toml | 6 ++ scripts/new_repos.py | 157 ++++++++++++++++++++++++++++ variables.tf | 5 + versions.tf | 19 ++++ 22 files changed, 983 insertions(+), 100 deletions(-) create mode 100644 .github/workflows/new-repos.yml create mode 100644 .github/workflows/terraform.yml create mode 100644 .terraform.lock.hcl create mode 100644 imports.tf create mode 100644 main.tf create mode 100644 modules/repository/main.tf create mode 100644 modules/repository/outputs.tf create mode 100644 modules/repository/variables.tf create mode 100644 modules/repository/versions.tf create mode 100644 outputs.tf create mode 100644 providers.tf create mode 100644 repos.yaml create mode 100644 ruff.toml create mode 100755 scripts/new_repos.py create mode 100644 variables.tf create mode 100644 versions.tf diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 7cee6b6..1902e87 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -28,3 +28,21 @@ updates: multi-ecosystem-group: "tooling" cooldown: default-days: 7 + + - package-ecosystem: "terraform" + directories: + - "/" + - "/modules/*" + schedule: + interval: "monthly" + groups: + monthly-batch: + patterns: + - "*" + pull-request-branch-name: + separator: "/" + commit-message: + prefix: "chore" + include: "scope" + cooldown: + default-days: 7 diff --git a/.github/workflows/new-repos.yml b/.github/workflows/new-repos.yml new file mode 100644 index 0000000..e42a5e5 --- /dev/null +++ b/.github/workflows/new-repos.yml @@ -0,0 +1,142 @@ +name: new-repos + +# Opens a pull request that adds any repository not yet listed in repos.yaml. +# See scripts/new_repos.py. While that pull request is open, runs leave it +# alone so edits pushed to it aren't overwritten; repositories created in the +# meantime are picked up after it merges. + +on: + schedule: + - cron: "17 9 * * *" + workflow_dispatch: + +permissions: {} + +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: false + +env: + OWNER: horrell-consulting + BRANCH: bot/new-repos + +jobs: + propose: + # Skip until the GitHub App is set up (see README). + if: vars.NEW_REPOS_APP_CLIENT_ID != '' + runs-on: ubuntu-slim + permissions: + contents: read + steps: + # Read-only access to every repository the app is installed on, to list + # private repositories too. + - name: Read token + id: read-token + uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 + with: + client-id: ${{ vars.NEW_REPOS_APP_CLIENT_ID }} + private-key: ${{ secrets.NEW_REPOS_APP_PRIVATE_KEY }} + owner: ${{ env.OWNER }} # zizmor: ignore[github-app] metadata: read only, and it must see every repository + permission-metadata: read + + # Write access to this repository only, to push the branch and open the + # pull request. Pull requests opened with an app token trigger CI. + - name: Write token + id: write-token + uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 + with: + client-id: ${{ vars.NEW_REPOS_APP_CLIENT_ID }} + private-key: ${{ secrets.NEW_REPOS_APP_PRIVATE_KEY }} + owner: ${{ env.OWNER }} + repositories: github-settings + permission-contents: write + permission-pull-requests: write + + - name: Check for an open pull request + id: open-pr + env: + GH_TOKEN: ${{ steps.write-token.outputs.token }} + REPO: ${{ github.repository }} + run: | + pr=$(gh pr list --repo "$REPO" --head "$BRANCH" --state open --json url --jq '.[0].url // empty') + if [ -n "$pr" ]; then + echo "A pull request is already open, leaving it alone: $pr" + echo "open=true" >> "$GITHUB_OUTPUT" + fi + + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + if: steps.open-pr.outputs.open != 'true' + with: + persist-credentials: false + + - name: Find new repositories + id: find + if: steps.open-pr.outputs.open != 'true' + env: + GH_TOKEN: ${{ steps.read-token.outputs.token }} + run: | + python3 scripts/new_repos.py --owner "$OWNER" > "$RUNNER_TEMP/added.txt" + if [ -s "$RUNNER_TEMP/added.txt" ]; then + echo "found=true" >> "$GITHUB_OUTPUT" + cat "$RUNNER_TEMP/added.txt" + else + echo "No new repositories." + fi + + # Commit through the API so the commit is signed by the app. + - name: Open the pull request + if: steps.find.outputs.found == 'true' + env: + GH_TOKEN: ${{ steps.write-token.outputs.token }} + REPO: ${{ github.repository }} + BASE: main + run: | + set -euo pipefail + names=$(paste -sd ' ' "$RUNNER_TEMP/added.txt") + list=$(while read -r name; do printf -- '- %s\n' "\`$name\`"; done < "$RUNNER_TEMP/added.txt") + base_sha=$(git rev-parse HEAD) + + # Point the bot branch at the current default branch. + if gh api "repos/$REPO/git/ref/heads/$BRANCH" > /dev/null 2>&1; then + gh api -X PATCH "repos/$REPO/git/refs/heads/$BRANCH" \ + -f sha="$base_sha" -F force=true > /dev/null + else + gh api "repos/$REPO/git/refs" \ + -f ref="refs/heads/$BRANCH" -f sha="$base_sha" > /dev/null + fi + + file_sha=$(gh api "repos/$REPO/contents/repos.yaml?ref=$BRANCH" --jq .sha) + gh api -X PUT "repos/$REPO/contents/repos.yaml" \ + -f message="feat: manage $names" \ + -f content="$(base64 -w0 repos.yaml)" \ + -f sha="$file_sha" \ + -f branch="$BRANCH" > /dev/null + + body=$(cat <- + {"GITHUB_APP_ID": "0", "GITHUB_APP_INSTALLATION_ID": "0", + "GITHUB_APP_PEM_FILE": "placeholder"} + + # The required check is `validate`, and a called workflow's check is + # prefixed with the caller's job id, so this gate reports under that name. + # Add every new job to needs. + validate: + if: always() + needs: [terraform] + runs-on: ubuntu-slim + steps: + - name: Require every job to succeed + env: + RESULTS: ${{ join(needs.*.result, ' ') }} + run: | + echo "Job results: ${RESULTS}" + for result in ${RESULTS}; do + if [ "${result}" != "success" ]; then + echo "::error::A required job did not succeed (${result})" + exit 1 + fi + done diff --git a/.gitignore b/.gitignore index 9229f54..651fc3e 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,24 @@ Thumbs.db # Claude Code local settings .claude/settings.local.json + +# Terraform / OpenTofu +.terraform/ +*.tfstate +*.tfstate.* +*.tfplan +crash.log +crash.*.log +override.tf +override.tf.json +*_override.tf +*_override.tf.json +.terraformrc +terraform.rc + +# Lock files that terraform_validate creates in modules; only the root lock file is committed +modules/*/.terraform.lock.hcl + +# Python +__pycache__/ +.ruff_cache/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ca4c4ce..ccbe461 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,3 +23,21 @@ repos: rev: v1.31.1 hooks: - id: zizmor + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.17.2 + hooks: + - id: ruff-check + - id: ruff-format + + - repo: https://github.com/antonbabenko/pre-commit-terraform + rev: v1.109.3 + hooks: + - id: terraform_fmt + - id: terraform_validate + # Placeholders for app_auth {}; see .github/workflows/terraform.yml. + args: + - --env-vars=GITHUB_APP_ID=0 + - --env-vars=GITHUB_APP_INSTALLATION_ID=0 + - --env-vars=GITHUB_APP_PEM_FILE=placeholder + - id: terraform_tflint diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl new file mode 100644 index 0000000..1100d3d --- /dev/null +++ b/.terraform.lock.hcl @@ -0,0 +1,25 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/integrations/github" { + version = "6.13.0" + constraints = ">= 6.13.0, ~> 6.13" + hashes = [ + "h1:2kD+4leuV8tBBXv+EPeehmfW6cDhIzVki61OXsGCtRI=", + "h1:y0Sujto8gttV86innNp/LTMzq7CqsFpBs7XKH8AlMl4=", + "zh:0ab29fc21699f34345cf0bbbe44745fd1b143b7c73b410c1dc4abe05ffad0a84", + "zh:1aed10d06755d420bb3a893bf548ab2932297a9d094c04c5a8501e949ca186ed", + "zh:2a6a11c21eae408055f45b9533c07afd2e845f6d496fd1b645aec2e873012103", + "zh:5dd05dee677f6ebdbed00cbb1b9be444ab2d1062d345cbc9ec50a47cb41b8622", + "zh:6b757d034831243d67ddda869eac4368cef539848bd97511f4d68f1aa38a9c88", + "zh:947c9b5b238f0364c57a705beabd24d3eea3159a6f3a24c07e3fbb13657ffae0", + "zh:a676549a98164b61630658cbeb6c17820331ca04a049dc9b5095996a0c31ffbe", + "zh:a8a81b7fe41dd61eb6a6fa5e08a4dd9ee070e862868252a7fd4cfce30364efee", + "zh:c26a9bca4865665084e7f59b1402d7aff34ee63a418d7401a0658fa280cad4d4", + "zh:c638d8d0762e62ea188f86302954ef4c92803f2160f0a45fca0cd13974bd3725", + "zh:e739a0b7e81ca816944a18a38e679f4015edf8be7ac319815cdea865ba7727d7", + "zh:ec099487ea3de8999c84b3b791e242d728461e51fe344832b37bd8d521201c77", + "zh:f016ff9e2daab5b88185cec0795213049d105439ffd585d3309a714514ccae13", + "zh:fbd1fee2c9df3aa19cf8851ce134dea6e45ea01cb85695c1726670c285797e25", + ] +} diff --git a/AGENTS.md b/AGENTS.md index 9c7e769..b372397 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,62 +1,101 @@ # AGENTS.md -The GitHub template (`is_template: true`) that new `chorrell` repositories are -created from. It contains only shared configuration, no application code. See -[README.md](README.md) for what each file does and the checklist for new -repositories. +Terraform for the settings and rulesets of the repositories owned by the `horrell-consulting` organization. See [README.md](README.md) for the +baseline every repository gets and for day-to-day usage. ## Structure ```text -├── .pre-commit-config.yaml # gitleaks, markdownlint-cli2 (Docker), hygiene hooks, zizmor -├── .markdownlint.yaml # MD013 (line length) disabled -├── .gitignore # Language-agnostic: OS files, .env*, editor dirs, .claude/settings.local.json -├── .gitattributes # * text=auto -├── AGENTS.md / CLAUDE.md # Agent guidance; CLAUDE.md only imports AGENTS.md -├── LICENSE # MPL-2.0 -└── .github/ - ├── CODEOWNERS # * @chorrell - ├── dependabot.yml # github-actions + pre-commit in one monthly `tooling` PR, 7-day cooldown - ├── zizmor.yml # chorrell/* may be tag-pinned; everything else hash-pinned - └── workflows/ - ├── markdownlint.yml # PR stub calling chorrell/workflows markdownlint.yml@v1 - ├── pre-commit.yml # PR stub calling chorrell/workflows pre-commit.yml@v1 - ├── dependabot-automerge.yml # PR stub: auto-merges minor/patch `tooling` PRs - └── zizmor.yml # PR + main stub calling chorrell/workflows zizmor.yml@v1 +├── repos.yaml # Every managed repository and its per-repo options (plain data) +├── main.tf # yamldecode(repos.yaml) into local.repos; one module.repository per entry +├── imports.tf # for_each import block: adopts existing repositories on apply +├── providers.tf # integrations/github, GitHub App auth (app_auth) from GITHUB_APP_* on the workspace +├── variables.tf # owner (defaults to horrell-consulting) +├── versions.tf # Terraform >= 1.16, integrations/github ~> 6.13; cloud block, horrell/horrell-consulting-github-settings +├── outputs.tf # Managed repositories and their URLs; fails the plan on unknown options +├── modules/repository/ # The baseline: repository settings, security, Actions permissions, ruleset +├── scripts/new_repos.py # Adds entries to repos.yaml for repositories that aren't managed yet +└── .github/workflows/ + ├── terraform.yml # Shared terraform-validate (fmt, init, validate, tflint), gated by the `validate` job + ├── markdownlint.yml # chorrell/workflows reusable markdownlint + └── new-repos.yml # Daily: runs new_repos.py and opens a PR on bot/new-repos (GitHub App auth); + # a failed scheduled run opens an issue (chorrell/workflows scheduled-failure-issue) ``` ## Rules -- **Everything here is copied into every new repository.** Keep it - language-agnostic. Python, Docker, Terraform and similar hooks, Dependabot - ecosystems and ignores belong in the repositories that need them. -- **Keep this in sync with my other repositories.** When a shared default - changes (a hook, the Dependabot layout, the markdownlint stub), change it here - too, so new repositories don't start out of date. -- **Reusable workflows live in [chorrell/workflows](https://github.com/chorrell/workflows).** - Workflows here are short stubs that own their triggers, `permissions` and - `concurrency` and call the shared workflow by tag (`@v1`). Third-party actions - are pinned by commit hash with a version comment; zizmor enforces this. -- **zizmor is the workflow linter.** Reference actions and reusable workflows - in the same repository with GitHub's `$/` self-repository syntax - (`uses: $/.github/workflows/build.yml`), not `./`, as zizmor's - `self-repository` audit requires. actionlint isn't used because it rejects - `$/` ([rhysd/actionlint#711](https://github.com/rhysd/actionlint/issues/711)). -- **Repository settings aren't configured here.** Merge settings, rulesets and - required status checks are managed by Terraform in - [chorrell/github-settings](https://github.com/chorrell/github-settings) - (`repos.yaml`). Don't change them in the GitHub UI. -- Run `prek run --all-files` before pushing (the markdownlint hook needs - Docker). CI runs markdownlint on pull requests to `main`, and zizmor on - every pull request and push to `main`. `zizmor / zizmor` is a required check - on every repository, so don't remove the zizmor stub. -- Dependabot opens one monthly `chore(deps): bump the tooling group ...` PR - for Actions and pre-commit hooks. `dependabot-automerge.yml` merges it once - checks pass if every update is minor or patch; majors wait for review. Add - other ecosystems (uv, Docker, Terraform) as separate entries, outside the - `tooling` group, so they aren't auto-merged. A repository that publishes or - deploys on pushes to `main` should drop the auto-merge stub, because merges - made with `GITHUB_TOKEN` don't trigger push workflows. -- Commits and PR titles use conventional commits (`feat: ...`, `ci: ...`, - `chore(deps): ...`). Branch from `main` with a `feature/` prefix. PRs are - squash-merged, so keep PR bodies short and focused on intent. +- **Generate new entries with `scripts/new_repos.py`, don't write them by hand.** `description`, `homepage_url`, + `topics`, `has_issues` and `has_discussions` are managed, so leaving one out resets it on the repository. The + script copies the current values from GitHub and sets only what differs from the defaults in + `modules/repository/variables.tf`. It can't know about CI, so add `required_status_checks` by hand. +- **Keep `repos.yaml` as plain data.** Quote strings that aren't simple words (the script uses JSON-style double + quotes, which are valid YAML). A new option needs a variable in the module, a `try()` in `main.tf`, and an entry in + `local.repo_options` and the script's `OPTIONS`. +- **The `new-repos` workflow proposes new repositories daily** as a PR from `bot/new-repos`. While that PR is open, + later runs skip, so push edits (such as required checks) straight to its branch. + The workflow is skipped until the GitHub App variable and secret exist; see the README's "Setup". +- **This repository is public and a portfolio piece.** Keep the history, issues and PRs free of secrets and of + anything about private repositories. Those are managed separately, by `chorrell/github-settings`. +- **Managed repositories must be public.** The organization is on GitHub Free, which doesn't allow rulesets on private + repositories, so an apply fails on a private entry. +- **Don't turn on `merge_queue` for this repository.** HCP Terraform doesn't plan merge queue branches, so its required + check would never report. Use it only where every required check runs in GitHub Actions with a `merge_group` trigger. +- **To keep a repository out, archive it.** The bot skips archived repositories and forks, and proposes anything else + that isn't in `repos.yaml`, so dropping an entry from its PR only lasts until the next run. +- **Removing an entry never deletes a repository.** `prevent_destroy` makes the PR's plan fail instead. To stop + managing one, open the PR that drops the entry, then run `terraform state rm 'module.repository[""]'` from a + laptop (it edits the HCP state) and re-run the PR's plan, which should show no changes. Merge it right away: until + then, a run on `main` would import the repository again. A `removed` block can't target one `for_each` instance. +- **Archived repositories and forks are not managed.** Archived repositories are read-only, so an apply fails on them. + Archive a repository only after removing it from `repos.yaml` and the state. +- **To make a private repository public, flip it first, then merge.** The provider sends `visibility` and + `security_and_analysis` in one PATCH, and GitHub rejects it with `422 Secret scanning is not available for this + repository` while the repository is still private. Open the `visibility: public` PR and check its plan, then run + `gh repo edit horrell-consulting/ --visibility public --accept-visibility-change-consequences` and merge the PR right + away. The merge's apply then only turns on secret scanning and push protection. Until the PR merges, any apply here + makes the repository private again, so don't flip it while another PR is about to merge. + - If the PR was merged first, its apply fails with that 422. Flip the repository, then re-run the apply (a manual + run needs a confirm in HCP). +- **Every repository gets exactly one ruleset, `default-branch`, owned by Terraform.** Don't add rulesets or branch + protection in the GitHub UI; put required checks in `required_status_checks` instead. +- **`zizmor / zizmor` is required on every repository** (`local.baseline_status_checks` in `main.tf`). Don't list it in + `repos.yaml`. Before applying a new entry, make sure the repository has the zizmor stub from `chorrell/template-repo`, + or its pull requests can't merge. +- **Read every PR's HCP speculative plan before merging.** Merging applies it. Expect only the intended changes. A + diff on `description`, `topics` or other per-repository fields means an entry is missing a value. +- **Never apply from a laptop.** State is in HCP; `terraform plan` from a laptop runs remotely as a speculative plan, + and `terraform apply` fails because the workspace is VCS-connected. See "Auto-apply workflow" below. +- This repository is managed by itself, so every change goes through a pull request and is squash-merged. +- Run `prek run --all-files` before pushing. It covers `terraform fmt`/`validate`/`tflint`, ruff (check and format) + for `scripts/`, zizmor, gitleaks and markdownlint. + zizmor is the workflow linter; actionlint isn't used because it rejects GitHub's `$/` self-repository `uses:` + syntax ([rhysd/actionlint#711](https://github.com/rhysd/actionlint/issues/711)). +- Commits and PR titles use conventional commits (`feat: ...`, `chore(deps): ...`). Keep PR bodies short and focused + on intent. + +## Auto-apply workflow + +State and runs live in the HCP Terraform workspace `horrell/horrell-consulting-github-settings`, whose settings are managed in +[chorrell/hcp-terraform-horrell](https://github.com/chorrell/hcp-terraform-horrell). A merge to `main` is the deploy: +it queues a run that applies without a confirm. The PR is where review happens. + +- **Every PR gets a speculative plan,** reported as `Terraform Cloud/horrell/horrell-consulting-github-settings` with its + add/change/destroy counts, and a policy check, `sentinel/horrell/horrell-consulting-github-settings`. Both are required, with + `validate` and `markdownlint / Markdown Lint`, so a PR can't merge until the plan passes. +- **The provider authenticates as a GitHub App** (separate from the new-repos bot), from the sensitive + `GITHUB_APP_ID`, `GITHUB_APP_INSTALLATION_ID` and `GITHUB_APP_PEM_FILE` env vars on the workspace, set by hand in + the HCP UI. `app_auth {}` makes them required arguments, so CI and pre-commit pass placeholders to `validate`. +- **Deletion guards:** + - `prevent_destroy` is on every resource in `modules/repository`, so a removed entry or a change that forces a + replacement fails the plan. Replacing a ruleset would leave the branch unprotected for a moment and change its ID. + - `prevent_destroy` only covers resources still in config. A PR that removes the guard, or renames a resource + without a `moved` block, plans a plain destroy. The `no-deletes` Sentinel policy (soft-mandatory, in + hcp-terraform-horrell's `deletion-guard` set) fails any plan that deletes or replaces a resource, and with it the + required `sentinel/horrell/horrell-consulting-github-settings` check. + - **Allow destroy plans** is off on the workspace, so nobody can queue a whole-workspace destroy run. +- **To unmanage a repository,** use `terraform state rm` as in the rules above, not a delete. +- **To delete or replace something on purpose,** remove the `prevent_destroy` in the PR, merge it with the admin + bypass (the policy check fails on the speculative plan, which can't be overridden), then override the soft-failed + policy check on the apply run in the HCP UI. Restore the guard in a follow-up PR. +- The workspace emails the owner when a run starts applying, waits for approval or errors, since nobody watches the + runs. diff --git a/README.md b/README.md index f799c5b..516e595 100644 --- a/README.md +++ b/README.md @@ -1,58 +1,132 @@ -# template-repo - -[![markdownlint](https://github.com/chorrell/template-repo/actions/workflows/markdownlint.yml/badge.svg)](https://github.com/chorrell/template-repo/actions/workflows/markdownlint.yml) - -The GitHub template I start new repositories from. It holds the lint, -Dependabot and pre-commit defaults every project shares, so a new repository -starts with the same baseline instead of copying files by hand. - -## What's included - -| File | Purpose | -| --- | --- | -| [`.pre-commit-config.yaml`](.pre-commit-config.yaml) | gitleaks, markdownlint-cli2, zizmor and the standard `pre-commit-hooks` hygiene checks. zizmor is the workflow linter; actionlint isn't used because it rejects GitHub's `$/` self-repository `uses:` syntax ([rhysd/actionlint#711](https://github.com/rhysd/actionlint/issues/711)) | -| [`.github/dependabot.yml`](.github/dependabot.yml) | One monthly `tooling` PR for GitHub Actions and pre-commit hook updates, with a 7-day cooldown | -| [`.github/workflows/markdownlint.yml`](.github/workflows/markdownlint.yml) | Lints Markdown on pull requests with the shared [chorrell/workflows](https://github.com/chorrell/workflows) workflow | -| [`.github/workflows/pre-commit.yml`](.github/workflows/pre-commit.yml) | Runs every pre-commit hook on pull requests, so hook updates are tested | -| [`.github/workflows/dependabot-automerge.yml`](.github/workflows/dependabot-automerge.yml) | Auto-merges the Dependabot `tooling` PR once checks pass, when every update is minor or patch | -| [`.github/workflows/zizmor.yml`](.github/workflows/zizmor.yml) | Audits GitHub Actions workflows with zizmor on pull requests and pushes to `main`, using the shared chorrell/workflows workflow | -| [`.github/zizmor.yml`](.github/zizmor.yml) | Lets `chorrell/*` reusable workflows be pinned by tag; everything else must be pinned by commit hash | -| [`.github/CODEOWNERS`](.github/CODEOWNERS) | Requests my review on every change | -| [`.markdownlint.yaml`](.markdownlint.yaml) | Markdown lint rules (line length is not enforced) | -| [`.gitignore`](.gitignore) / [`.gitattributes`](.gitattributes) | Language-agnostic ignores and LF normalization | -| [`AGENTS.md`](AGENTS.md) / [`CLAUDE.md`](CLAUDE.md) | Guidance for coding agents; `CLAUDE.md` imports `AGENTS.md` | -| [`LICENSE`](LICENSE) | Mozilla Public License 2.0 | - -## Creating a repository from this template - -```sh -gh repo create chorrell/ --template chorrell/template-repo --public --clone -``` +# github-settings + +[![terraform](https://github.com/horrell-consulting/github-settings/actions/workflows/terraform.yml/badge.svg)](https://github.com/horrell-consulting/github-settings/actions/workflows/terraform.yml) +[![zizmor](https://github.com/horrell-consulting/github-settings/actions/workflows/zizmor.yml/badge.svg)](https://github.com/horrell-consulting/github-settings/actions/workflows/zizmor.yml) -Then: +Every repository in the `horrell-consulting` organization, including this one, +is configured by the Terraform in this repository. Settings, branch rulesets, +required checks and security features are code, reviewed in a pull request and +applied on merge by HCP Terraform. New repositories are onboarded by a bot. -1. Retitle this README and describe the new project. -2. Rewrite `AGENTS.md` for the project. Keep `CLAUDE.md` as it is. -3. Add language-specific pre-commit hooks (ruff, shellcheck, hadolint, - terraform, ...) and Dependabot ecosystems (`docker`, `uv`, `terraform`, ...). -4. Add language-specific entries to `.gitignore`. -5. Check that `CODEOWNERS` and `LICENSE` still fit. -6. Add the repository to - [chorrell/github-settings](https://github.com/chorrell/github-settings) - (its daily bot proposes it), with any CI checks it should require beyond - `zizmor / zizmor`, which every repository requires. +## What every repository gets -## Local development +Each repository listed in [`repos.yaml`](repos.yaml) gets the baseline in +[`modules/repository`](modules/repository): -Install [prek](https://github.com/j178/prek) (`brew install prek`), a faster -drop-in replacement for pre-commit, and run the hooks before pushing: +- **Merging:** squash merges only, with the pull request title and description + as the commit message. Auto-merge and "update branch" are on, and head + branches are deleted after merging. +- **Default branch ruleset:** changes go through a pull request, with linear + history, no force-pushes and no deletion. Review threads must be resolved. + Repository admins can bypass it in an emergency. +- **Required checks:** `zizmor / zizmor` (GitHub Actions security audit) on + every repository, plus each repository's own CI checks. +- **Security:** Dependabot alerts and security updates, and secret scanning + with push protection. +- **Actions:** the default `GITHUB_TOKEN` is read-only and can't approve pull + requests. +- **Housekeeping:** wikis and projects are off. -```sh -prek install -prek run --all-files +## How it works + +```text +pull request ──► HCP speculative plan + Sentinel policy check + CI ──► review ──► merge ──► apply + ▲ +daily new-repos bot ──► pull request adding unmanaged repositories ───────────────────┘ ``` -The markdownlint hook runs in Docker, so Docker needs to be running. +1. A pull request gets a speculative plan from HCP Terraform, reported as the + `Terraform Cloud/horrell/horrell-consulting-github-settings` check, and a + policy check, `sentinel/horrell/horrell-consulting-github-settings`. Both + are required, along with `validate`, markdownlint and pre-commit. +2. Merging to `main` applies the plan without a confirm. The pull request is + where review happens. +3. The [`new-repos`](.github/workflows/new-repos.yml) workflow runs daily and + opens a pull request adding any repository that isn't archived, isn't a + fork, and isn't in `repos.yaml` yet. Each entry copies the repository's + current description, topics and settings, so the first apply changes only + the baseline. Existing repositories are adopted with `import` blocks, not + recreated. + +## Design decisions + +- **Nothing can be deleted by accident.** Merges apply unattended, so there + are three independent guards: `prevent_destroy` on every resource, a + [Sentinel policy](https://github.com/chorrell/hcp-terraform-horrell/blob/main/policies/no-deletes.sentinel) + that fails any plan deleting or replacing a resource, and destroy plans + turned off on the workspace. Removing a repository from `repos.yaml` fails + the plan instead of deleting it. +- **The repository list is data, not HCL.** `repos.yaml` is read with + `yamldecode`, so a bot can edit it safely and a `${` in a description is just + text. A misspelled option fails the plan rather than being silently ignored. +- **GitHub Apps, not personal access tokens.** Terraform authenticates as an + organization-owned GitHub App with only the permissions it needs. The bot + uses a second, smaller app, and mints two short-lived tokens per run: one + that can only read metadata across the organization, and one that can write + to this repository only. Pull requests opened with an app token run CI, + which `GITHUB_TOKEN` pull requests don't. +- **Public, but safe to be public.** No secrets are in the repository or its + state: credentials are sensitive variables on the HCP workspace. HCP + Terraform doesn't run speculative plans for pull requests from forks, so an + outside contribution can't run provider code with the app's key. +- **No merge queue here.** The module supports one (`merge_queue: true`), but + HCP Terraform plans pull requests, not merge queue branches, so its required + check would never report and every queued pull request would wait forever. + Merge queues suit repositories whose required checks all come from GitHub + Actions with a `merge_group` trigger. +- **Separate from my personal repositories.** My personal account has its own + copy of this setup for private repositories. Keeping them apart gives each + owner its own GitHub App, workspace and state, so a mistake in one can't + reach the other. + +## Usage + +- **Change a setting:** edit `repos.yaml` or the module, open a pull request, + read the HCP plan, and merge. +- **Add a repository:** create it from + [chorrell/template-repo](https://github.com/chorrell/template-repo), which + provides the zizmor stub every repository requires. The bot proposes it + within a day, or run the workflow from the Actions tab. Add its CI checks to + `required_status_checks` in the bot's pull request before merging. +- **Keep a repository out:** archive it. +- **Stop managing a repository:** open the pull request that removes its + entry, run `terraform state rm 'module.repository[""]'` from a laptop, + re-run the pull request's plan, and merge it right away. + +`terraform plan` from a laptop runs a remote speculative plan after +`terraform login`. `terraform apply` from a laptop fails, because the +workspace is VCS-connected: merging is the only way to apply. + +Run `prek run --all-files` before pushing. It covers `terraform fmt`, +`validate` and tflint, ruff for `scripts/`, zizmor, gitleaks and markdownlint. + +## Setup + +Done once; kept here so the setup can be reproduced. + +1. **Terraform's GitHub App.** Create a GitHub App owned by the organization, + with no webhook and these repository permissions: **Administration** read + and write, **Dependabot alerts** read and write, **Contents** read, + **Pages** read. Install it on all repositories. +2. **HCP Terraform workspace.** Install the HCP Terraform GitHub App on the + organization, then create the workspace `horrell-consulting-github-settings` + in the `horrell` HCP organization, connected to this repository. Add + `GITHUB_APP_ID`, `GITHUB_APP_INSTALLATION_ID` and `GITHUB_APP_PEM_FILE` as + sensitive environment variables. The key goes on one line, with `\n` for + each line break: + + ```sh + awk 'NF {printf "%s\\n", $0}' key.pem | pbcopy + ``` + + The workspace's run settings, notifications and Sentinel policy are managed + in [chorrell/hcp-terraform-horrell](https://github.com/chorrell/hcp-terraform-horrell). +3. **Bot app.** Create a second organization-owned GitHub App with no webhook + and **Contents** and **Pull requests** read and write. Install it on all + repositories. Add its client ID as the Actions variable + `NEW_REPOS_APP_CLIENT_ID` and a private key as the Actions secret + `NEW_REPOS_APP_PRIVATE_KEY`. If a scheduled run fails, it opens an issue, + which the next successful run closes. ## License diff --git a/imports.tf b/imports.tf new file mode 100644 index 0000000..11b49f6 --- /dev/null +++ b/imports.tf @@ -0,0 +1,7 @@ +# Adopt existing repositories instead of trying to create them. Importing an +# already-managed repository is a no-op, so this block can stay in place. +import { + for_each = local.repos + to = module.repository[each.key].github_repository.this + id = each.key +} diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..1c93cba --- /dev/null +++ b/main.tf @@ -0,0 +1,35 @@ +locals { + # Managed repositories and their options. Kept as YAML so values are plain + # data: `${` in a description is text, not a Terraform template. + repos = yamldecode(file("${path.module}/repos.yaml")) + + repo_options = [ + "visibility", "description", "homepage_url", "topics", "is_template", + "has_issues", "has_discussions", "required_status_checks", "merge_queue", + ] + # Checks every repository must pass, on top of its own required_status_checks. + # Repositories get the zizmor stub from chorrell/template-repo. + baseline_status_checks = ["zizmor / zizmor"] + + unknown_repo_options = sort(flatten([ + for name, repo in local.repos : [ + for key in keys(repo) : "${name}.${key}" if !contains(local.repo_options, key) + ] + ])) +} + +module "repository" { + source = "./modules/repository" + for_each = local.repos + + name = each.key + visibility = each.value.visibility + description = try(each.value.description, null) + homepage_url = try(each.value.homepage_url, null) + topics = try(each.value.topics, []) + is_template = try(each.value.is_template, false) + has_issues = try(each.value.has_issues, true) + has_discussions = try(each.value.has_discussions, false) + required_status_checks = distinct(concat(local.baseline_status_checks, try(each.value.required_status_checks, []))) + merge_queue = try(each.value.merge_queue, false) +} diff --git a/modules/repository/main.tf b/modules/repository/main.tf new file mode 100644 index 0000000..668481f --- /dev/null +++ b/modules/repository/main.tf @@ -0,0 +1,142 @@ +resource "github_repository" "this" { + name = var.name + visibility = var.visibility + description = var.description + homepage_url = var.homepage_url + topics = var.topics + is_template = var.is_template + + has_issues = var.has_issues + has_discussions = var.has_discussions + has_projects = false + has_wiki = false + + # Squash merging only, using the pull request title and description. + allow_merge_commit = false + allow_rebase_merge = false + allow_squash_merge = true + squash_merge_commit_title = "PR_TITLE" + squash_merge_commit_message = "PR_BODY" + + allow_auto_merge = true + allow_update_branch = true + delete_branch_on_merge = true + + # Secret scanning is free for public repositories only; private ones need + # GitHub Secret Protection. + dynamic "security_and_analysis" { + for_each = var.visibility == "public" ? [1] : [] + content { + secret_scanning { + status = "enabled" + } + secret_scanning_push_protection { + status = "enabled" + } + } + } + + lifecycle { + # Removing a repository from repos.yaml must never delete it on GitHub. + prevent_destroy = true + + # Records which template a repository was created from; it can't be + # changed afterwards, so don't try to reconcile it. + ignore_changes = [template] + } +} + +resource "github_repository_vulnerability_alerts" "this" { + repository = github_repository.this.name + enabled = true + + # A forced replacement fails the plan instead; see the ruleset below. + lifecycle { + prevent_destroy = true + } +} + +resource "github_repository_dependabot_security_updates" "this" { + repository = github_repository.this.name + enabled = true + + depends_on = [github_repository_vulnerability_alerts.this] + + # A forced replacement fails the plan instead; see the ruleset below. + lifecycle { + prevent_destroy = true + } +} + +resource "github_workflow_repository_permissions" "this" { + repository = github_repository.this.name + default_workflow_permissions = "read" + can_approve_pull_request_reviews = false + + # A forced replacement fails the plan instead; see the ruleset below. + lifecycle { + prevent_destroy = true + } +} + +resource "github_repository_ruleset" "default_branch" { + name = "default-branch" + repository = github_repository.this.name + target = "branch" + enforcement = "active" + + conditions { + ref_name { + include = ["~DEFAULT_BRANCH"] + exclude = [] + } + } + + # Repository admins (you) can bypass the rules in an emergency. + bypass_actors { + actor_id = 5 # Built-in "admin" repository role + actor_type = "RepositoryRole" + bypass_mode = "always" + } + + rules { + deletion = true + non_fast_forward = true + required_linear_history = true + + pull_request { + allowed_merge_methods = ["squash"] + required_approving_review_count = 0 + required_review_thread_resolution = true + dismiss_stale_reviews_on_push = true + } + + dynamic "required_status_checks" { + for_each = length(var.required_status_checks) > 0 ? [1] : [] + content { + strict_required_status_checks_policy = false + + dynamic "required_check" { + for_each = var.required_status_checks + content { + context = required_check.value + } + } + } + } + + dynamic "merge_queue" { + for_each = var.merge_queue ? [1] : [] + content { + merge_method = "SQUASH" + } + } + } + + # Merges apply without a confirm, so a change that would destroy or replace + # any of these resources fails the plan instead. Replacing the ruleset would + # leave the branch unprotected for a moment and change the ruleset's ID. + lifecycle { + prevent_destroy = true + } +} diff --git a/modules/repository/outputs.tf b/modules/repository/outputs.tf new file mode 100644 index 0000000..92f473a --- /dev/null +++ b/modules/repository/outputs.tf @@ -0,0 +1,4 @@ +output "html_url" { + description = "URL of the repository on GitHub." + value = github_repository.this.html_url +} diff --git a/modules/repository/variables.tf b/modules/repository/variables.tf new file mode 100644 index 0000000..9eef13b --- /dev/null +++ b/modules/repository/variables.tf @@ -0,0 +1,62 @@ +variable "name" { + description = "Repository name." + type = string +} + +variable "visibility" { + description = "Repository visibility: public or private." + type = string + + validation { + condition = contains(["public", "private"], var.visibility) + error_message = "visibility must be \"public\" or \"private\"." + } +} + +variable "description" { + description = "Repository description. Leaving it null clears any existing description." + type = string + default = null +} + +variable "homepage_url" { + description = "Repository homepage URL. Leaving it null clears any existing URL." + type = string + default = null +} + +variable "topics" { + description = "Repository topics." + type = list(string) + default = [] +} + +variable "is_template" { + description = "Whether the repository is a template repository." + type = bool + default = false +} + +variable "has_issues" { + description = "Whether issues are enabled." + type = bool + default = true +} + +variable "has_discussions" { + description = "Whether discussions are enabled." + type = bool + default = false +} + +variable "required_status_checks" { + description = "Status check names that must pass before merging into the default branch." + type = list(string) + default = [] +} + +variable "merge_queue" { + description = "Require a merge queue on the default branch. Only works for public repositories owned by an organization." + type = bool + default = false +} diff --git a/modules/repository/versions.tf b/modules/repository/versions.tf new file mode 100644 index 0000000..cf2f9a6 --- /dev/null +++ b/modules/repository/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 1.16" + + required_providers { + github = { + source = "integrations/github" + version = ">= 6.13" + } + } +} diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..83dec58 --- /dev/null +++ b/outputs.tf @@ -0,0 +1,11 @@ +output "repositories" { + description = "Managed repositories and their URLs." + value = { for name, repo in module.repository : name => repo.html_url } + + # main.tf reads each option with try(), so a misspelled key in repos.yaml + # would otherwise be ignored silently. Fail the plan instead. + precondition { + condition = length(local.unknown_repo_options) == 0 + error_message = "Unknown options in repos.yaml: ${join(", ", local.unknown_repo_options)}. See modules/repository/variables.tf." + } +} diff --git a/providers.tf b/providers.tf new file mode 100644 index 0000000..599b7ee --- /dev/null +++ b/providers.tf @@ -0,0 +1,8 @@ +# Authenticates as a GitHub App, from the sensitive GITHUB_APP_ID, +# GITHUB_APP_INSTALLATION_ID and GITHUB_APP_PEM_FILE environment variables on +# the HCP workspace. Runs only happen on HCP, so there's no token fallback. +provider "github" { + owner = var.owner + + app_auth {} +} diff --git a/repos.yaml b/repos.yaml new file mode 100644 index 0000000..2d8849e --- /dev/null +++ b/repos.yaml @@ -0,0 +1,30 @@ +# Repositories managed by this project, read by main.tf. Each key is the +# repository name under horrell-consulting. Every option has a default in +# modules/repository/variables.tf; set only what differs from the baseline. +# +# Archived repositories and forks are never managed. New repositories are +# proposed automatically by the new-repos workflow (scripts/new_repos.py); to +# keep one out, archive it. + +".github": + visibility: public + description: Organization profile and default community health files + required_status_checks: + - markdownlint / Markdown Lint + - pre-commit / pre-commit + +github-settings: + visibility: public + description: Terraform for the settings and rulesets of the horrell-consulting repositories + topics: + - terraform + - hcp-terraform + - github + - sentinel + - infrastructure-as-code + required_status_checks: + - validate + - markdownlint / Markdown Lint + - Terraform Cloud/horrell/horrell-consulting-github-settings + - sentinel/horrell/horrell-consulting-github-settings + - pre-commit / pre-commit diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..3ada041 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,6 @@ +# Ruff settings for scripts/. The GitHub-hosted runners have a newer Python, +# but the script also runs locally on macOS's Python 3.9. +target-version = "py39" + +[lint] +extend-select = ["B", "I", "UP", "SIM"] diff --git a/scripts/new_repos.py b/scripts/new_repos.py new file mode 100755 index 0000000..fb51031 --- /dev/null +++ b/scripts/new_repos.py @@ -0,0 +1,157 @@ +#!/usr/bin/env python3 +"""Add entries to repos.yaml for repositories that aren't managed yet. + +Lists the owner's repositories with the GitHub CLI and skips archived ones, +forks, and anything already in repos.yaml. Each new entry copies the +repository's current visibility, description, homepage, topics and +issue/discussion settings, so the first plan only changes the baseline. + +Needs `gh` (authenticated). Prints the names of the repositories it added, one +per line. +""" + +import argparse +import json +import re +import subprocess +import sys + +REPOS_YAML = "repos.yaml" + +# Options in the order they're written. See modules/repository/variables.tf. +OPTIONS = [ + "visibility", + "description", + "homepage_url", + "topics", + "is_template", + "has_issues", + "has_discussions", + "required_status_checks", + "merge_queue", +] + +# A top-level key: a repository name, bare or JSON-quoted. +KEY_RE = re.compile(r'^("(?:[^"\\]|\\.)*"|[^\s#"][^:]*):\s*$') +PLAIN_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9 ._/()+-]*$") +NUMBER_RE = re.compile(r"^[-+]?[0-9._]+([eE][-+]?[0-9]+)?$") +RESERVED = {"true", "false", "yes", "no", "on", "off", "y", "n", "null"} + + +def scalar(value): + """Render a YAML scalar, quoting strings unless they're unambiguous. + + A JSON string is also a valid YAML double-quoted string, so json.dumps + handles every character that needs escaping. + """ + if isinstance(value, bool): + return "true" if value else "false" + plain = ( + PLAIN_RE.match(value) + and value == value.strip() + and value.lower() not in RESERVED + and not NUMBER_RE.match(value) + ) + return value if plain else json.dumps(value, ensure_ascii=False) + + +def render(name, options): + lines = [f"{scalar(name)}:"] + for key in sorted(options, key=OPTIONS.index): + value = options[key] + if isinstance(value, list): + lines.append(f" {key}:") + lines += [f" - {scalar(item)}" for item in value] + else: + lines.append(f" {key}: {scalar(value)}") + return [line + "\n" for line in lines] + + +def options_for(repo): + """The options for a repository: only those that differ from the defaults.""" + options = {"visibility": repo["visibility"].lower()} + if repo.get("description"): + options["description"] = repo["description"] + if repo.get("homepageUrl"): + options["homepage_url"] = repo["homepageUrl"] + topics = [t["name"] for t in repo.get("repositoryTopics") or []] + if topics: + options["topics"] = topics + if repo.get("isTemplate"): + options["is_template"] = True + if not repo.get("hasIssuesEnabled", True): + options["has_issues"] = False + if repo.get("hasDiscussionsEnabled"): + options["has_discussions"] = True + return options + + +def key_lines(lines): + """Map line index to repository name for every top-level key.""" + keys = {} + for i, line in enumerate(lines): + m = KEY_RE.match(line.rstrip("\n")) + if m: + key = m.group(1) + keys[i] = json.loads(key) if key.startswith('"') else key.strip() + return keys + + +def insert(lines, name, options): + """Insert an entry before the first existing entry that sorts after it.""" + entry = render(name, options) + for i, key in key_lines(lines).items(): + if key.lower() > name.lower(): + lines[i:i] = entry + ["\n"] + return + if lines and not lines[-1].endswith("\n"): + lines[-1] += "\n" + lines += ["\n"] + entry + + +def github_repos(owner): + fields = ( + "name,visibility,isArchived,isFork,isTemplate,description,homepageUrl," + "repositoryTopics,hasIssuesEnabled,hasDiscussionsEnabled" + ) + out = subprocess.run( + ["gh", "repo", "list", owner, "--limit", "1000", "--json", fields], + capture_output=True, + text=True, + check=True, + ).stdout + return json.loads(out) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("--owner", default="horrell-consulting") + args = parser.parse_args() + + with open(REPOS_YAML) as f: + lines = f.readlines() + known = set(key_lines(lines).values()) + + new = sorted( + ( + r + for r in github_repos(args.owner) + if not r["isArchived"] and not r["isFork"] and r["name"] not in known + ), + key=lambda r: r["name"].lower(), + ) + if not new: + return 0 + + for repo in new: + insert(lines, repo["name"], options_for(repo)) + with open(REPOS_YAML, "w") as f: + f.writelines(lines) + + for repo in new: + print(repo["name"]) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..9d7f217 --- /dev/null +++ b/variables.tf @@ -0,0 +1,5 @@ +variable "owner" { + description = "GitHub user or organization that owns the managed repositories." + type = string + default = "horrell-consulting" +} diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..37ff954 --- /dev/null +++ b/versions.tf @@ -0,0 +1,19 @@ +terraform { + required_version = ">= 1.16" + + required_providers { + github = { + source = "integrations/github" + version = "~> 6.13" + } + } + + # Runs on HCP Terraform: a PR gets a speculative plan, and a merge to main + # applies. The workspace's settings live in chorrell/hcp-terraform-horrell. + cloud { + organization = "horrell" + workspaces { + name = "horrell-consulting-github-settings" + } + } +} From f42943e323f50b9fda36b82bbf691bcdaf4a5f2a Mon Sep 17 00:00:00 2001 From: Christopher Horrell Date: Fri, 13 Nov 2026 10:43:29 -0500 Subject: [PATCH 2/3] docs: tighten merge queue rationale and .github description --- AGENTS.md | 2 +- README.md | 10 ++++++---- repos.yaml | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index b372397..62e03e4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -38,7 +38,7 @@ baseline every repository gets and for day-to-day usage. anything about private repositories. Those are managed separately, by `chorrell/github-settings`. - **Managed repositories must be public.** The organization is on GitHub Free, which doesn't allow rulesets on private repositories, so an apply fails on a private entry. -- **Don't turn on `merge_queue` for this repository.** HCP Terraform doesn't plan merge queue branches, so its required +- **Don't turn on `merge_queue` for this repository.** HCP Terraform doesn't report on merge queue branches, so its required check would never report. Use it only where every required check runs in GitHub Actions with a `merge_group` trigger. - **To keep a repository out, archive it.** The bot skips archived repositories and forks, and proposes anything else that isn't in `repos.yaml`, so dropping an entry from its PR only lasts until the next run. diff --git a/README.md b/README.md index 516e595..d0d3bfd 100644 --- a/README.md +++ b/README.md @@ -70,10 +70,12 @@ daily new-repos bot ──► pull request adding unmanaged repositories ── Terraform doesn't run speculative plans for pull requests from forks, so an outside contribution can't run provider code with the app's key. - **No merge queue here.** The module supports one (`merge_queue: true`), but - HCP Terraform plans pull requests, not merge queue branches, so its required - check would never report and every queued pull request would wait forever. - Merge queues suit repositories whose required checks all come from GitHub - Actions with a `merge_group` trigger. + a merge queue needs every required check to report on its temporary merge + branch. HCP Terraform reports on pull requests, and its documentation + describes no support for merge queue branches, so a queued pull request here + would wait for a check that never comes. Merge queues suit repositories + whose required checks all come from GitHub Actions with a `merge_group` + trigger. - **Separate from my personal repositories.** My personal account has its own copy of this setup for private repositories. Keeping them apart gives each owner its own GitHub App, workspace and state, so a mistake in one can't diff --git a/repos.yaml b/repos.yaml index 2d8849e..0eccfa3 100644 --- a/repos.yaml +++ b/repos.yaml @@ -8,7 +8,7 @@ ".github": visibility: public - description: Organization profile and default community health files + description: Organization profile required_status_checks: - markdownlint / Markdown Lint - pre-commit / pre-commit From 06fb348ac94acda935d348bbcb16f1e52deae1d0 Mon Sep 17 00:00:00 2001 From: Christopher Horrell Date: Fri, 13 Nov 2026 10:43:39 -0500 Subject: [PATCH 3/3] docs: clarify merge queue rule --- AGENTS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 62e03e4..9d96112 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -38,8 +38,8 @@ baseline every repository gets and for day-to-day usage. anything about private repositories. Those are managed separately, by `chorrell/github-settings`. - **Managed repositories must be public.** The organization is on GitHub Free, which doesn't allow rulesets on private repositories, so an apply fails on a private entry. -- **Don't turn on `merge_queue` for this repository.** HCP Terraform doesn't report on merge queue branches, so its required - check would never report. Use it only where every required check runs in GitHub Actions with a `merge_group` trigger. +- **Don't turn on `merge_queue` for this repository.** HCP Terraform doesn't report on merge queue branches, so queued PRs + would wait forever for its required check. Use it only where every required check runs in GitHub Actions with a `merge_group` trigger. - **To keep a repository out, archive it.** The bot skips archived repositories and forks, and proposes anything else that isn't in `repos.yaml`, so dropping an entry from its PR only lasts until the next run. - **Removing an entry never deletes a repository.** `prevent_destroy` makes the PR's plan fail instead. To stop