Skip to content

Commit df1b028

Browse files
committed
ci: serialize labeler runs with cancellation and make the title step repeatable
The Preflight actionlint does not know the queue setting. One group per pull request with cancellation keeps a single writer, and the title step now runs first on every event, adding the type label only while the pull request has none, so a run replaced or cancelled by a newer push loses nothing and a hand-picked type label stays.
1 parent 28b3531 commit df1b028

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

‎.github/workflows/label_prs.yml‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,24 @@ permissions:
2828
contents: read
2929
pull-requests: write
3030

31-
# One group per pull request, queued rather than cancelled: the labeler action reads the label
32-
# set and writes it back whole, so two runs writing at once can drop a label the other just
33-
# added, and the opened run must always complete because the title step runs on open only.
31+
# One group per pull request with cancellation, so at most one run writes labels at a time:
32+
# the labeler action reads the label set and writes it back whole, and two runs writing at
33+
# once can drop a label the other just added. A cancelled or replaced run loses nothing
34+
# because every step below is safe to repeat on the next event.
3435
concurrency:
3536
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
36-
queue: max
37+
cancel-in-progress: true
3738

3839
jobs:
3940
label:
4041
runs-on: ubuntu-slim
4142
steps:
42-
- name: Label by changed paths
43-
uses: actions/labeler@v7
44-
with:
45-
configuration-path: .github/labeler.yml
46-
sync-labels: false
47-
4843
# The type label follows the conventional commit prefix in the title, matching how
49-
# maintainers label by hand. Only on open, so later hand edits are not overwritten, and
50-
# not for dependabot, whose PRs already carry the dependencies label.
44+
# maintainers label by hand. It is added only while the pull request carries no type
45+
# label at all, so a hand-picked replacement stays, and a run cut short by a newer push
46+
# is completed by that push. Dependabot pull requests already carry their label.
5147
- name: Label by title prefix
52-
if: github.event.action == 'opened' && github.actor != 'dependabot[bot]'
48+
if: github.actor != 'dependabot[bot]'
5349
uses: actions/github-script@v9
5450
with:
5551
script: |
@@ -73,7 +69,12 @@ jobs:
7369
deps: ['dependencies'],
7470
};
7571
const labels = byPrefix[match[1].toLowerCase()];
72+
const typeLabels = new Set(Object.values(byPrefix).flat());
7673
const present = new Set(context.payload.pull_request.labels.map((l) => l.name));
74+
if ([...present].some((l) => typeLabels.has(l))) {
75+
core.info('A type label is already present, leaving it as is');
76+
return;
77+
}
7778
const missing = labels.filter((l) => !present.has(l));
7879
if (missing.length === 0) {
7980
return;
@@ -84,3 +85,9 @@ jobs:
8485
issue_number: context.issue.number,
8586
labels: missing,
8687
});
88+
89+
- name: Label by changed paths
90+
uses: actions/labeler@v7
91+
with:
92+
configuration-path: .github/labeler.yml
93+
sync-labels: false

0 commit comments

Comments
 (0)