-
Notifications
You must be signed in to change notification settings - Fork 0
291 lines (282 loc) · 9.94 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
name: 'Build'
on: [push, pull_request]
env:
CI: true
DOCKER_BUILD_TAG: build-${{ github.run_number }}
jobs:
install:
name: 'Install'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Restore "node_modules" from cache
uses: martijnhols/actions-cache/restore@v3
id: cache
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('patches') }}-${{ hashFiles('yarn.lock') }}
restore-keys: ${{ runner.os }}-node_modules-${{ hashFiles('patches') }}
- name: Get yarn cache directory path
if: steps.cache.outputs.cache-hit != 'true'
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
# Use week number for automatically purging the cache every week. This is
# useful because caching yarn-cache would otherwise lead it to grow
# indefinitely since old dependencies are never purged.
- name: Get week number
if: steps.cache.outputs.cache-hit != 'true'
id: week-number
run: echo "value=$(date +%W)" >> $GITHUB_OUTPUT
- name: Cache "yarn-cache"
uses: martijnhols/actions-cache/restore@v3
if: steps.cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-${{ steps.week-number.outputs.value }}-root-yarn-cache-${{ hashFiles('yarn.lock') }}
restore-keys: ${{ runner.os }}-${{ steps.week-number.outputs.value }}-root-yarn-cache-
- run: yarn --frozen-lockfile --prefer-offline
if: steps.cache.outputs.cache-hit != 'true'
- name: Save "node_modules" to cache
if: steps.cache.outputs.cache-hit != 'true'
uses: martijnhols/actions-cache/save@v3
with:
path: node_modules
key: ${{ steps.cache.outputs.primary-key }}
typecheck:
needs: [install]
name: 'Typecheck'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Restore "node_modules" from cache
uses: martijnhols/actions-cache/restore@v3
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('patches') }}-${{ hashFiles('yarn.lock') }}
required: true
- run: yarn typecheck
lint:
needs: [install]
name: 'Lint'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Restore "node_modules" from cache
uses: martijnhols/actions-cache/restore@v3
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('patches') }}-${{ hashFiles('yarn.lock') }}
required: true
- run: yarn lint
build:
needs: [install]
name: 'Build'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
# Not only does this share the artifact with other jobs, this also improves build performance by reusing next cache
- name: Check "build" in cache
id: cache
uses: martijnhols/actions-cache/restore@v3
with:
path: |
.next
public
key: build-${{ github.run_number }}
restore-keys: build
required: false
- name: Restore "node_modules" from cache
if: steps.cache.outputs.cache-hit != 'true'
uses: martijnhols/actions-cache/restore@v3
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('patches') }}-${{ hashFiles('yarn.lock') }}
required: true
- name: Load tags
if: steps.cache.outputs.cache-hit != 'true'
run: git fetch --prune --unshallow --tags
- run: |
echo "ENVIRONMENT_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
echo "VERSION=$(git describe --tags)" >> $GITHUB_ENV
if: steps.cache.outputs.cache-hit != 'true'
- name: 'Build martijnhols.nl@${{env.VERSION}} for ${{env.ENVIRONMENT_NAME}}'
if: steps.cache.outputs.cache-hit != 'true'
run: yarn build
- name: Save "build" in cache
if: steps.cache.outputs.cache-hit != 'true'
uses: martijnhols/actions-cache/save@v3
with:
path: |
.next
public
key: ${{ steps.cache.outputs.primary-key }}
# TODO: Sentry release
docker-image:
needs: [build]
name: 'Build Pipeline Docker image'
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
steps:
- uses: actions/checkout@v4
- name: Restore "build" from cache
uses: martijnhols/actions-cache/restore@v3
with:
path: |
.next
public
key: build-${{ github.run_number }}
required: true
- name: Restore "node_modules" from cache
uses: martijnhols/actions-cache/restore@v3
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('patches') }}-${{ hashFiles('yarn.lock') }}
required: true
# Docker build / push
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 'Build martijnhols/martijnhols.nl:${{env.DOCKER_BUILD_TAG}}'
uses: docker/build-push-action@v6
with:
context: . # otherwise the action does weird things with the git context (see docs)
tags: 'martijnhols/martijnhols.nl:${{ env.DOCKER_BUILD_TAG }}'
outputs: type=docker,dest=/tmp/dockerimage.tar
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: dockerimage
path: /tmp/dockerimage.tar
# TODO: Cypress
lhci-mobile:
if: false # TODO: fixme
needs: [install, docker-image]
name: Lighthouse Mobile
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Restore "node_modules" from cache
if: steps.cache.outputs.cache-hit != 'true'
uses: martijnhols/actions-cache/restore@v3
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('patches') }}-${{ hashFiles('yarn.lock') }}
required: true
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: dockerimage
path: /tmp
- name: Load Docker image
run: docker load --input /tmp/dockerimage.tar
- run: docker run -d -p 3000:3000 martijnhols/martijnhols.nl:${{ env.DOCKER_BUILD_TAG }}
- run: timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:3000)" != "200" ]]; do sleep 1; done' || false
- name: Collect results
run: yarn lhci collect
- name: Assert results
run: yarn lhci assert
- name: Store results
if: always()
run: yarn lhci upload
- name: Upload results
if: always()
uses: actions/upload-artifact@v4
with:
name: lighthouse-mobile
path: lighthouse
lhci-desktop:
if: false # TODO: fixme
needs: [install, docker-image]
name: Lighthouse Desktop
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Restore "node_modules" from cache
if: steps.cache.outputs.cache-hit != 'true'
uses: martijnhols/actions-cache/restore@v3
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('patches') }}-${{ hashFiles('yarn.lock') }}
required: true
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: dockerimage
path: /tmp
- name: Load Docker image
run: docker load --input /tmp/dockerimage.tar
- run: docker run -d -p 3000:3000 martijnhols/martijnhols.nl:${{ env.DOCKER_BUILD_TAG }}
- run: timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:3000)" != "200" ]]; do sleep 1; done' || false
- name: Collect results
run: yarn lhci collect --settings.preset="desktop"
- name: Assert results
run: yarn lhci assert
- name: Store results
if: always()
run: yarn lhci upload
- name: Upload results
if: always()
uses: actions/upload-artifact@v4
with:
name: lighthouse-desktop
path: lighthouse
# TODO: Storybook
deploy:
needs: [
# cypress-typecheck,
# cypress-lint,
# cypress-generated-types,
typecheck,
lint,
build,
docker-image,
# cypress-run,
]
name: 'Publish Docker image'
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]'
steps:
- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v5
with:
images: martijnhols/martijnhols.nl
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=semver,pattern={{version}}
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: dockerimage
path: /tmp
- name: Load Docker image
run: docker load --input /tmp/dockerimage.tar
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{secrets.DOCKER_USERNAME}}
password: ${{secrets.DOCKER_PASSWORD}}
- run: docker tag martijnhols/martijnhols.nl:${{ env.DOCKER_BUILD_TAG }} ${{ steps.docker_meta.outputs.tags }}
- run: docker push ${{ steps.docker_meta.outputs.tags }}