-
Notifications
You must be signed in to change notification settings - Fork 5
262 lines (225 loc) · 11.6 KB
/
main.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
name: Main workflow
# The event triggers are configured as following:
# - on branch main, trigger the workflow on every push to trigger production checks and deployment
# - on any pull request, trigger the workflow
# This is to avoid running the workflow twice on pull requests.
on:
push:
branches:
- main
merge_group:
branches: [main]
pull_request:
repository_dispatch:
types: [manual-build-and-deploy]
jobs:
build_deploy_test:
runs-on: ubuntu-latest
# https://github.com/bahmutov/cypress-gh-action-split-install/blob/ca3916d4e7240ebdc337825d2d78eb354855464b/.github/workflows/tests.yml#L8-L11
env:
# prevents extra Cypress installation progress messages (github action default is true)
CI: 1
# avoid warnings like "tput: No value for $TERM and no -T specified"
TERM: xterm
# default to being a preview deployment
DEPLOY_ENV: Preview
steps:
- name: Add comment with link to ongoing build
uses: marocchino/sticky-pull-request-comment@v2
with:
header: -build-status
append: true
message: |
---
**[🏭 A new build process was started - watch live 📺](https://github.com/commercetools/commercetools-docs-kit/actions/runs/${{ github.run_id }})**
- name: Detect Production Deploy
if: github.event_name == 'push' && github.ref_name == 'main'
run: |
echo "DEPLOY_ENV=Production" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node (uses version in .nvmrc)
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
# cached dependencies
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-v3-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-v3-
# cached build (separately to increase cache efficiency)
- uses: actions/cache@v4
id: build-cache
with:
path: |
.cache
public
key: ${{ runner.os }}-gatsby-monolithic-v2-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
run: yarn install --immutable
env:
# https://github.com/bahmutov/cypress-gh-action-split-install/blob/ca3916d4e7240ebdc337825d2d78eb354855464b/.github/workflows/tests.yml#L14-L18
# https://github.com/marketplace/actions/cypress-io#custom-install
CYPRESS_INSTALL_BINARY: 0
- name: Running static type checking
run: yarn typecheck
- name: Building Websites
run: yarn build
env:
ENABLE_SEARCH: 'true'
NODE_OPTIONS: '--max-old-space-size=6144'
GATSBY_EXPERIMENTAL_QUERY_CONCURRENCY: 8 # default is 4, going too high on the 2-core github actions machines will fire back
GATSBY_CPU_COUNT: logical_cores # use hyperthreading if available to statistically better saturate the cores
- name: GitHub Slug Action
uses: rlespinasse/github-slug-action@v4
with:
slug-maxlength: 52
- name: Deploy preview to commercetools-docs-kit vercel via CLI
if: ${{ env.DEPLOY_ENV == 'Preview' }}
id: deploy-to-vercel
env:
GITHUB_COMMITMESSAGE: ${{ toJSON(github.event.head_commit.message) }} # toJSON is de facto escaping and quoting the string
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID}}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID}}
run: |
vercel deploy --yes --token ${{ secrets.VERCEL_TOKEN }} --scope commercetools -m githubCommitSha=${{ github.sha }} -m githubCommitAuthorName=${{ github.actor }} -m githubCommitAuthorLogin=${{ github.actor }} -m githubDeployment=1 -m githubOrg=commercetools -m githubRepo=commercetools-docs-kit -m githubCommitOrg=commercetools -m githubCommitRepo=commercetools-docs-kit -m githubCommitRef=main -m githubCommitMessage="$GITHUB_COMMITMESSAGE" > deployment-url.txt
vercel alias set $(cat deployment-url.txt) docskit-sha-${{ github.sha }}.commercetools.vercel.app --token ${{ secrets.VERCEL_TOKEN }} --scope commercetools
vercel alias set $(cat deployment-url.txt) docskit-${{ env.GITHUB_REF_NAME_SLUG_URL }}.commercetools.vercel.app --token ${{ secrets.VERCEL_TOKEN }} --scope commercetools
- name: Post new build information
if: ${{ env.DEPLOY_ENV == 'Preview' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: -build-status
message: |
**[🚚 Build Process Details](https://github.com/commercetools/commercetools-docs-kit/actions/runs/${{ github.run_id }})**
Preview URLs:
* https://docskit-${{ env.GITHUB_REF_NAME_SLUG_URL }}.commercetools.vercel.app _(permalink to the last build of this **branch**)_
* https://docskit-sha-${{ github.sha }}.commercetools.vercel.app _(this **commit**)_
- name: Running linters and tests
run: |
yarn jest --projects jest.{eslint,test}.config.js \
--maxWorkers=3 \
--reporters jest-silent-reporter
yarn percy config:validate
- name: Run Writing Style check over Websites
run: yarn lint:text
- name: Deploy production to commercetools-docs-kit vercel via CLI
if: ${{ env.DEPLOY_ENV == 'Production' }}
id: deploy-to-vercel-production
env:
GITHUB_COMMITMESSAGE: ${{ toJSON(github.event.head_commit.message) }} # toJSON is de facto escaping and quoting the string
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID}}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID}}
run: |
vercel deploy --prod --yes --token ${{ secrets.VERCEL_TOKEN }} --scope commercetools -m githubCommitSha=${{ github.sha }} -m githubCommitAuthorName=${{ github.actor }} -m githubCommitAuthorLogin=${{ github.actor }} -m githubDeployment=1 -m githubOrg=commercetools -m githubRepo=commercetools-docs-kit -m githubCommitOrg=commercetools -m githubCommitRepo=commercetools-docs-kit -m githubCommitRef=main -m githubCommitMessage="$GITHUB_COMMITMESSAGE" > deployment-url.txt
vercel alias set $(cat deployment-url.txt) docskit-sha-${{ github.sha }}.commercetools.vercel.app --token ${{ secrets.VERCEL_TOKEN }} --scope commercetools
- name: Running Visual Regression Tests
run: yarn percy snapshot ./public
env:
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN_SMOKE_TESTS }}
# https://github.com/bahmutov/cypress-gh-action-split-install/blob/ca3916d4e7240ebdc337825d2d78eb354855464b/.github/workflows/tests.yml#L23-L30
# https://github.com/marketplace/actions/cypress-io#custom-install
- name: Restoring Cypress cache
# restore / cache the binary ourselves on Linux
# see https://github.com/actions/cache
id: cache-cypress
uses: actions/cache@v4
with:
path: ~/.cache/Cypress
key: ${{ runner.os }}-cypress-${{ hashFiles('**/package.json') }}
- name: Installing Cypress binary
run: yarn cypress install && yarn cypress cache list
- name: Running End-to-End tests
run: yarn percy exec -- yarn test:e2e:docs-smoke-test --config baseUrl="https://docskit-sha-${{ github.sha }}.commercetools.vercel.app"
env:
NODE_ENV: test
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN_SMOKE_TESTS_E2E }}
CYPRESS_CI: 'true'
- name: Running API End-to-End tests
run: yarn percy exec -- yarn test:e2e:api-docs-smoke-test --config baseUrl="https://docskit-sha-${{ github.sha }}.commercetools.vercel.app"
env:
NODE_ENV: test
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN_API_SMOKE_TESTS_E2E }}
CYPRESS_CI: 'true'
- name: Check local links including anchors
if: ${{ env.DEPLOY_ENV == 'Preview' }}
working-directory: public
run: npx --quiet start-server-and-test 'npx --quiet http-server --silent -p 9000' http://127.0.0.1:9000 'docker run --platform linux/amd64 --network=host -v "$(pwd)/../:/repo/" tennox/linkcheck --skip-file /repo/linkcheck-local-skip-list :9000'
self_learning_test:
name: 'Self-learning e2e tests'
needs: build_deploy_test
runs-on: ubuntu-latest
concurrency: self-learning-concurrency-group
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node (uses version in .nvmrc)
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
# cached dependencies
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-v3-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-v3-
- name: Install dependencies
run: yarn install --immutable
env:
# https://github.com/bahmutov/cypress-gh-action-split-install/blob/ca3916d4e7240ebdc337825d2d78eb354855464b/.github/workflows/tests.yml#L14-L18
# https://github.com/marketplace/actions/cypress-io#custom-install
CYPRESS_INSTALL_BINARY: 0
# https://github.com/bahmutov/cypress-gh-action-split-install/blob/ca3916d4e7240ebdc337825d2d78eb354855464b/.github/workflows/tests.yml#L23-L30
# https://github.com/marketplace/actions/cypress-io#custom-install
- name: Restoring Cypress cache
# restore / cache the binary ourselves on Linux
# see https://github.com/actions/cache
id: cache-cypress
uses: actions/cache@v4
with:
path: ~/.cache/Cypress
key: ${{ runner.os }}-cypress-${{ hashFiles('**/package.json') }}
- name: Installing Cypress binary
run: yarn cypress install && yarn cypress cache list
- name: Running Self Learning End-to-End tests
run: yarn percy exec -- yarn test:e2e:self-learning-smoke-test --config baseUrl="https://docskit-sha-${{ github.sha }}.commercetools.vercel.app"
env:
NODE_ENV: test
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN_SMOKE_TESTS_SELF_LEARNING_E2E }}
CYPRESS_CI: 'true'
- name: Upload e2e artifacts
uses: actions/upload-artifact@v3-node20
if: ${{ failure() }}
with:
name: self-learning-e2e-failure-snapshots-${{ github.run_attempt }}
path: cypress/screenshots/
link-check:
name: 'Check links'
needs: build_deploy_test
if: github.event_name != 'push' && github.ref_name != 'main'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check links
uses: JustinBeckwith/linkinator-action@v1.11.0
with:
paths: https://docskit-sha-${{ github.sha }}.commercetools.vercel.app
config: linkinator.remote.config.json
markdown: false
# the docs production domain has to be rewritten to the preview URL to allow new pages to be created without the link checker
# erroring on the canonical URL of the new page. Known compromise to not find links that point to the absolute production URL
# but the docs kit is automatically making those a relative URL in authored content so the impact is low.
urlRewriteReplace: https://docskit-sha-${{ github.sha }}.commercetools.vercel.app
urlRewriteSearch: https://docs.commercetools.com