Repository navigation
59 lines (53 loc) · 2.29 KB
/
Copy pathmain-source.yml
File metadata and controls
59 lines (53 loc) · 2.29 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
# A pull request into `main` brings nothing that is not already on `v2/main`
# (#5119). `main` only ever receives a milestone's merge PR, a pure merge of
# `v2/main`; GitHub rulesets cannot restrict a PR's source branch, so this
# check, required by the `main` ruleset, is what does. The rule and why it is
# on the head commit rather than the branch name are in
# `scripts/verify-main-source.mjs`.
#
# On `pull_request_target`, unlike dco.yml: it runs `main`'s copy of this
# workflow and of the script, so a PR cannot edit the guard into passing. That
# is safe here because nothing from the PR runs: the checkout is `main`, and
# the PR's head is only fetched as git objects for `git merge-base` to read.
# Never add a step that checks out, installs or runs the PR's code.
# `edited` is there so retargeting a PR onto `main` runs the check.
on:
pull_request_target:
types: [opened, synchronize, reopened, edited]
branches: [main]
# Read-only, and handed no secret, so this job holds no credential and stays
# outside the SHA-pin rule (`verify:action-pins`).
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
main-source:
timeout-minutes: 5
name: Source is v2/main
runs-on: ubuntu-latest
steps:
# The base branch (`main`), which `pull_request_target` checks out by
# default; never the PR's ref.
- uses: actions/checkout@v6
with:
persist-credentials: false
# The PR's head and `v2/main`, as objects only. A fork PR's head is
# reachable here through `refs/pull/<n>/head`. Full history, so
# `git merge-base` can walk both.
- name: Fetch the PR head and v2/main
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
git fetch --no-tags --unshallow origin \
"+refs/heads/v2/main:refs/remotes/origin/v2/main" \
"+refs/pull/${PR_NUMBER}/head:refs/remotes/pr/head"
- uses: actions/setup-node@v7
with:
node-version: 22
# Node built-ins and git only, so no `npm ci`.
- name: Check the head is already on v2/main
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: node scripts/verify-main-source.mjs --head "$HEAD_SHA"