-
Notifications
You must be signed in to change notification settings - Fork 557
231 lines (223 loc) · 7.72 KB
/
update-pull-request.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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
name: Update pull request
on:
issue_comment:
types:
- created
jobs:
is-fork-pull-request:
name: Determine whether this issue comment was on a pull request from a fork
if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '@metamaskbot update-pr') }}
runs-on: ubuntu-latest
outputs:
IS_FORK: ${{ steps.is-fork.outputs.IS_FORK }}
steps:
- uses: actions/checkout@v4
- name: Determine whether this PR is from a fork
id: is-fork
run: echo "IS_FORK=$(gh pr view --json isCrossRepository --jq '.isCrossRepository' "${PR_NUMBER}" )" >> "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
react-to-comment:
name: React to the comment
runs-on: ubuntu-latest
needs: is-fork-pull-request
# Early exit if this is a fork, since later steps are skipped for forks.
if: ${{ needs.is-fork-pull-request.outputs.IS_FORK == 'false' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: React to the comment
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${REPO}/issues/comments/${COMMENT_ID}/reactions" \
-f content='+1'
env:
COMMENT_ID: ${{ github.event.comment.id }}
GITHUB_TOKEN: ${{ secrets.PULL_REQUEST_UPDATE_TOKEN }}
REPO: ${{ github.repository }}
prepare:
name: Prepare dependencies
runs-on: ubuntu-latest
needs: is-fork-pull-request
# Early exit if this is a fork, since later steps are skipped for forks.
if: ${{ needs.is-fork-pull-request.outputs.IS_FORK == 'false' }}
outputs:
COMMIT_SHA: ${{ steps.commit-sha.outputs.COMMIT_SHA }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout pull request
run: gh pr checkout "${PR_NUMBER}"
env:
GITHUB_TOKEN: ${{ secrets.PULL_REQUEST_UPDATE_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Install Yarn dependencies
run: yarn --immutable
- name: Get commit SHA
id: commit-sha
run: echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
dedupe-yarn-lock:
name: Deduplicate yarn.lock
runs-on: ubuntu-latest
needs: prepare
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout pull request
run: gh pr checkout "${PR_NUMBER}"
env:
GITHUB_TOKEN: ${{ secrets.PULL_REQUEST_UPDATE_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Install dependencies from cache
run: yarn --immutable --immutable-cache
- name: Deduplicate yarn.lock
run: yarn dedupe
- name: Cache yarn.lock
uses: actions/cache/save@v4
with:
path: yarn.lock
key: cache-yarn-lock-${{ needs.prepare.outputs.COMMIT_SHA }}
regenerate-lavamoat-policies:
name: Regenerate LavaMoat policies
runs-on: ubuntu-latest
needs:
- prepare
- dedupe-yarn-lock
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout pull request
run: gh pr checkout "${PR_NUMBER}"
env:
GITHUB_TOKEN: ${{ secrets.PULL_REQUEST_UPDATE_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
- name: Restore yarn.lock
uses: actions/cache/restore@v4
with:
path: yarn.lock
key: cache-yarn-lock-${{ needs.prepare.outputs.COMMIT_SHA }}
fail-on-cache-miss: true
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Install dependencies from cache
run: yarn --immutable
- name: Regenerate LavaMoat policies
run: yarn build:lavamoat:policy
- name: Cache LavaMoat policies
uses: actions/cache/save@v4
with:
path: packages/snaps-execution-environments/lavamoat
key: cache-lavamoat-${{ needs.prepare.outputs.COMMIT_SHA }}
update-examples:
name: Update examples
runs-on: ubuntu-latest
needs:
- prepare
- dedupe-yarn-lock
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout pull request
run: gh pr checkout "${PR_NUMBER}"
env:
GITHUB_TOKEN: ${{ secrets.PULL_REQUEST_UPDATE_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
- name: Restore yarn.lock
uses: actions/cache/restore@v4
with:
path: yarn.lock
key: cache-yarn-lock-${{ needs.prepare.outputs.COMMIT_SHA }}
fail-on-cache-miss: true
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Install dependencies from cache
run: yarn --immutable
- name: Build dependencies
run: |
yarn build:ci
- name: Update examples
run: yarn build:examples
- name: Cache examples
uses: actions/cache/save@v4
with:
path: packages/examples/packages
key: cache-examples-${{ needs.prepare.outputs.COMMIT_SHA }}
commit-result:
name: Commit result
runs-on: ubuntu-latest
needs:
- prepare
- dedupe-yarn-lock
- regenerate-lavamoat-policies
- update-examples
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# Use PAT to ensure that the commit later can trigger status check
# workflows.
token: ${{ secrets.PULL_REQUEST_UPDATE_TOKEN }}
- name: Checkout pull request
run: gh pr checkout "${PR_NUMBER}"
env:
GITHUB_TOKEN: ${{ secrets.PULL_REQUEST_UPDATE_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
- name: Configure Git
run: |
git config --global user.name 'MetaMask Bot'
git config --global user.email '[email protected]'
- name: Get commit SHA
id: commit-sha
run: echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
- name: Restore yarn.lock
uses: actions/cache/restore@v4
with:
path: yarn.lock
key: cache-yarn-lock-${{ needs.prepare.outputs.COMMIT_SHA }}
fail-on-cache-miss: true
- name: Commit yarn.lock
run: |
git add yarn.lock
git commit -m "Deduplicate yarn.lock" || true
- name: Restore LavaMoat policies
uses: actions/cache/restore@v4
with:
path: packages/snaps-execution-environments/lavamoat
key: cache-lavamoat-${{ needs.prepare.outputs.COMMIT_SHA }}
fail-on-cache-miss: true
- name: Commit LavaMoat policies
run: |
git add packages/snaps-execution-environments/lavamoat
git commit -m "Update LavaMoat policies" || true
- name: Restore examples
uses: actions/cache/restore@v4
with:
path: packages/examples/packages
key: cache-examples-${{ needs.prepare.outputs.COMMIT_SHA }}
fail-on-cache-miss: true
- name: Commit examples
run: |
git add packages/examples/packages
git commit -m "Update example snaps" || true
- name: Push changes
run: git push