-
Notifications
You must be signed in to change notification settings - Fork 119
321 lines (305 loc) · 13.3 KB
/
website.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
name: Website
on:
push:
branches:
- main
paths:
# test-e2e depends on api running too
- 'packages/api/**'
- 'packages/website/**'
- '.github/workflows/website.yml'
- 'package-lock.json'
pull_request:
paths:
- 'packages/website/**'
- '.github/workflows/website.yml'
- 'package-lock.json'
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
type: choice
options:
- info
- warning
- debug
add_playwright_report_to_web3_storage:
description: Whether to add add_playwright_report_to_web3_storage to web3.storage (publicly)
required: true
type: boolean
default: true
force_release:
description: Whether to run the release job no matter what
required: true
type: boolean
default: false
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- uses: bahmutov/npm-install@v1
- run: npm run lint -w packages/website
test-e2e:
if: false
name: "Test e2e - ${{ matrix.browser }}"
strategy:
fail-fast: false
matrix:
browser:
- firefox
- chromium
os:
- ubuntu-latest
node-version:
- 16
test_results_path:
# corresponds to playwright invocation/configuration
- packages/website/test-results
runs-on: ${{ matrix.os }}
outputs:
playwright-report: ${{ steps.create_output_playwright_reporter.outputs.url }}
playwright-report-cid: ${{ steps.create_output_playwright_reporter_cid.outputs.cid }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- uses: bahmutov/npm-install@v1
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
# sed removes tempalted env vars that we want set from actual env and not env file
- name: write .env
run: npm -w '@web3-storage/website' run ci:envfile --silent > .env
env:
ENVFILE_WITHOUT: 'MAGIC_SECRET_KEY,NEXT_PUBLIC_MAGIC,NEXT_PUBLIC_MAGIC_TESTMODE_ENABLED'
- name: load db schema
run: |
npm run start -w packages/db
npm run load-schema -w packages/db
npm run stop -w packages/db
- run: npx playwright install --with-deps ${{ matrix.browser }}
working-directory: packages/website
# run e2e tests
- id: website_test_e2e
continue-on-error: true # when this fails, we still want to do some cleanup
run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- node -r dotenv/config $(which npm) run -w @web3-storage/website test:e2e -- --project=${{ matrix.browser }} --reporter=html
env:
# Timeout is in milliseconds
PLAYWRIGHT_TIMEOUT: 120000
NEXT_PUBLIC_MAGIC: ${{ secrets.STAGING_MAGIC_PUBLIC_KEY }}
MAGIC_SECRET_KEY: ${{ secrets.STAGING_MAGIC_SECRET_KEY }}
NEXT_PUBLIC_MAGIC_TESTMODE_ENABLED: "true"
API_MINIFLARE_FLAGS: '--binding NEXT_PUBLIC_MAGIC_TESTMODE_ENABLED=$NEXT_PUBLIC_MAGIC_TESTMODE_ENABLED --binding MAGIC_SECRET_KEY=$MAGIC_SECRET_KEY --binding NEXT_PUBLIC_MAGIC=$NEXT_PUBLIC_MAGIC'
- name: Check for website playwright-report
id: check_website_playwright_report
uses: andstor/file-existence-action@v1
with:
files: packages/website/playwright-report
# if playwright-report exists, upload it as artifact
- name: upload playwright-report artifact
if: steps.check_website_playwright_report.outputs.files_exists == 'true'
uses: actions/upload-artifact@v1
with:
name: ${{ matrix.browser }}-${{ matrix.os }}-playwright-report
path: packages/website/playwright-report
# add playwright-report to web3.storage
- name: add playwright-report to web3.storage
if: ${{ inputs.add_playwright_report_to_web3_storage }} && steps.check_website_playwright_report.outputs.files_exists == 'true'
uses: web3-storage/add-to-web3@v2
id: add_playwright_report_to_web3_storage
with:
path_to_add: packages/website/playwright-report
web3_token: ${{ secrets.WEB3_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# output playwright-report on web3.storage cid
- id: create_output_playwright_reporter_cid
if: steps.add_playwright_report_to_web3_storage.outputs.cid
run: echo "::set-output name=cid::${{ steps.add_playwright_report_to_web3_storage.outputs.cid }}"
# log playwright-report on web3.storage cid
- name: log playwright-report on web3.storage cid
if: steps.add_playwright_report_to_web3_storage.outputs.cid
run: |
echo cid: ${{ steps.create_output_playwright_reporter_cid.outputs.cid }}
# output playwright-report on web3.storage url
- id: create_output_playwright_reporter_url
if: steps.add_playwright_report_to_web3_storage.outputs.cid
run: echo "::set-output name=url::https://w3s.link/ipfs/${{ steps.add_playwright_report_to_web3_storage.outputs.cid }}"
# log playwright-report on web3.storage url
- name: log playwright-report on web3.storage url
if: steps.create_output_playwright_reporter_url.outputs.url
run: |
echo url: ${{ steps.create_output_playwright_reporter_url.outputs.url }}
- name: add url to GITHUB_STEP_SUMMARY
if: steps.create_output_playwright_reporter_url.outputs.url
run: |
echo "
### playwright-report-${{ matrix.browser }}-${{ matrix.os }}
* url: ${{ steps.create_output_playwright_reporter_url.outputs.url }}
* cid: ${{ steps.create_output_playwright_reporter_cid.outputs.cid }}
" >> $GITHUB_STEP_SUMMARY
# if test-results, upload as artifact
- name: Check for website test results
id: check_website_test_results
uses: andstor/file-existence-action@v1
with:
files: ${{ matrix.test_results_path }}
- name: upload test-results artifact
if: steps.check_website_test_results.outputs.files_exists == 'true'
uses: actions/upload-artifact@v1
with:
name: ${{ matrix.browser }}-${{ matrix.os }}-test-results
path: ${{ matrix.test_results_path }}
- name: fail if test:e2e didn't succeed
if: steps.website_test_e2e.outcome != 'success'
uses: actions/github-script@v3
with:
script: |
core.setFailed('e2e tests did not succeed')
preview:
name: Preview
environment:
name: ${{ (github.ref_name == 'main') && 'staging' || format('preview-{0}', github.ref_name) }}
url: ${{ (github.ref_name == 'main') && 'https://staging.web3.storage/' || steps.cloudflare_url.outputs.stdout }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- uses: bahmutov/npm-install@v1
- run: npm run build -w packages/client
- name: build website
run: |
echo NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_ANNOUNCEMENT_START="$NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_ANNOUNCEMENT_START"
npm run build -w packages/website
env:
NEXT_PUBLIC_ENV: staging
NEXT_PUBLIC_API: https://api-staging.web3.storage
NEXT_PUBLIC_MAGIC: ${{ secrets.STAGING_MAGIC_PUBLIC_KEY }}
NEXT_PUBLIC_COUNTLY_URL: ${{ secrets.COUNTLY_URL }}
NEXT_PUBLIC_COUNTLY_KEY: ${{ secrets.COUNTLY_KEY }}
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: ${{ secrets.TESTING_STRIPE_PUBLISHABLE_KEY }}
NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_ANNOUNCEMENT_START: ${{ vars.NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_ANNOUNCEMENT_START }}
NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_START: ${{ vars.NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_START }}
NEXT_PUBLIC_W3UP_LAUNCH_LIMITED_AVAILABILITY_START: ${{ vars.NEXT_PUBLIC_W3UP_LAUNCH_LIMITED_AVAILABILITY_START }}
DID_DOCUMENT_ID: ${{ secrets.STAGING_DID_DOCUMENT_ID }}
DID_DOCUMENT_PRIMARY_DID_KEY: ${{ secrets.STAGING_DID_DOCUMENT_PRIMARY_DID_KEY }}
- name: Add to web3.storage
uses: web3-storage/add-to-web3@v2
id: ipfs
with:
path_to_add: packages/website/out
web3_token: ${{ secrets.WEB3_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update IPFS DNSLink https://staging.web3.storage
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: npx dnslink-cloudflare --record staging --domain web3.storage --link /ipfs/${{ steps.ipfs.outputs.cid }}
env:
CF_API_TOKEN: ${{ secrets.CF_TOKEN }}
- name: Deploy preview build to Cloudflare Pages
uses: mathiasvr/[email protected]
id: cloudflare
with:
run: npx wrangler pages publish --project-name web3-storage-staging --branch "$GITHUB_REF_NAME" --commit-hash "$GITHUB_SHA" ./packages/website/out
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
- name: Find Cloudflare Pages preview URL
uses: mathiasvr/[email protected]
id: cloudflare_url
with:
run: egrep -o 'https?://[^ ]+' <(echo "${{ steps.cloudflare.outputs.stdout }}")
- name: Find Current Pull Request
uses: jwalton/[email protected]
id: finder
- name: Update Preview URLs PR Comment
uses: marocchino/[email protected]
with:
number: ${{ steps.finder.outputs.pr }}
message: |
### Website preview 🔗✨
- 🙂 https://w3s.link/ipfs/${{ steps.ipfs.outputs.cid }}
- ⛅️ ${{ steps.cloudflare_url.outputs.stdout }}
[build log](/${{ github.repository }}/actions/runs/${{ github.run_id }})
- name: Add Preview URLs as Job Summary
run: |
echo "
### Website preview 🔗✨
- 🙂 https://w3s.link/ipfs/${{ steps.ipfs.outputs.cid }}
- ⛅️ ${{ steps.cloudflare_url.outputs.stdout }}
[build log](/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> $GITHUB_STEP_SUMMARY
changelog:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
name: Changelog
runs-on: ubuntu-latest
outputs:
releases_created: ${{ steps.tag-release.outputs.releases_created }}
steps:
- uses: GoogleCloudPlatform/release-please-action@v3
id: tag-release
with:
path: packages/website
token: ${{ secrets.GITHUB_TOKEN }}
release-type: node
monorepo-tags: true
package-name: website
changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Other Changes","hidden":false}]'
release:
if: (github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.changelog.outputs.releases_created) || inputs.force_release
name: Release
runs-on: ubuntu-latest
environment:
name: production
url: https://web3.storage
needs:
- test
# - test-e2e
- preview
- changelog
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16'
registry-url: https://registry.npmjs.org/
- uses: bahmutov/npm-install@v1
- run: npm run build -w packages/client
- run: npm run build -w packages/website
env:
NEXT_PUBLIC_ENV: production
NEXT_PUBLIC_API: https://api.web3.storage
NEXT_PUBLIC_MAGIC: ${{ secrets.PROD_MAGIC_PUBLIC_KEY }}
NEXT_PUBLIC_COUNTLY_URL: ${{ secrets.COUNTLY_URL }}
NEXT_PUBLIC_COUNTLY_KEY: ${{ secrets.COUNTLY_KEY }}
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: ${{ secrets.STRIPE_PUBLISHABLE_KEY }}
NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_ANNOUNCEMENT_START: ${{ vars.NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_ANNOUNCEMENT_START }}
NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_START: ${{ vars.NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_START }}
NEXT_PUBLIC_W3UP_LAUNCH_LIMITED_AVAILABILITY_START: ${{ vars.NEXT_PUBLIC_W3UP_LAUNCH_LIMITED_AVAILABILITY_START }}
DID_DOCUMENT_ID: ${{ secrets.PRODUCTION_DID_DOCUMENT_ID }}
DID_DOCUMENT_PRIMARY_DID_KEY: ${{ secrets.PRODUCTION_DID_DOCUMENT_PRIMARY_DID_KEY }}
- name: Add to web3.storage
uses: web3-storage/add-to-web3@v2
id: ipfs
with:
path_to_add: packages/website/out
web3_token: ${{ secrets.WEB3_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update IPFS DNSLink https://web3.storage
run: npx dnslink-cloudflare --record _dnslink --domain web3.storage --link /ipfs/${{ steps.ipfs.outputs.cid }}
env:
CF_API_TOKEN: ${{ secrets.CF_TOKEN }}
- name: Deploy https://web3.storage to Cloudflare Pages
run: npx wrangler pages publish --project-name web3-storage --branch "main" --commit-hash "$GITHUB_SHA" ./packages/website/out
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_TOKEN}}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}