-
Notifications
You must be signed in to change notification settings - Fork 133
317 lines (294 loc) · 10.8 KB
/
dev-pipeline.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
name: Process v3 push or PR
on:
push:
branches:
- v3
- node-migration
pull_request:
branches:
- v3
- node-migration
env:
# We tell Playwright not to download browser binaries because we use microsoft/playwright-github-action.
# https://github.com/microsoft/playwright/blob/v1.16.2/installation-tests/installation-tests.sh#L200-L216
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1'
jobs:
# install dependencies, build shared components, cache both for subsequent jobs
install:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
# https://github.com/actions/cache/blob/8f1e2e02865c42348f9baddbbaafb1841dce610a/examples.md#node---yarn-2
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/yarn.lock') }}
- name: Cache .yarn/cache
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
uses: actions/cache@v3
with:
path: '.yarn/cache'
key: yarn-v3-cache-${{ github.ref_name }}
restore-keys: yarn-v3-cache-v3
- name: Install dependencies
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
run: yarn install --immutable
- name: cache shared components
id: cache-shared-components
uses: actions/cache@v3
with:
path: 'digitransit-*'
key: ${{ runner.os }}-shared-components-${{ hashFiles('digitransit-*') }}
- name: build shared components
if: ${{ steps.cache-shared-components.outputs.cache-hit != 'true' }}
run: yarn run build-workspaces
lint:
needs: install
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: "Set time zone to Europe/Helsinki"
uses: zcong1993/setup-timezone@master
with:
timezone: "Europe/Helsinki"
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
# https://github.com/actions/cache/blob/8f1e2e02865c42348f9baddbbaafb1841dce610a/examples.md#node---yarn-2
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/yarn.lock') }}
- name: Cache .yarn/cache
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
uses: actions/cache@v3
with:
path: '.yarn/cache'
key: yarn-v3-cache-${{ github.ref_name }}
restore-keys: yarn-v3-cache-v3
- name: Install dependencies
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
run: yarn install --immutable
- name: cache shared components
id: cache-shared-components
uses: actions/cache@v3
with:
path: 'digitransit-*'
key: ${{ runner.os }}-shared-components-${{ hashFiles('digitransit-*') }}
- name: Build shared components
if: ${{ steps.cache-shared-components.outputs.cache-hit != 'true' }}
run: yarn run build-workspaces
- name: Run linters
run: yarn lint
- name: lint SVG sprites using xmllint
run: |
sudo apt install -y libxml2-utils
xmllint --nonet --noout static/assets/svg-sprite.*.svg
unit-test:
needs: install
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: "Set time zone to Europe/Helsinki"
uses: zcong1993/setup-timezone@master
with:
timezone: "Europe/Helsinki"
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
# https://github.com/actions/cache/blob/8f1e2e02865c42348f9baddbbaafb1841dce610a/examples.md#node---yarn-2
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/yarn.lock') }}
- name: Cache .yarn/cache
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
uses: actions/cache@v3
with:
path: '.yarn/cache'
key: yarn-v3-cache-${{ github.ref_name }}
restore-keys: yarn-v3-cache-v3
- name: Install dependencies
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
run: yarn install --immutable
- name: cache shared components
id: cache-shared-components
uses: actions/cache@v3
with:
path: 'digitransit-*'
key: ${{ runner.os }}-shared-components-${{ hashFiles('digitransit-*') }}
- name: Build shared components
if: ${{ steps.cache-shared-components.outputs.cache-hit != 'true' }}
run: yarn run build-workspaces
- name: cache built Relay queries
id: cache-relay
uses: actions/cache@v3
with:
path: |
./__generated__
**/__generated__
key: ${{ runner.os }}-relay-${{ github.sha }}
- name: build Relay queries
if: ${{ steps.cache-relay.outputs.cache-hit != 'true' }}
run: |
yarn run relay
- name: Run unit tests
run: yarn run test-coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
publish-npm:
if: github.ref == 'refs/heads/v3'
needs:
- lint
- unit-test
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 16.x ]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: "Set time zone to Europe/Helsinki"
uses: zcong1993/setup-timezone@master
with:
timezone: "Europe/Helsinki"
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
# https://github.com/actions/cache/blob/8f1e2e02865c42348f9baddbbaafb1841dce610a/examples.md#node---yarn-2
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/yarn.lock') }}
- name: Cache .yarn/cache
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
uses: actions/cache@v3
with:
path: '.yarn/cache'
key: yarn-v3-cache-${{ github.ref_name }}
restore-keys: yarn-v3-cache-v3
- name: Install dependencies
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
run: yarn install --immutable
- name: cache shared components
id: cache-shared-components
uses: actions/cache@v3
with:
path: 'digitransit-*'
key: ${{ runner.os }}-shared-components-${{ hashFiles('digitransit-*') }}
- name: Build shared components
if: ${{ steps.cache-shared-components.outputs.cache-hit != 'true' }}
run: yarn run build-workspaces
- name: cache built Relay queries
id: cache-relay
uses: actions/cache@v3
with:
path: |
./__generated__
**/__generated__
key: ${{ runner.os }}-relay-${{ github.sha }}
- name: build Relay queries
if: ${{ steps.cache-relay.outputs.cache-hit != 'true' }}
run: |
yarn run relay
- name: Authenticate with registry
run: echo //registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN} > .npmrc
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: disregard changed yarn.lock
run: git update-index --assume-unchanged yarn.lock
- name: Publish shared components to npm
run: |
{
echo 'publish-logs<<EOF' >> $GITHUB_OUTPUT
yarn digitransit-npm-autopublish >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
}
shell: bash
id: publish
- name: Parse publish logs
if: steps.publish.outputs.publish-logs != ''
run: |
{
echo 'published-packages<<EOF' >> $GITHUB_OUTPUT
echo "${{ steps.publish.outputs.publish-logs }}" | grep -A100 'Successfully published' >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
}
shell: bash
id: log-parse
- name: Send published packages to slack
if: steps.log-parse.outputs.published-packages != ''
run: |
./.github/workflows/scripts/slack_message.sh
env:
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID }}
SLACK_ACCESS_TOKEN: ${{ secrets.SLACK_ACCESS_TOKEN }}
PUBLISHED_PACKAGES: ${{ steps.log-parse.outputs.published-packages }}
shell: bash
docker-push:
if: github.ref == 'refs/heads/v3'
needs:
- lint
- unit-test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set time zone to Europe/Helsinki
uses: zcong1993/setup-timezone@master
with:
timezone: "Europe/Helsinki"
- name: Create buildInfo.js file
run: |
echo -e "export const COMMIT_ID = \"${GITHUB_SHA}\";\nexport const BUILD_TIME = \"$(date -Iminutes -u)\";" >app/buildInfo.js
- name: Configure Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_AUTH }}
- name: compute Docker image tag
id: docker-tags
# todo: update to v3 before merging!
run: |
echo "permanent-tag=v3-$(date +"%Y-%m-%dT%H.%M.%S")-${GITHUB_SHA:0:7}" >>$GITHUB_OUTPUT
- name: build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
tags: |
hsldevcom/digitransit-ui:v3
hsldevcom/digitransit-ui:${{ steps.docker-tags.outputs.permanent-tag }}
# https://github.com/docker/build-push-action/blob/9472e9021074a3cb3279ba431598b8836d40433f/docs/advanced/cache.md#github-cache
# https://github.com/moby/buildkit#registry-push-image-and-cache-separately
cache-from: type=gha
cache-to: type=gha,mode=max,oci-mediatypes=true,compression=zstd
push: true