Repository navigation
70 lines (66 loc) · 3.26 KB
/
Copy pathupdate.yaml
File metadata and controls
70 lines (66 loc) · 3.26 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# "/update" comments on pull requests: bring main into the branch (CONTRIBUTING.md, "We do the chores"). The logic is
# in .github/scripts/update.js (tested by .github/scripts/update.test.js). It reads the comment only to compare it
# with "/update", and never checks out or runs the pull request's code: conflicts are found with git merge-tree on
# the git objects alone.
name: Update pull requests
on:
issue_comment:
types: [created]
# A push to a pull request labelled "needs update" takes the label off once the branch is up to date (for example
# after the author clicked "Update branch", or a maintainer merged main in by hand).
pull_request_target:
types: [synchronize]
permissions: {}
jobs:
update:
# Pull requests only (an issue comment also fires issue_comment), and only a comment that is exactly the command
# (allowing a trailing space or line break), so other comments never queue here.
if: >-
github.event_name == 'issue_comment' &&
github.event.issue.pull_request != null &&
contains(fromJSON('["/update", "/update ", "/update\n", "/update\r\n"]'), github.event.comment.body)
concurrency:
group: update-pr-${{ github.event.issue.number }}
runs-on: ubuntu-latest
timeout-minutes: 8
# Each one was tried for real (#464): update-branch needs both contents and pull-requests write, also for a fork
# with maintainer edits on. GitHub holds the checks of a commit made with this token, so restarting them needs
# the other two (see update.js).
permissions:
contents: write # update-branch writes the merge commit to the pull request's branch
pull-requests: write # update-branch, the reply and the "needs update" label
actions: write # approve the held CI runs on the bot's own merge commit
checks: write # copy the CLA check to that merge commit, as pull_request_target doesn't run for it
steps:
# issue_comment always runs on the default branch, so this is our own script, never a contributor's.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
sparse-checkout: .github/scripts
persist-credentials: false
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const run = require('./.github/scripts/update.js');
await run({ github, context, core });
clear-label:
if: >-
github.event_name == 'pull_request_target' &&
contains(github.event.pull_request.labels.*.name, 'needs update')
concurrency:
group: update-pr-${{ github.event.pull_request.number }}
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
pull-requests: write # removing the label
steps:
# pull_request_target checks out the base branch: our script, never the pull request's code.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
sparse-checkout: .github/scripts
persist-credentials: false
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const { clearLabel } = require('./.github/scripts/update.js');
await clearLabel({ github, context, core });