Repository navigation
194 lines (189 loc) · 7.35 KB
/
Copy pathremain.yml
File metadata and controls
194 lines (189 loc) · 7.35 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: remain
# The whole of remain for a caller (README.md's Workflow section): list the conflicting pull
# requests whose merge needs files rebuilt, rebuild each in its own job, then check and push. The
# push job reads the App's client ID (variable REMAIN_CLIENT_ID) and key (secret
# REMAIN_PRIVATE_KEY) from the caller's `remain` environment, and the caller passes the secret
# too. Each job runs the action from this
# workflow's own commit, so the workflow and the action can't drift apart.
on:
workflow_call:
inputs:
base:
description: 'The branch merged into the pull requests based on it [default: the default branch]'
type: string
default: ''
config:
description: The config file, read from the base branch
type: string
default: .github/remain.json
rust:
description: Install the toolchain rust-toolchain.toml names, for regen commands that run cargo
type: boolean
default: false
node:
description: Install the Node .node-version names, for regen commands that run node or npm
type: boolean
default: false
pnpm:
description: Install pnpm (from package.json's packageManager) and Node, for regen commands that run pnpm
type: boolean
default: false
setup:
description: A shell command the merge jobs run before the regen commands, such as `corepack enable`
type: string
default: ''
merge-timeout:
description: Minutes each merge job may take, regen commands included
type: number
default: 30
secrets:
REMAIN_PRIVATE_KEY:
description: The App's private key. Pass it even though it lives in the `remain` environment, or it arrives empty
required: true
permissions: {}
jobs:
# The pull requests whose merge needs files rebuilt. Runs none of the repository's code.
list:
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
pull-requests: read
outputs:
pulls: ${{ steps.remain.outputs.pulls }}
steps:
# All of history, since remain merges and learns resolutions from it.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: ${{ job.workflow_repository }}
ref: ${{ job.workflow_sha }}
path: .remain
persist-credentials: false
- uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .git/rr-cache
key: remain-rerere-${{ github.run_id }}
restore-keys: remain-rerere-
- id: remain
uses: ./.remain
with:
mode: list
base: ${{ inputs.base }}
config: ${{ inputs.config }}
# Rebuilds one pull request's files with its regen commands, which run its code. One job each, so
# one pull request's code can't touch another's files. No secrets here, and caches restore only.
merge:
needs: list
if: needs.list.outputs.pulls != '[]'
strategy:
fail-fast: false
matrix:
pull: ${{ fromJSON(needs.list.outputs.pulls) }}
runs-on: ubuntu-latest
timeout-minutes: ${{ inputs.merge-timeout }}
permissions:
contents: read
pull-requests: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: ${{ job.workflow_repository }}
ref: ${{ job.workflow_sha }}
path: .remain
persist-credentials: false
- if: inputs.rust
run: rustup toolchain install
- if: inputs.rust
uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
save-if: false
- if: inputs.pnpm
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
- if: inputs.node || inputs.pnpm
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: .node-version
package-manager-cache: false
# The caller's own command, from its default branch. Through the environment, so no part of it
# is spliced into this script.
- if: inputs.setup != ''
run: bash -euo pipefail -c "$SETUP"
env:
SETUP: ${{ inputs.setup }}
- uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .git/rr-cache
key: remain-rerere-${{ github.run_id }}
restore-keys: remain-rerere-
- uses: ./.remain
with:
mode: merge
pull: ${{ matrix.pull }}
base: ${{ inputs.base }}
config: ${{ inputs.config }}
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: remain-plans-${{ github.run_attempt }}-${{ matrix.pull }}
path: remain-plans
retention-days: 1
# Checks the merge jobs' work without running any of the repository's code, then pushes. It
# restores no cache: a merge job could have written one, so it learns its resolutions itself.
push:
needs: [list, merge]
if: ${{ !cancelled() && needs.list.result == 'success' }}
runs-on: ubuntu-latest
timeout-minutes: 15
environment: remain
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: ${{ job.workflow_repository }}
ref: ${{ job.workflow_sha }}
path: .remain
persist-credentials: false
- if: needs.list.outputs.pulls != '[]'
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: remain-plans-${{ github.run_attempt }}-*
path: remain-plans
merge-multiple: true
- id: app
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
client-id: ${{ vars.REMAIN_CLIENT_ID }}
private-key: ${{ secrets.REMAIN_PRIVATE_KEY }}
permission-contents: write
permission-workflows: write
- uses: ./.remain
with:
mode: push
app-token: ${{ steps.app.outputs.token }}
app-slug: ${{ steps.app.outputs.app-slug }}
base: ${{ inputs.base }}
config: ${{ inputs.config }}
# What it learned, for the next run's list and merge jobs.
- uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .git/rr-cache
key: remain-rerere-push-${{ github.run_id }}-${{ github.run_attempt }}
# The pull requests waiting on a re-approval. A second call in the same run replaces it.
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: remain-digest
path: remain-digest
overwrite: true