forked from block-wallet/extension
-
Notifications
You must be signed in to change notification settings - Fork 0
418 lines (364 loc) · 15 KB
/
build.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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
name: Release (manual)
on:
workflow_dispatch:
inputs:
extension-version:
description: 'Extension version to be released'
required: true
release-notes:
description: 'Release notes of the extension'
required: true
pre-release:
type: boolean
required: false
default: false
description: Is a pre-release?
env:
RELEASE_BRANCH: release/${{ github.event.inputs.extension-version }}
GH_ACCESS_TOKEN: ${{ secrets.USER_PAT }}:${{ secrets.PAT }}
EXTENSION_NAME: block-wallet-${{ github.event.inputs.extension-version }}
ARTIFACTS_FOLDER: artifacts
S3_PATH: s3://releases.blockwallet.io/extension
TARGET_BRANCH: master
CYPRESS_CACHE_FOLDER: cypress/cache
jobs:
validation:
runs-on: ubuntu-latest
steps:
- name: Print user input
run: |
echo -e extension-version: ${{ github.event.inputs.extension-version }}
echo -e pre-release: ${{ github.event.inputs.pre-release }}
echo -e release-notes: ${{ github.event.inputs.release-notes }}
- name: Parse and validate extension version string
id: semver_extension
uses: booxmedialtd/ws-action-parse-semver@v1
with:
input_string: ${{ github.event.inputs.extension-version }}
version_extractor_regex: 'v(.*)$'
- name: Validate release notes is a valid JSON
env:
DATA: '${{ github.event.inputs.release-notes }}'
READ_ONLY: 1
run: |
wget https://raw.githubusercontent.com/block-wallet/release-helpers/main/validate_release_notes_and_convert_to_markdown.py -O validate_release_notes_and_convert_to_markdown.py
python3 validate_release_notes_and_convert_to_markdown.py
- name: Validate the extension version
run: |
if [[ "${{ steps.semver_extension.outputs.prerelease }}" != "" || "${{ steps.semver_extension.outputs.build }}" != "" ]]
then
echo "The release must follow the notation MAJOR.MINOR.PATCH without pre-release or build metadata."
exit 1
fi
if: ${{ github.event.inputs.pre-release == 'false' }}
- name: Install semver package
run: |
wget -O /usr/local/bin/semver \https://raw.githubusercontent.com/block-wallet/release-helpers/main/semver
chmod +x /usr/local/bin/semver
- name: Check out code
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
ref: ${{ env.GITHUB_REF_NAME }}
- name: Compare release version with the latest tag
id: tag_comparison
run: |
git fetch --all --tags
latest_tag=$(git tag -l | tail -n 1)
if [[ -z $latest_tag ]]
then
exit 0
fi
result=$(semver compare ${{github.event.inputs.extension-version}} $latest_tag)
if [[ "$result" != "1" ]]
then
echo "The proposed tag for the release \"v${{ steps.semver_extension.outputs.fullversion }}\" is not greater than the latest one \"$latest_tag\""
exit 1
fi
build:
needs: validation
runs-on: ubuntu-latest
outputs:
version_without_preffix: ${{ steps.remove_preffix.outputs.version }}
steps:
- name: Check out code
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
ref: ${{ env.TARGET_BRANCH }}
- name: Remove preffix from the extension version
id: remove_preffix
run: |
updated_version=${{ github.event.inputs.extension-version }}
echo $updated_version
updated_version=$(echo ${updated_version:1})
echo "::set-output name=version::$updated_version"
- name: Initialize mandatory git config
run: |
git config --global user.name release_process
git config --global user.email release_process@blockwallet.io
git config --global url.https://$GH_ACCESS_TOKEN@github.com/.insteadOf https://github.com/
- name: Create release branch
run: |
existed_in_remote=$(git ls-remote --heads origin ${RELEASE_BRANCH})
if [[ ${existed_in_remote} ]]; then
echo "Deleting the branch \"$RELEASE_BRANCH\" to continue with the release"
git push origin --delete $RELEASE_BRANCH
fi
git checkout -b $RELEASE_BRANCH
git push -u origin $RELEASE_BRANCH
- name: Update new version
env:
VERSION: ${{ steps.remove_preffix.outputs.version }}
run: |
wget https://raw.githubusercontent.com/block-wallet/release-helpers/main/update_file.py -O update_file.py
FILE=package.json python3 update_file.py
FILE=public/manifest.json python3 update_file.py
- name: Update release notes
env:
VERSION: ${{ steps.remove_preffix.outputs.version }}
DATA: '${{ github.event.inputs.release-notes }}'
run: |
FILE=release-notes.json python3 update_file.py
rm update_file.py
- name: Commit package.json, manifest.json and release-notes.json
id: version_commit
run: |
git add package.json release-notes.json public/manifest.json
git commit --message "chore: update files with the new version ${{ github.event.inputs.extension-version }} and also add the new release notes"
git push origin $RELEASE_BRANCH
- name: Install node
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
registry-url: https://npm.pkg.github.com
- name: Install yarn
run: |
npm install --global yarn
- name: Dependency UI cache
uses: actions/cache@v3
with:
path: 'packages/ui/node_modules'
key: ${{ runner.os }}-modules-v1-${{ hashFiles('packages/ui/yarn.lock') }}
- name: Dependency Background cache
uses: actions/cache@v3
with:
path: 'packages/background/node_modules'
key: ${{ runner.os }}-modules-v1-${{ hashFiles('packages/background/yarn.lock') }}
- name: Dependency Provider cache
uses: actions/cache@v3
with:
path: 'packages/provider/node_modules'
key: ${{ runner.os }}-modules-v1-${{ hashFiles('packages/provider/yarn.lock') }}
- name: Install packages dependencies
run: |
make install/ci
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
- name: Build extension
env:
CI: false
run: |
make build/prod
- name: Save extension folder
uses: actions/upload-artifact@v3
with:
name: blockwallet-extension
if-no-files-found: error
path: dist
#tests:
# needs: build
# container: cypress/browsers:node16.16.0-chrome105-ff99-edge
# runs-on: ubuntu-latest
# env:
# WIDTH: 357
# HEIGHT: 610
# DBUS_SESSION_BUS_ADDRESS: /dev/null
# steps:
# - name: Checkout e2e repository
# uses: actions/checkout@v3
# with:
# repository: block-wallet/e2e-tests
# ref: refs/heads/main
# token: ${{ secrets.PAT }}
# - name: Install node
# uses: actions/setup-node@v3
# with:
# node-version-file: .nvmrc
# - name: Install yarn
# run: |
# npm install --global yarn
# - name: Cache e2e dependencies
# id: cache-cypress
# uses: actions/cache@v3
# with:
# path: |
# node_modules
# cypress/cache
# key: ${{ runner.os }}-cypress-v1-${{ hashFiles('yarn.lock') }}
# - name: Download the extension
# uses: actions/download-artifact@v3
# with:
# name: blockwallet-extension
# path: blockwallet-extension
# - name: Install e2e dependencies
# run: |
# yarn install --prefer-offline --frozen-lockfile --network-concurrency 1
# - name: UI Tests - Chrome
# run: |
# yarn run test:e2e
# env:
# ETHERSCAN_KEY: ${{ secrets.ETHERSCAN_KEY }}
# GITHUB_TOKEN: ${{ secrets.PAT }}
# TEST_TAGS: puppeteer,extension
# - name: Take the release notes screenshot
# run: |
# yarn run test:e2e
# env:
# EXTENSION_VERSION: ${{ needs.build.outputs.version_without_preffix }}
# TEST_TAGS: release-notes
# BROWSER_WIDTH: ${{ env.WIDTH }}
# BROWSER_HEIGHT: ${{ env.HEIGHT }}
# - name: Install ImageMagick (needed for convert)
# run: |
# apt update && apt install -y imagemagick --fix-missing
# - name: Cut the screenshot
# run: |
# convert screenshots/release-notes-${{ needs.build.outputs.version_without_preffix }}.png -crop ${{ env.WIDTH }}x${{ env.HEIGHT }}+0+0 $EXTENSION_NAME.png
# - name: Save screenshot of release notes
# uses: actions/upload-artifact@v3
# with:
# name: screenshot
# if-no-files-found: error
# path: ${{ env.EXTENSION_NAME }}.png
package:
needs: build
runs-on: ubuntu-latest
steps:
- name: Delete artifacts folders
run: |
rm -rf screenshot
rm -rf blockwallet-extension
- name: Download the extension built folder
uses: actions/download-artifact@v3
with:
name: blockwallet-extension
path: blockwallet-extension
#- name: Download the extension screenshot (release notes)
# uses: actions/download-artifact@v3
# with:
# name: screenshot
# path: screenshot
- name: Zip extension
id: zip
run: |
mkdir -p $ARTIFACTS_FOLDER
mv blockwallet-extension dist
zip -r -D $ARTIFACTS_FOLDER/$EXTENSION_NAME.zip dist/
- name: Calculate SHA of the extension
id: sha
run: |
cd $ARTIFACTS_FOLDER
sha256sum $EXTENSION_NAME.zip > $EXTENSION_NAME.checksum
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_RELEASE_BUCKET }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_RELEASE_BUCKET }}
aws-region: eu-central-1
- name: Upload to S3
run: |
aws s3 cp --recursive $ARTIFACTS_FOLDER $S3_PATH
# aws s3 cp screenshot/$EXTENSION_NAME.png $S3_PATH/$EXTENSION_NAME.png
- name: Upload version and notes to S3
env:
DATA: '${{ github.event.inputs.release-notes }}'
run: |
echo "{" > version.json
echo "\"extension\": \"${{ github.event.inputs.extension-version }}\"," >> version.json
echo "\"prerelease\": \"${{ github.event.inputs.pre-release }}\"" >> version.json
echo "}" >> version.json
aws s3 cp version.json $S3_PATH/version.json
wget https://raw.githubusercontent.com/block-wallet/release-helpers/main/validate_release_notes_and_convert_to_markdown.py -O validate_release_notes_and_convert_to_markdown.py
python3 validate_release_notes_and_convert_to_markdown.py
aws s3 cp notes.md $S3_PATH/notes.md
pull_request:
outputs:
pr_url: ${{ steps.create_pull_request.outputs.pr_url }}
needs: package
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
- name: Initialize mandatory git config
run: |
git config --global user.name release_process
git config --global user.email release_process@blockwallet.io
git config --global url.https://$GH_ACCESS_TOKEN@github.com/.insteadOf https://github.com/
- name: Create Pull Request
id: create_pull_request
env:
GH_TOKEN: ${{ secrets.PAT }}
run: |
s3_url=$(echo "${S3_PATH/s3/https}")
pr_title="[Automated] Extension release ${{ github.event.inputs.extension-version }}"
pr_body=$(echo -e "# PR for release ${{ github.event.inputs.extension-version }}\n\n## Type of change :writing_hand:\n\nClick the correct/s option/s\n\n- [ ] Bug fix (non-breaking change which fixes an issue)\n- [ ] New feature (non-breaking change which adds functionality)\n- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)\n- [ ] This change requires a documentation update\n\n## Manual tests :test_tube:\n\n- [ ] I run the tests and they were succesful\n\n## Artifacts :space_invader:\n\n - [Extension zip]($s3_url/${{ env.EXTENSION_NAME }}.zip)\n - [SHA256 checksum]($s3_url/${{ env.EXTENSION_NAME }}.checksum)\n\n")
pr_reviewer="block-wallet/releasereviewers"
pr_assignee="leablock"
pr_label="automated,release"
gh label create --force "automated" --description "PR made by an automation" --color "bcf5db"
gh label create --force "release" --description "Extension release" --color "0e8a16"
gh pr create \
--base "$TARGET_BRANCH" \
--head "$RELEASE_BRANCH" \
--title "$pr_title" \
--label "$pr_label" \
--reviewer "$pr_reviewer" \
--body "$pr_body" \
--assignee "$pr_assignee" \
--no-maintainer-edit \
--draft
sleep 5
url=$(gh pr list --state open --label "$pr_label" --base "$TARGET_BRANCH" --head "$RELEASE_BRANCH" --json url | jq ".[0].url" | tr -d '"')
echo "::set-output name=pr_url::$url"
notify:
if: success()
needs: [validation, build, package, pull_request]
runs-on: ubuntu-latest
steps:
- name: Slack notification - Ready to release
uses: 8398a7/action-slack@v3
with:
status: custom
fields: repo,workflow
github_token: ${{ secrets.PAT }}
custom_payload: |
{
"text": "*Release (manual)* for ${{ github.event.inputs.extension-version }} finished.",
"attachments": [
{
"color": "good",
"pretext": "The pull request was created. After reviewing it, please merge it to continue the release process that will launch *Release (automated)*. CC: <@U01H6J242BY>, <@U021GBLL00Z>",
"author_name": "GitHub Pull Request ${{ github.event.inputs.extension-version }}",
"author_link": "${{ needs.pull_request.outputs.pr_url }}",
"title": "GitHub Pull Request for the release ${{ github.event.inputs.extension-version }} created as draft"
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_BLOCKWALLET_RELEASES }}
error:
if: failure()
needs: [validation, build, package, pull_request, notify]
runs-on: ubuntu-latest
steps:
- name: Slack notification - CI status
uses: 8398a7/action-slack@v3
with:
status: failure
fields: workflow
github_token: ${{ secrets.PAT }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_ALERTS_RELEASES }}