Repository navigation
96 lines (89 loc) · 3.68 KB
/
Copy pathfast-forward.yml
File metadata and controls
96 lines (89 loc) · 3.68 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: Fast-forward on approval
on:
pull_request_review:
types: [submitted]
permissions:
contents: read
jobs:
# Separate from the privileged job so that approvals from people without write access never
# take (and cancel) the per-target concurrency slot of a maintainer's pending run.
gate:
name: Check approver
if: |
github.event.review.state == 'approved' &&
github.event.pull_request.head.repo.full_name == github.repository &&
(
(github.event.pull_request.head.ref == 'develop' && github.event.pull_request.base.ref == 'main') ||
(github.event.pull_request.head.ref == 'next' && github.event.pull_request.base.ref == 'develop') ||
(github.event.pull_request.head.ref == 'sync/main-into-develop' && github.event.pull_request.base.ref == 'develop') ||
(github.event.pull_request.head.ref == 'sync/develop-into-next' && github.event.pull_request.base.ref == 'next')
)
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
outputs:
allowed: ${{ steps.reviewer.outputs.allowed }}
steps:
# Any GitHub user can submit an approving review on a public repo.
- id: reviewer
name: Check reviewer permission
env:
GH_TOKEN: ${{ github.token }}
REVIEWER: ${{ github.event.review.user.login }}
run: |
role=$(gh api "repos/${GITHUB_REPOSITORY}/collaborators/${REVIEWER}/permission" --jq '.permission')
case "${role}" in
admin | write)
echo "allowed=true" >> "$GITHUB_OUTPUT"
;;
*)
echo "allowed=false" >> "$GITHUB_OUTPUT"
echo "::notice::Skipping fast-forward: ${REVIEWER} lacks write access (${role})"
;;
esac
fast-forward:
name: Fast-forward ${{ github.event.pull_request.base.ref }} to ${{ github.event.pull_request.head.ref }}
needs: gate
if: needs.gate.outputs.allowed == 'true'
# Held per target so an unrelated review run never replaces a pending fast-forward.
concurrency:
group: fast-forward-${{ github.event.pull_request.base.ref }}
cancel-in-progress: false
runs-on: ubuntu-latest
timeout-minutes: 15
# `actions: write` lets the job token dispatch `Sync branches` when `next` moved and conflicts with a sync.
permissions:
contents: read
checks: read
statuses: read
pull-requests: write
actions: write
steps:
- id: app-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
client-id: ${{ vars.GH_APP_CLIENT_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
permission-contents: write
permission-workflows: write
# The script always comes from the default branch, never from the pull request head.
- uses: useblacksmith/checkout@6fd481652155169ed4d2f25ebaf97464f685175f # v1
with:
ref: ${{ github.event.repository.default_branch }}
fetch-depth: 0
persist-credentials: true
token: ${{ steps.app-token.outputs.token }}
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version-file: .bun-version
- name: Fast-forward
env:
GH_TOKEN: ${{ github.token }}
REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REVIEW_COMMIT_ID: ${{ github.event.review.commit_id }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
bun .github/scripts/fast-forward.ts