Data updates: open the PR with ATLAS_BOT_TOKEN and auto-merge it once CI passes (#7)
Changes made with GITHUB_TOKEN do not start other workflows, so a merged data PR would not redeploy the site. With the ATLAS_BOT_TOKEN secret the workflow opens the PR with it and turns on auto-merge; without it, it falls back to GITHUB_TOKEN and a manual merge. docs/REPO_SETTINGS.md lists the settings only the owner can change (auto-merge, the ruleset for main, the token). Refs #4, #5, #6 Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
2b905b4a84
commit
dcd5117373
@@ -10,6 +10,9 @@ permissions:
|
||||
jobs:
|
||||
check:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
# secrets cannot be tested in `if:` directly
|
||||
HAS_BOT_TOKEN: ${{ secrets.ATLAS_BOT_TOKEN != '' }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
@@ -27,16 +30,26 @@ jobs:
|
||||
node scripts/build-graph.js
|
||||
npm run policy
|
||||
npm test
|
||||
# The PR is opened with ATLAS_BOT_TOKEN (a fine-grained token, see docs/REPO_SETTINGS.md) when it is set:
|
||||
# changes made with the built-in GITHUB_TOKEN do not start other workflows, so its merge would not
|
||||
# redeploy the site. Without the secret it falls back to GITHUB_TOKEN and the PR waits for a manual merge.
|
||||
- name: Open a pull request with the new data
|
||||
id: pr
|
||||
if: steps.check.outputs.changed == 'true'
|
||||
uses: peter-evans/create-pull-request@v6
|
||||
with:
|
||||
token: ${{ secrets.ATLAS_BOT_TOKEN || github.token }}
|
||||
branch: data/source-update
|
||||
delete-branch: true
|
||||
commit-message: "data: update from community sources"
|
||||
title: "New data from the community sources"
|
||||
body-path: ${{ runner.temp }}/report.md
|
||||
labels: data
|
||||
- name: Merge it automatically once CI passes
|
||||
if: steps.pr.outputs.pull-request-number != '' && env.HAS_BOT_TOKEN == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.ATLAS_BOT_TOKEN }}
|
||||
run: gh pr merge "${{ steps.pr.outputs.pull-request-number }}" --auto --squash
|
||||
- name: Report a broken source link
|
||||
if: steps.check.outputs.failed != ''
|
||||
env:
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
# Repository settings
|
||||
|
||||
Some settings live on GitHub, not in the code. Only the repository owner (ekcSchiano) can change them.
|
||||
They go together: the ruleset makes CI a gate on `main`, auto-merge lets a pull request merge itself once
|
||||
it passes, and the token lets the daily data update do that on its own.
|
||||
|
||||
## 1. Allow auto-merge (issue #4)
|
||||
|
||||
Settings → General → Pull Requests:
|
||||
|
||||
- tick **Allow auto-merge**
|
||||
- tick **Automatically delete head branches**
|
||||
|
||||
## 2. Require CI to pass on `main` (issue #5)
|
||||
|
||||
Settings → Rules → Rulesets → New ruleset → New branch ruleset:
|
||||
|
||||
| Field | Value |
|
||||
|---|---|
|
||||
| Ruleset name | `main: CI must pass` |
|
||||
| Enforcement status | Active |
|
||||
| Bypass list | leave empty |
|
||||
| Target branches | Add target → Include default branch |
|
||||
| Restrict deletions | on |
|
||||
| Block force pushes | on |
|
||||
| Require a pull request before merging | on, required approvals **0** |
|
||||
| Require status checks to pass | on → Add checks → `test` (GitHub Actions) |
|
||||
|
||||
`test` is the job in `.github/workflows/ci.yml`. It runs the JS and Python tests, the JS/Python parity
|
||||
checks, checks that `data/public/graph.json` is up to date, and builds the site.
|
||||
|
||||
From then on every change, including ours, goes through a pull request. Nothing can be pushed straight to
|
||||
`main`. To merge without waiting, open the PR and turn on auto-merge; it merges when `test` passes.
|
||||
|
||||
## 3. Access token for automation (issue #6)
|
||||
|
||||
The daily source check (`.github/workflows/update-sources.yml`) opens a pull request when the community data
|
||||
change. If it uses the built-in `GITHUB_TOKEN`, GitHub does not start other workflows from what it does. CI
|
||||
still runs on the PR, but after the merge the site would not redeploy. With a token it opens the PR, turns on
|
||||
auto-merge, and the merge redeploys the site.
|
||||
|
||||
Create the token at github.com → Settings → Developer settings → Personal access tokens → Fine-grained tokens →
|
||||
Generate new token:
|
||||
|
||||
| Field | Value |
|
||||
|---|---|
|
||||
| Token name | `threshing-atlas automation` |
|
||||
| Resource owner | ekcSchiano |
|
||||
| Expiration | 90 days, with a calendar reminder to renew |
|
||||
| Repository access | Only select repositories → `ekcSchiano/threshing-atlas` |
|
||||
| Repository permissions | **Contents: Read and write**, **Pull requests: Read and write** (Metadata: Read-only is added automatically) |
|
||||
|
||||
Then store it as a secret, never in a file, issue, chat or commit: repository Settings → Secrets and
|
||||
variables → Actions → New repository secret, name **`ATLAS_BOT_TOKEN`**.
|
||||
|
||||
Without the secret the workflow still works. It falls back to `GITHUB_TOKEN` and the PR waits for a manual
|
||||
merge.
|
||||
|
||||
If Ken's bot should also open pull requests here (for example to send new bot runs), create a **second** token
|
||||
with the same settings and store it as a secret in the bot's own repository. Separate tokens can be revoked
|
||||
separately, and a leak in one place does not expose the other.
|
||||
Reference in New Issue
Block a user