-
Notifications
You must be signed in to change notification settings - Fork 3
52 lines (44 loc) · 1.64 KB
/
rw-preview-label.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
name: Update Preview Label
# Ensure that only this Pull Request has the preview label.
on:
workflow_call:
jobs:
preview_labels:
name: Update preview labels
runs-on: ubuntu-latest
steps:
- name: Remove preview label from all other PRs
uses: actions/github-script@v7
with:
script: |
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: 'preview',
});
for (const issue of issues.data) {
if (issue.number === context.issue.number) continue;
if (!issue.pull_request) continue;
console.log(`Removing label from #${issue.number}`);
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
name: 'preview',
});
}
# When two PRs get the Preview label before they can execute, the first will
# remove the label from the second, and the second from the first. This would
# leave no PR with a Preview label. So always make sure that if we finish,
# our PR has a preview label. As by concurrency one PR always finishes last,
# the last one is now guaranteed to have a preview label.
- name: Ensure we have a preview label
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['preview'],
});