Skip to content

Commit 76f008d

Browse files
install-labels: Install the agent labels on every pipeline repository (#126)
* install-labels: Test that the workflow copy of LABELS matches install-labels.yml has to inline the label list because gh aw add copies it into consumer repositories without the script, so the two copies are kept in sync by hand. Nothing checked that, and the pipeline-wide installer coming next applies the install-labels.js copy to every repository running the pipeline, so drift between the two would go unnoticed. Also document agent/flake-tracker, which the scripts README list was missing. Prep for installing labels on every pipeline repository. Generated-by: AI Signed-off-by: Colin Walters <walters@verbum.org> * install-labels: Plan label changes before applying them installLabels() blindly PATCHed every label it found and only created one after a getLabel 404, which means a request per label per run even when nothing changed, and no way to see what a run would do. Split it into a pure planLabelChanges() over the repository's current labels and a small apply step behind a transport interface, so the planned diff is unit tested, can be printed as a dry run, and the upcoming multi-repository installer can reuse the same code with the gh CLI instead of carrying its own copy of the create/update logic. Labels are matched case-insensitively like GitHub does, so a label that differs only in case is renamed rather than failing to create a duplicate. Prep for installing labels on every pipeline repository. Generated-by: AI Signed-off-by: Colin Walters <walters@verbum.org> * install-labels: Install the labels on every pipeline repository Each repository running the pipeline installs its labels from its own copy of install-labels.yml, which only changes when that repository runs gh aw update, so a new or renamed label can take a long time to arrive: bcvk still lacks agent/drafter-working after the rename, and its drafter silently skips setting its working label because gh issue edit --add-label refuses unknown labels. Add install-labels-org.yml, run on every push to main, that applies LABELS to every bootc-dev repository containing any of drafter.lock.yml, review.lock.yml or fix.lock.yml, the compiled workflows gh aw add installs, so a repository that adopted only part of the pipeline still counts. Today that is bootc, bcvk, infra and gh-agentic-workflows; the other 17 repositories don't run the pipeline and have no use for agent/* labels, so they are skipped rather than cluttered. With --installation it only considers repositories the pipeline's App is installed on, so an adopter the App doesn't cover yet is not tried (and failed) on every run. It runs as a postsubmit rather than on a schedule: label changes land here, so a push is when there is something to apply, and syncing on every push rather than only label changes also repairs drift (labels edited by hand, or reverted by a repository's outdated install-labels.yml) without polling, for one label listing per pipeline repository when nothing changed. bootc-dev/infra already syncs labels.toml to every bootc-dev and composefs repository. Putting the agent labels there was considered, but that sync is unconditional, so it would need a per-label repository filter it doesn't have, and it would add a third copy of LABELS in a different repository with nothing checking it against the two here that gh aw add distributes. Keeping the agent labels here means one repository owns their definition, distribution and sync, while infra keeps owning org-wide labels; the two sets don't overlap. Nothing here runs against the live organization in PR CI; the dry run is available locally or by dispatching the workflow with dry-run. Closes: #104 Generated-by: AI Signed-off-by: Colin Walters <walters@verbum.org> --------- Signed-off-by: Colin Walters <walters@verbum.org>
1 parent f1b7feb commit 76f008d

5 files changed

Lines changed: 598 additions & 40 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ jobs:
9393
assert.ok(snapshot.coverage.aic.total === null || typeof snapshot.coverage.aic.total === 'number');
9494
NODE
9595
96+
install-labels:
97+
runs-on: ubuntu-24.04
98+
permissions:
99+
contents: read
100+
steps:
101+
- name: Checkout repository
102+
uses: actions/checkout@v7
103+
104+
- name: Test label installer
105+
run: node --test tests/install-labels.test.js
106+
96107
history-immutability:
97108
if: github.event_name == 'pull_request'
98109
runs-on: ubuntu-24.04
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Install labels on pipeline repositories
2+
3+
# This is a plain (non-gh-aw) workflow: installs the pipeline's labels
4+
# (scripts/install-labels.js LABELS) on every repository in the organization
5+
# that runs the pipeline, i.e. contains any of drafter.lock.yml,
6+
# review.lock.yml or fix.lock.yml in .github/workflows, so they pick up new or
7+
# renamed labels without waiting for their own copy of install-labels.yml to
8+
# be updated. It only creates labels and fixes their color, description and
9+
# name case; it never deletes one.
10+
#
11+
# Labels every repository should have regardless of the pipeline are synced by
12+
# bootc-dev/infra (labels.toml) instead; this workflow owns only the agent/*
13+
# labels. It is not part of the gh-aw package (aw.yml): it's specific to the
14+
# organization hosting this repository.
15+
16+
on:
17+
# Every push to main syncs, not only those changing the label set: a run
18+
# that finds nothing to change costs one label listing per pipeline
19+
# repository, and it repairs labels changed by hand or reverted by a
20+
# repository's outdated install-labels.yml without polling for drift.
21+
push:
22+
branches: [main]
23+
workflow_dispatch:
24+
inputs:
25+
dry-run:
26+
description: "Only print the planned label changes (uncheck to apply them)"
27+
type: boolean
28+
default: true
29+
30+
permissions:
31+
contents: read
32+
33+
concurrency:
34+
group: install-labels-org
35+
cancel-in-progress: false
36+
37+
jobs:
38+
install-labels:
39+
# Forks have neither the App credentials nor any business editing the
40+
# organization's labels.
41+
if: github.repository == 'bootc-dev/gh-agentic-workflows'
42+
runs-on: ubuntu-24.04
43+
steps:
44+
- name: Checkout repository
45+
uses: actions/checkout@v7
46+
with:
47+
persist-credentials: false
48+
49+
# The pipeline's own App: it is installed wherever the pipeline runs,
50+
# and --installation below only considers repositories it can access.
51+
- name: Generate label token
52+
id: app-token
53+
uses: actions/create-github-app-token@v3
54+
with:
55+
client-id: ${{ vars.GH_AW_APP_CLIENT_ID }}
56+
private-key: ${{ secrets.GH_AW_APP_PRIVATE_KEY }}
57+
owner: ${{ github.repository_owner }}
58+
# Labels are managed through the Issues API; contents: read is for
59+
# detecting the pipeline marker file.
60+
permission-issues: write
61+
permission-contents: read
62+
63+
- name: Install labels
64+
env:
65+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
66+
ORG: ${{ github.repository_owner }}
67+
DRY_RUN: ${{ inputs.dry-run && '--dry-run' || '' }}
68+
run: |
69+
set -euo pipefail
70+
# shellcheck disable=SC2086 # DRY_RUN is empty or a single flag.
71+
node scripts/install-labels.js --org "$ORG" --installation $DRY_RUN

‎scripts/README.md‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ The script creates or updates the following labels:
6868

6969
- **`agent/workflow-edits-allowed`** (purple) — Pre-authorizes an agent run to edit protected files (workflows, README, etc.) without triggering the request_review gate. Apply this to an issue before labeling it `agent/code`, or to a PR before applying `agent/fixme`.
7070

71+
- **`agent/flake-tracker`** (blue) — Marks the CI flake tracker issue that the merge queue analyzer (`queue-triage.md`) maintains.
72+
7173
### Usage
7274

7375
#### Via GitHub Actions
@@ -85,6 +87,33 @@ Alternatively, you can copy `.github/workflows/install-labels.yml` to your own r
8587
workflow inlines the LABELS array and install loop directly in its `actions/github-script` step, so it has no
8688
dependency on this file being checked out.
8789

90+
#### On every pipeline repository in bootc-dev
91+
92+
`.github/workflows/install-labels-org.yml` runs this script on every push to `main` and on
93+
dispatch. It installs the labels on every non-archived
94+
bootc-dev repository that runs the pipeline, i.e. contains any of `drafter.lock.yml`,
95+
`review.lock.yml` or `fix.lock.yml` in `.github/workflows`, and that the `GH_AW_APP_*` App
96+
is installed on. Other repositories are left alone. It creates missing labels and fixes the color,
97+
description and name case of existing ones, but never deletes a label. It is not part of the gh-aw
98+
package and runs only from `bootc-dev/gh-agentic-workflows`.
99+
100+
Each pipeline repository also keeps running its own weekly copy of `install-labels.yml`,
101+
which only picks up label changes when that repository runs `gh aw update`. So after a
102+
label's color or description changes here, that copy reverts it to the old value (and
103+
recreates a renamed label's old name) every week until the repository updates it, and
104+
the next push to `main` here applies the new value again.
105+
106+
Only the `agent/*` labels are managed here. Labels every bootc-dev and composefs
107+
repository should have regardless of the pipeline (e.g. `triaged`) are synced by
108+
[bootc-dev/infra](https://github.com/bootc-dev/infra)'s `labels.toml`.
109+
110+
To see what it would change without writing anything, run it with any authenticated
111+
`gh` (read access is enough), or dispatch the workflow, which does a dry run unless `dry-run` is unchecked:
112+
113+
```bash
114+
node scripts/install-labels.js --org bootc-dev --dry-run
115+
```
116+
88117
#### Via github-script action
89118

90119
If you want to integrate label installation into your own workflow, `install-labels.js` is a plain CommonJS module
@@ -137,5 +166,6 @@ gh api repos/:owner/:repo/labels/agent/code -X PATCH \
137166
### Customizing Labels
138167

139168
To customize the labels (change colors, descriptions, or add new ones), edit the `LABELS` array in
140-
`install-labels.js` **and** the matching copy in `.github/workflows/install-labels.yml`, then rerun the
141-
installation workflow to update the labels on your repository.
169+
`install-labels.js` **and** the matching copy in `.github/workflows/install-labels.yml`
170+
(`tests/install-labels.test.js` fails if they differ), then rerun the installation workflow to update
171+
the labels on your repository.

0 commit comments

Comments
 (0)