From 6f5f95e1a11a3efdbe6bfa3154ef9ccab82c88aa Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Fri, 23 Oct 2026 15:21:13 +0100 Subject: [PATCH 1/2] ci(release): mint pyautolabs-bot App token for the nightly driver; retire repo_settings.yml nightly-release.yml drops PAT_PYAUTOLABS for a per-job, owner-wide App token (actions write, contents read, issues read): the driver dispatches and polls the Hands release and Heart integrate workflows and reads commits, tags and release-blocker issues across the release-relevant repos. repo_settings.yml needs repo Administration, which the App deliberately lacks, so it is deleted with its test; the skills that pointed at it now give the local gh api -X PATCH delete_branch_on_merge loop. Refs PyAutoLabs/PyAutoBrain#531 Co-Authored-By: Claude Opus 5.5 --- .github/workflows/nightly-release.yml | 19 ++- .github/workflows/repo_settings.yml | 179 -------------------------- skills/GITHUB_ACCESS.md | 2 +- skills/prm/reference.md | 2 +- skills/repo_cleanup/SKILL.md | 5 +- skills/repo_cleanup/reference.md | 33 +++-- tests/test_repo_settings_workflow.py | 176 ------------------------- 7 files changed, 43 insertions(+), 373 deletions(-) delete mode 100644 .github/workflows/repo_settings.yml delete mode 100644 tests/test_repo_settings_workflow.py diff --git a/.github/workflows/nightly-release.yml b/.github/workflows/nightly-release.yml index 36a09bd6..a325be7f 100644 --- a/.github/workflows/nightly-release.yml +++ b/.github/workflows/nightly-release.yml @@ -86,10 +86,27 @@ jobs: - name: Install PyYAML (Heart's only dependency) run: pip install --quiet pyyaml + - name: Mint App token (dispatch + poll the release path, read activity) + # The driver dispatches and polls PyAutoHands release.yml and the + # PyAutoHeart integrate workflow (actions write), reads main commits and + # tags across the release-relevant repos (contents read) and their open + # `release-blocker` issues (issues read). That set spans most of the + # org, so the token is owner-wide (no `repositories:`). No fallback: a + # failed mint fails the job before any gate is judged. + id: app_token + uses: actions/create-github-app-token@v3 + with: + client-id: ${{ vars.APP_CLIENT_ID }} + private-key: ${{ secrets.APP_PRIVATE_KEY }} + owner: PyAutoLabs + permission-actions: write + permission-contents: read + permission-issues: read + - name: Run the nightly driver id: driver env: - GH_TOKEN: ${{ secrets.PAT_PYAUTOLABS }} + GH_TOKEN: ${{ steps.app_token.outputs.token }} PYAUTO_RELEASE_WEBHOOK_URL: ${{ secrets.PYAUTO_RELEASE_WEBHOOK_URL }} NIGHTLY_RELEASES: ${{ vars.NIGHTLY_RELEASES }} # Scheduled runs have no inputs: default 'false' — ARMED 2026-07-09 diff --git a/.github/workflows/repo_settings.yml b/.github/workflows/repo_settings.yml deleted file mode 100644 index aa3c88fd..00000000 --- a/.github/workflows/repo_settings.yml +++ /dev/null @@ -1,179 +0,0 @@ -name: Repo Settings - -# Turns on "Automatically delete head branches" across the organism's repos, -# and reports any repo where it is off. -# -# WHY THIS EXISTS. Branch cleanup was written as a close-out step: /prm deletes -# the head once the PR merges. That step cannot run in a cloud Claude session — -# a ref delete there dies on a 403 in front of GitHub, and (the part that made -# it a silent hole) `git push origin --delete` still prints "Everything -# up-to-date" and exits 0, so the run cannot tell the delete failed. Every web -# close-out therefore left its branch on origin while reporting success. -# -# branch_sweep.yml is the backstop for the backlog that already piled up. This -# workflow is the fix: with the setting on, GitHub removes each head at merge -# and no session credential is involved at all. It is a *per-repo* setting with -# no org-wide default, so something has to visit each repo — that something is -# here rather than a browser tab per repo. -# -# WHY IT ENUMERATES THE ORG RATHER THAN THE BODY MAP. It derived its targets -# from the body map first, and that was blind in exactly the wrong place: a -# repo is created *before* anyone registers it, so the repos most in need of -# the setting were the ones the sweep could not see — along with any repo whose -# category the body map excludes for the branch sweep's sake, a boundary drawn -# around *deleting refs* that has no bearing on flipping a boolean. Listing the -# organisation instead means a new repo is covered the run after it exists, and -# no category question arises. `--outside-owner` supplies the complement: the -# body-map repos under some other account, which an org listing cannot return. -# -# WHY THE SCHEDULE APPLIES RATHER THAN AUDITS. Unlike the branch sweep, this -# deletes nothing: it flips a boolean whose effect starts at the *next* merge, -# and it is one click to undo. Left as audit-only it would report the same -# drift every week and rely on someone acting on it — which is the failure this -# is meant to end. - -on: - workflow_dispatch: - inputs: - mode: - description: "apply = turn the setting on where it is off · audit = report only" - type: choice - options: [apply, audit] - default: apply - schedule: - # Weekly, an hour after the org-wide branch sweep's audit, so a fresh repo - # is corrected shortly after that audit has shown it accumulating heads. - - cron: "40 6 * * 0" - -permissions: - contents: read - -concurrency: - group: repo-settings - cancel-in-progress: false - -jobs: - settings: - runs-on: ubuntu-latest - steps: - - name: Check out PyAutoBrain (the complement derivation lives here) - uses: actions/checkout@v4 - with: - fetch-depth: 1 - - - name: Check out the Mind (the body map the complement derives from) - uses: actions/checkout@v4 - with: - repository: ${{ github.repository_owner }}/PyAutoMind - path: .mind - fetch-depth: 1 - - - uses: actions/setup-python@v5 - with: - python-version: "3.12" - - run: pip install --quiet pyyaml - - - name: Read or set the merge setting, per repo - env: - # A repo's own GITHUB_TOKEN reaches only that repo, and this setting - # needs admin on each one. Same credential the org-wide sweep uses. - GH_TOKEN: ${{ secrets.PAT_PYAUTOLABS }} - # Passed as env rather than interpolated into the script below, so a - # value containing shell metacharacters cannot become shell. - ORG: ${{ github.repository_owner }} - MODE: ${{ inputs.mode }} - run: | - set -uo pipefail - # GitHub runs this block as `bash -e`. That is wrong for this script: - # its whole design is to survive a per-repo failure and REPORT it, and - # the read below sends stderr to /dev/null, so under -e the first - # unreadable repo aborted the run with no output at all — the - # unreadable branch and the in-org/out-of-org split never executed. - # Disabled explicitly rather than with `|| true` on one line, because - # the hazard applies to every guarded command here, not just that one. - set +e - mode="${MODE:-apply}" - - if [ -z "${GH_TOKEN:-}" ]; then - echo "::error::PAT_PYAUTOLABS is not set — cannot reach sibling repos." - exit 1 - fi - - # Every repo in the organisation, archived ones excluded: an archived - # repo takes no merges, and PATCHing one fails. - in_org=$(gh api --paginate "orgs/$ORG/repos?per_page=100" \ - --jq '.[] | select(.archived == false) | .full_name') - if [ -z "$in_org" ]; then - # Distinguishable from "nothing to do": an empty listing means the - # PAT lost org read, and sweeping nothing would look like success. - echo "::error::listed no repos in $ORG — refusing to continue." - exit 1 - fi - - # The complement: body-map repos an org listing cannot return. - outside=$(python3 bin/branch_sweep_targets.py --outside-owner "$ORG" .mind/repos.yaml) - - { - echo "## Automatically delete head branches — \`$mode\`" - echo - echo "| Repo | Scope | Before | Action |" - echo "|---|---|---|---|" - } >> "$GITHUB_STEP_SUMMARY" - - failed=0 changed=0 already=0 - - visit() { - slug="$1" scope="$2" - # Out-of-org repos sit under a personal account. The org PAT's - # admin scope there is unverified by design, so a refusal is - # expected and must not redden a weekly unattended run; in-org, the - # same refusal is a real finding. - case "$scope" in - in-org) hard=1 ;; - *) hard=0 ;; - esac - - before=$(gh api "repos/$slug" --jq '.delete_branch_on_merge' 2>/dev/null) - case "$before" in - true) - already=$((already + 1)) - echo "| \`$slug\` | $scope | on | — |" >> "$GITHUB_STEP_SUMMARY" - return ;; - false) ;; - *) - echo "::warning::$slug — could not read the setting (repo missing, or the PAT cannot see it)" - echo "| \`$slug\` | $scope | ? | **unreadable** |" >> "$GITHUB_STEP_SUMMARY" - if [ "$hard" -eq 1 ]; then failed=1; fi - return ;; - esac - - if [ "$mode" = "audit" ]; then - echo "| \`$slug\` | $scope | off | would enable |" >> "$GITHUB_STEP_SUMMARY" - changed=$((changed + 1)) - return - fi - - # -F, not -f: the API wants a JSON boolean, not the string "true". - if gh api -X PATCH "repos/$slug" -F delete_branch_on_merge=true --silent 2>/dev/null; then - echo "✓ $slug — enabled" - echo "| \`$slug\` | $scope | off | **enabled** |" >> "$GITHUB_STEP_SUMMARY" - changed=$((changed + 1)) - else - # The read succeeded, so this is a permission ceiling, not a typo: - # changing a repo setting needs admin, which read access does not - # imply. Widening a PAT is a human decision, not a retry. - echo "::warning::$slug — PATCH refused; the PAT needs admin on this repo" - echo "| \`$slug\` | $scope | off | **refused (needs admin)** |" >> "$GITHUB_STEP_SUMMARY" - if [ "$hard" -eq 1 ]; then failed=1; fi - fi - } - - for slug in $in_org; do visit "$slug" in-org; done - for slug in $outside; do visit "$slug" outside; done - - { - echo - echo "$already already on · $changed $([ "$mode" = audit ] && echo 'to enable' || echo 'enabled')" - } >> "$GITHUB_STEP_SUMMARY" - - [ "$failed" -eq 0 ] || { echo "::error::one or more repos in $ORG could not be read or set — see the table"; exit 1; } diff --git a/skills/GITHUB_ACCESS.md b/skills/GITHUB_ACCESS.md index 44a534e8..2c5916e1 100644 --- a/skills/GITHUB_ACCESS.md +++ b/skills/GITHUB_ACCESS.md @@ -189,7 +189,7 @@ against `gh api repos/...` REST paths runs in a remote session by pointing the 403 goes to stderr, git then prints `Everything up-to-date` and exits 0, so the run cannot tell the delete failed and will report one that never happened. Never run it here. No workflow asks you to: GitHub deletes a merged PR's head - itself (`repo_settings.yml` keeps that setting on), and `branch_sweep.yml` + itself (the per-repo `delete_branch_on_merge` setting), and `branch_sweep.yml` sweeps the rest. Nothing about branch cleanup belongs in an MCP-surface run. - **Reach a repo outside the session's scope.** The session is scoped to a repository set at start; `add_repo` extends it. A call outside that scope is diff --git a/skills/prm/reference.md b/skills/prm/reference.md index 8376170b..5adfebeb 100644 --- a/skills/prm/reference.md +++ b/skills/prm/reference.md @@ -393,7 +393,7 @@ directory listing is the only way to find it. Local branches go with the worktree. **The remote branch is not `/prm`'s to delete, on any surface** — GitHub removes a merged PR's head itself, kept on per -repo by `repo_settings.yml` (`delete_branch_on_merge`), and `branch_sweep.yml` / +repo by the `delete_branch_on_merge` setting, and `branch_sweep.yml` / `branch_sweep_all.yml` collect whatever escapes that: a head pushed without a PR, a PR closed unmerged, a repo whose setting is off. `/repo_cleanup` Bucket B does the same locally. So run no `git push --delete`, and write no branch line diff --git a/skills/repo_cleanup/SKILL.md b/skills/repo_cleanup/SKILL.md index 6180a002..1757b412 100644 --- a/skills/repo_cleanup/SKILL.md +++ b/skills/repo_cleanup/SKILL.md @@ -125,7 +125,8 @@ Format: [`reference.md`](reference.md) → "Recap". - Suggest `/health worktrees` first if unsure whether tasks are in flight. - A repo that still accumulates merged PR heads has **"Automatically delete head branches" off** (Settings → General). That setting prevents the backlog this - skill exists to clear, and no sweep substitutes for it — dispatch - `repo_settings.yml` (mode `apply`) to turn it on org-wide, then move on. + skill exists to clear, and no sweep substitutes for it — have the human run + the local `gh api -X PATCH` loop in [`reference.md`](reference.md) (it needs + repo admin, which no workflow credential carries), then move on. - Cloud-session routing (dispatch `branch_sweep.yml` rather than pushing deletes) is in [`reference.md`](reference.md) → "Execution environments". diff --git a/skills/repo_cleanup/reference.md b/skills/repo_cleanup/reference.md index 47b0b185..815bfa71 100644 --- a/skills/repo_cleanup/reference.md +++ b/skills/repo_cleanup/reference.md @@ -167,12 +167,10 @@ Never-touched repos fall out with their categories — `autolens_assistant` is a names them twice. Brain code may not name satellite repos at all (the tenant firewall enforces this; a hardcoded list was written first and rejected). -That boundary is this sweep's alone. `repo_settings.yml` no longer shares it: -flipping `delete_branch_on_merge` is not deleting a ref, and a body-map-derived -target set could never see a repo in the window between its creation and its -registration — so it lists the organisation from the GitHub API instead, and -uses `--outside-owner` only for the body-map repos an org listing cannot -return. +That boundary is this sweep's alone. Flipping `delete_branch_on_merge` (below) +is not deleting a ref, and a body-map-derived target set could never see a repo +in the window between its creation and its registration — so that loop lists +the organisation from the GitHub API instead. ## Branches that must not simply be deleted @@ -209,13 +207,22 @@ unaffected: their heads live in the fork.) survive has *Settings → General → "Automatically delete head branches"* off. That single toggle removes each head at merge and stops the backlog forming; this sweep is the backstop for what predates it, for branches pushed without a -PR, and for heads whose PR closed unmerged. There is no repo-settings *tool*, -but there is a workflow: dispatch **`repo_settings.yml`** in PyAutoBrain (mode -`apply`) and it turns the setting on across every development repo in the body -map, including any added since. It also runs weekly, so a repo born after today -is corrected without anyone noticing it drifted. Report a repo it lists as -`refused (needs admin)` to the human — that is a PAT scope, not something to -retry. +PR, and for heads whose PR closed unmerged. There is no repo-settings *tool* and +no workflow: the setting needs repo **admin**, which the org's `pyautolabs-bot` +App deliberately lacks (so it can never delete or reconfigure a repo), so the +former `repo_settings.yml` sweep was retired. The human runs it locally with +their own admin credential — rerun it after creating a repo: + +```bash +for r in $(gh repo list PyAutoLabs -L 200 --no-archived --json name --jq '.[].name'); do + gh api -X PATCH "repos/PyAutoLabs/$r" -F delete_branch_on_merge=true --jq '"\(.full_name) \(.delete_branch_on_merge)"' +done +``` + +(`-F`, not `-f`: the field is a JSON boolean, and `-f` sends the string +`"true"`.) A repo under another owner in the body map is not in that listing; +flip it by hand in its Settings → General. Report any `403` to the human rather +than retrying. Whichever environment: resolve each repo's `/` from the `github:` field in `PyAutoMind/repos.yaml` (the body map is the single source of repo diff --git a/tests/test_repo_settings_workflow.py b/tests/test_repo_settings_workflow.py deleted file mode 100644 index d580b76f..00000000 --- a/tests/test_repo_settings_workflow.py +++ /dev/null @@ -1,176 +0,0 @@ -"""tests/test_repo_settings_workflow.py — the settings sweep's shell block. - -**Why this file exists.** The sweep was control-tested across seven scenarios -before it shipped, and still failed on its first real dispatch. The harness ran -`bash