-
Notifications
You must be signed in to change notification settings - Fork 570
314 lines (300 loc) · 10.9 KB
/
publish-release.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
name: Publish Release
on:
workflow_call:
inputs:
slack-channel:
required: false
type: string
default: 'metamask-snaps-deployments'
slack-icon-url:
required: false
type: string
default: 'https://raw.githubusercontent.com/MetaMask/action-npm-publish/main/robo.png'
slack-subteam:
required: false
type: string
slack-username:
required: false
type: string
default: 'MetaMask bot'
secrets:
NPM_TOKEN:
required: true
PUBLISH_PAGES_TOKEN:
required: true
SLACK_WEBHOOK_URL:
required: false
jobs:
get-release-tag:
name: Get release tag
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.get-release-tag.outputs.tag }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- run: yarn install --immutable
- name: Get release tag
id: get-release-tag
run: echo "tag=$(yarn get-release-tag)" >> "$GITHUB_OUTPUT"
shell: bash
publish-release:
name: Publish release
needs: get-release-tag
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- uses: MetaMask/action-publish-release@v3
id: publish-release
with:
npm-tag: ${{ needs.get-release-tag.outputs.tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build
run: |
yarn install --immutable
yarn build
- uses: actions/cache@v4
id: restore-build
with:
path: |
./packages/**/dist
./node_modules
key: ${{ github.sha }}
npm-publish-dry-run:
name: Publish to NPM (dry run)
runs-on: ubuntu-latest
needs: publish-release
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- uses: actions/cache@v4
id: restore-build
with:
path: |
./packages/**/dist
./node_modules
key: ${{ github.sha }}
fail-on-cache-miss: true
- run: npm config set ignore-scripts true
- name: Dry Run Publish
uses: MetaMask/action-npm-publish@v5
with:
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
subteam: ${{ inputs.slack-subteam }}
channel: metamask-snaps-deployments
npm-publish:
name: Publish to NPM
environment: npm-publish
runs-on: ubuntu-latest
needs:
- npm-publish-dry-run
- get-release-tag
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- uses: actions/cache@v4
id: restore-build
with:
path: |
./packages/**/dist
./node_modules
key: ${{ github.sha }}
fail-on-cache-miss: true
- name: Publish ${{ needs.get-release-tag.outputs.tag }} to NPM
uses: MetaMask/action-npm-publish@v5
with:
npm-token: ${{ secrets.NPM_TOKEN }}
npm-tag: ${{ needs.get-release-tag.outputs.tag }}
is-environment-release:
name: Determine whether this release updates the iframe execution environment
runs-on: ubuntu-latest
needs: publish-release
outputs:
IS_ENVIRONMENT_RELEASE: ${{ steps.is-environment-release.outputs.IS_ENVIRONMENT_RELEASE }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
fetch-depth: 2
- name: Check if this is an environment release
id: is-environment-release
shell: bash
run: ./scripts/is-release.sh "packages/snaps-execution-environments/package.json" "${{ github.event.before }}" "IS_ENVIRONMENT_RELEASE"
- name: Set output
if: steps.is-environment-release.outputs.IS_ENVIRONMENT_RELEASE == 'true'
run: echo "IS_ENVIRONMENT_RELEASE=true" >> "$GITHUB_OUTPUT"
configure-environment-publish:
name: Configure iframe execution environment release
runs-on: ubuntu-latest
needs: is-environment-release
if: needs.is-environment-release.outputs.IS_ENVIRONMENT_RELEASE == 'true'
outputs:
version: ${{ steps.version.outputs.VERSION }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- id: version
name: Get release version
shell: bash
run: |
VERSION=$(jq --raw-output '.version' packages/snaps-execution-environments/package.json)
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
- id: name-version
name: Get Slack name and version
shell: bash
if: inputs.slack-subteam != ''
run: |
NAME_VERSION_TEXT=$(jq --raw-output '.name + "@" + .version' packages/snaps-execution-environments/package.json)
NAME_VERSION_TEXT_STRIPPED="${NAME_VERSION_TEXT#@}"
echo "NAME_VERSION=$NAME_VERSION_TEXT_STRIPPED" >> "$GITHUB_OUTPUT"
- id: final-text
name: Get Slack final text
shell: bash
if: inputs.slack-subteam != ''
run: |
DEFAULT_TEXT="\`${{ steps.name-version.outputs.NAME_VERSION }}\` is awaiting deployment :rocket: \n <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/|→ Click here to review deployment>"
SUBTEAM_TEXT="${{ inputs.slack-subteam }}"
FINAL_TEXT="$DEFAULT_TEXT"
if [[ ! "$SUBTEAM_TEXT" == "" ]]; then
FINAL_TEXT="<!subteam^$SUBTEAM_TEXT> $DEFAULT_TEXT"
fi
echo "FINAL_TEXT=$FINAL_TEXT" >> "$GITHUB_OUTPUT"
- name: Post to a Slack channel
if: inputs.slack-subteam != ''
uses: slackapi/slack-github-action@007b2c3c751a190b6f0f040e47ed024deaa72844
with:
payload: |
{
"text": "${{ steps.final-text.outputs.FINAL_TEXT }}",
"icon_url": "${{ inputs.slack-icon-url }}",
"username": "${{ inputs.slack-username }}",
"channel": "#${{ inputs.slack-channel }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
publish-environment:
name: Publish iframe execution environment
permissions:
id-token: write
contents: read
uses: ./.github/workflows/publish-environment.yml
needs:
- is-environment-release
- configure-environment-publish
if: needs.is-environment-release.outputs.IS_ENVIRONMENT_RELEASE == 'true'
with:
destination_dir: ${{ needs.configure-environment-publish.outputs.version }}
is-test-snaps-release:
name: Determine whether this release updates test snaps
runs-on: ubuntu-latest
needs: publish-release
outputs:
IS_TEST_SNAPS_RELEASE: ${{ steps.set-output.outputs.IS_TEST_SNAPS_RELEASE }}
TEST_SNAPS_VERSION: ${{ steps.set-output.outputs.TEST_SNAPS_VERSION }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
fetch-depth: 2
- name: Check if this is a test snaps release
id: is-test-snaps-release
shell: bash
run: ./scripts/is-release.sh "packages/test-snaps/package.json" "${{ github.event.before }}" "IS_TEST_SNAPS_RELEASE"
- name: Set output
id: set-output
if: steps.is-test-snaps-release.outputs.IS_TEST_SNAPS_RELEASE == 'true'
run: |
echo "IS_TEST_SNAPS_RELEASE=true" >> "$GITHUB_OUTPUT"
echo "TEST_SNAPS_VERSION=$(jq --raw-output '.version' packages/test-snaps/package.json)" >> "$GITHUB_OUTPUT"
publish-test-snaps:
name: Publish test snaps
needs: is-test-snaps-release
if: ${{ needs.is-test-snaps-release.outputs.IS_TEST_SNAPS_RELEASE == 'true' }}
permissions:
contents: write
uses: ./.github/workflows/publish-github-pages.yml
with:
build_script: yarn workspace @metamask/test-snaps build
destination_dir: test-snaps/${{ needs.is-test-snaps-release.outputs.TEST_SNAPS_VERSION }}
publish_dir: ./packages/test-snaps/dist
secrets:
PUBLISH_PAGES_TOKEN: ${{ secrets.PUBLISH_PAGES_TOKEN }}
publish-test-snaps-latest:
name: Publish test snaps to `latest` folder
needs: is-test-snaps-release
if: ${{ needs.is-test-snaps-release.outputs.IS_TEST_SNAPS_RELEASE == 'true' }}
permissions:
contents: write
uses: ./.github/workflows/publish-github-pages.yml
with:
build_script: yarn workspace @metamask/test-snaps build
destination_dir: test-snaps/latest
publish_dir: ./packages/test-snaps/dist
secrets:
PUBLISH_PAGES_TOKEN: ${{ secrets.PUBLISH_PAGES_TOKEN }}
is-simulator-release:
name: Determine whether this release updates the simulator
runs-on: ubuntu-latest
needs: publish-release
outputs:
IS_SIMULATOR_RELEASE: ${{ steps.set-output.outputs.IS_SIMULATOR_RELEASE }}
SIMULATOR_VERSION: ${{ steps.set-output.outputs.SIMULATOR_VERSION }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
fetch-depth: 2
- name: Check if this is a simulator release
id: is-simulator-release
shell: bash
run: ./scripts/is-release.sh "packages/snaps-simulator/package.json" "${{ github.event.before }}" "IS_SIMULATOR_RELEASE"
- name: Set output
id: set-output
if: steps.is-simulator-release.outputs.IS_SIMULATOR_RELEASE == 'true'
run: |
echo "IS_SIMULATOR_RELEASE=true" >> "$GITHUB_OUTPUT"
echo "SIMULATOR_VERSION=$(jq --raw-output '.version' packages/snaps-simulator/package.json)" >> "$GITHUB_OUTPUT"
publish-simulator-versioned:
name: Publish Snaps Simulator to `${{ needs.is-simulator-release.outputs.SIMULATOR_VERSION }}` folder
needs: is-simulator-release
if: ${{ needs.is-simulator-release.outputs.IS_SIMULATOR_RELEASE == 'true' }}
permissions:
contents: write
uses: ./.github/workflows/publish-github-pages.yml
with:
build_script: yarn workspace @metamask/snaps-simulator build
publish_dir: ./packages/snaps-simulator/dist/webpack/main
destination_dir: snaps-simulator/${{ needs.is-simulator-release.outputs.SIMULATOR_VERSION }}
secrets:
PUBLISH_PAGES_TOKEN: ${{ secrets.PUBLISH_PAGES_TOKEN }}
publish-simulator-latest:
name: Publish Snaps Simulator to `latest` folder
needs: is-simulator-release
if: ${{ needs.is-simulator-release.outputs.IS_SIMULATOR_RELEASE == 'true' }}
permissions:
contents: write
uses: ./.github/workflows/publish-github-pages.yml
with:
build_script: yarn workspace @metamask/snaps-simulator build
publish_dir: ./packages/snaps-simulator/dist/webpack/main
destination_dir: snaps-simulator/latest
secrets:
PUBLISH_PAGES_TOKEN: ${{ secrets.PUBLISH_PAGES_TOKEN }}