Skip to content

Commit 68c8dac

Browse files
authored
Open sync pull requests when a consumer's automation.yml drifts
Consumer repos hold a copied automation-template.yml, and nothing checked that the copies still matched. A stale copy fails silently: the repo keeps running its old on: block, so a new automation never fires there. The workflow finds the consumers, compares each copy against the template, and opens one pull request per repo that differs. It only proposes. It never commits to a default branch, and never merges or approves. Refs #95.
1 parent deb6cc8 commit 68c8dac

4 files changed

Lines changed: 806 additions & 2 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Sync automation template
2+
run-name: Open a pull request in every consumer repo whose automation.yml has drifted
3+
on:
4+
schedule:
5+
- cron: "17 6 * * 1"
6+
workflow_dispatch:
7+
inputs:
8+
dry_run:
9+
description: 'Report drift without opening pull requests'
10+
type: boolean
11+
default: false
12+
push:
13+
branches:
14+
- main
15+
paths:
16+
- automation-template.yml
17+
permissions:
18+
contents: read
19+
concurrency:
20+
group: sync-automation-template
21+
cancel-in-progress: false
22+
jobs:
23+
sync:
24+
name: Sync consumers
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Generate App Token
28+
id: generate-token
29+
uses: actions/create-github-app-token@v3
30+
with:
31+
app-id: ${{ secrets.LE_BOT_APP_ID }}
32+
private-key: ${{ secrets.LE_BOT_PRIVATE_KEY }}
33+
owner: learningequality
34+
- name: Checkout
35+
uses: actions/checkout@v6
36+
- name: Setup Node.js
37+
uses: actions/setup-node@v6
38+
with:
39+
node-version: '20'
40+
cache: 'yarn'
41+
- name: Install dependencies
42+
run: yarn install --frozen-lockfile
43+
- name: Sync consumers
44+
env:
45+
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
46+
run: node scripts/sync-automation-template.js ${{ inputs.dry_run && '--dry-run' || '' }}

‎docs/automation.md‎

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ No edits required. Then set the secrets:
4747
| `CONTRIBUTIONS_SHEET_NAME` | no | Sheet name within the spreadsheet |
4848
| `GH_UPLOADER_GCP_SA_CREDENTIALS` | no | GCP service account credentials for Sheets access |
4949

50-
Every automation except `resolve-bot-pr-threads` authenticates as the bot, so the two required
51-
secrets must be set. `resolve-bot-pr-threads` uses the default `GITHUB_TOKEN` instead.
50+
Every automation except `resolve-bot-pr-threads` authenticates as `learning-equality-bot[bot]`, the
51+
GitHub App behind `LE_BOT_APP_ID`, so the two required secrets must be set. `resolve-bot-pr-threads`
52+
uses the default `GITHUB_TOKEN` instead.
5253

5354
Optional means that you accept losing the automations that use the secret. It does not mean that
5455
they degrade gracefully. The generated caller forwards every key, so an absent secret reaches the
@@ -68,3 +69,57 @@ leaf workflow as an empty string, and every automation that needs it fails at ru
6869
picks up the wider `on:` block the next time they re-copy `automation-template.yml` - existing
6970
copies keep running on their current `on:` block until then, since GitHub workflow triggers are
7071
evaluated from the file checked into the consumer repo itself, not from this repo.
72+
73+
## Keeping the copies in sync
74+
75+
Most registry changes reach consumers automatically because their copied file only says:
76+
`uses: learningequality/.github/.github/workflows/automation.yml@main`. A consumer needs its file
77+
updated whenever its copy no longer matches the template, which happens in two ways.
78+
79+
The template changes here, such as when a new event or activity type is added to the `on:` union,
80+
permissions are widened, or the secret list changes. Or the consumer's own tooling rewrites its
81+
copy, which is reported as a `toolchain-conflict` below.
82+
83+
`.github/workflows/sync-automation-template.yml` handles this. It runs weekly, on manual dispatch,
84+
and whenever `automation-template.yml` changes on `main`.
85+
86+
It discovers the consumers by walking the org's repos, skipping archived ones and forks, and keeping
87+
every repo whose `.github/workflows/automation.yml` calls this repo's `automation.yml`. Each pull
88+
request targets that repo's default branch, which is the only branch GitHub evaluates workflow
89+
triggers from.
90+
91+
For each consumer it compares the copy with the template and opens a pull request when they differ.
92+
A repo that is already in sync gets nothing, while a repo with an existing sync pull request has
93+
that pull request updated rather than a second one opened.
94+
95+
The workflow only proposes changes. It opens pull requests on a branch, never commits to a default
96+
branch, and never merges, approves, or enables auto-merge. A core maintainer in each consumer repo
97+
gives the final review and merges under that repo's own rules.
98+
99+
Run it with `dry_run` to see which repos have drifted without opening any pull requests.
100+
101+
Two results turn the run red and require action:
102+
103+
- `error` means the repo could not be read or written. The app already has the permissions required
104+
for syncing, so this is usually a transient API failure or the app not being installed on that
105+
repo. Check the installation first for a recently added repo.
106+
- `toolchain-conflict` means a sync pull request was merged, the template has not changed since, and
107+
the file has drifted again. The repo's own tooling is rewriting the copy, so the template is not
108+
stable under that toolchain. Fix the template rather than reopening the pull request.
109+
110+
A third result, `declined`, keeps the run green and requires no action. It means a core maintainer
111+
closed the last sync pull request without merging it, so the workflow leaves that repo alone until
112+
the template changes again. The repo remains drifted in the meantime. To restore it sooner, copy the
113+
template in by hand.
114+
115+
To onboard a repo, copy the template in and make sure the `learning-equality-bot[bot]` app is
116+
installed on it. The next run picks it up. A repo on which the app is not installed stays invisible
117+
to the sync, so the installation is what enrols it.
118+
119+
The pull request body is a short explanation of what changed and why the file is generated.
120+
121+
`kolibri-design-system` is the exception. Its `check-description` job fails unless the body carries
122+
a Changelog section whose Description is not the placeholder its own template ships with, and a
123+
plain explanation has no such section. For that repo the sync reads its template and fills each
124+
field, so the body is not a half-filled form. Nothing about that template is stored here, so it
125+
stays current as they change it.

0 commit comments

Comments
 (0)