generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 1
395 lines (354 loc) · 13.5 KB
/
ci-full-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
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
name: "CI/CD - Full Pipeline"
on:
pull_request:
push:
branches:
- main
- development
- production
jobs:
build_test:
name: Build (Test)
runs-on: ubuntu-20.04
outputs:
docker_image: ${{ steps.build.outputs.docker_image }}
if: ${{ github.ref != 'refs/heads/production' && github.ref != 'refs/heads/development' }}
steps:
- uses: actions/[email protected]
- uses: ./.github/workflows/actions/build-docker-image
name: Build docker image
id: build
with:
target: test
ghcr_username: ${{ github.actor }}
ghcr_password: ${{ secrets.GITHUB_TOKEN }}
build_release:
name: Build (Release)
runs-on: ubuntu-20.04
outputs:
docker_image: ${{ steps.build.outputs.docker_image }}
steps:
- uses: actions/[email protected]
- uses: ./.github/workflows/actions/build-docker-image
name: Build docker image
id: build
with:
target: app
ghcr_username: ${{ github.actor }}
ghcr_password: ${{ secrets.GITHUB_TOKEN }}
brakeman:
name: Checks - Brakeman
needs: build_test
runs-on: ubuntu-20.04
steps:
- name: Set up Docker Buildx
uses: docker/[email protected]
- run: docker run ${{ needs.build_test.outputs.docker_image }} bundle exec brakeman
rubocop:
name: Checks - Rubocop
needs: build_test
runs-on: ubuntu-20.04
steps:
- name: Set up Docker Buildx
uses: docker/[email protected]
- run: docker run ${{ needs.build_test.outputs.docker_image }} bundle exec rubocop
jest:
name: Checks - Jest
needs: build_test
runs-on: ubuntu-20.04
steps:
- uses: actions/[email protected]
- name: Install node modules
run: yarn install
- name: Run tests
run: yarn jest
rspec:
name: Checks - Rspec
needs: build_test
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
ci_node_total: [6]
ci_node_index: [0, 1, 2, 3, 4, 5]
services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
redis:
image: redis
ports:
- 6379:6379
chrome:
image: selenium/standalone-chrome:95.0-chromedriver-95.0
ports:
- 4444:4444
steps:
- name: Run Rspec tests
run: |
docker run \
--network ${{ job.container.network }} \
--name test_container \
-e RAILS_ENV=test \
-e DATABASE_URL=postgres://postgres:password@postgres:5432/buy-for-your-school-test \
-e DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL="true" \
-e DOCKER=true \
-e SELENIUM_HUB_URL=http://chrome:4444/wd/hub \
-e REDIS_URL=redis://redis:6379 \
-e APPLICATION_URL=http://localhost:3000 \
-e SECRET_KEY_BASE=test \
-e CONTENTFUL_SPACE=test \
-e CONTENTFUL_ENVIRONMENT=master \
-e CONTENTFUL_DELIVERY_TOKEN=123 \
-e CONTENTFUL_PREVIEW_TOKEN=123 \
-e CONTENTFUL_ENTRY_CACHING=false \
-e CONTENTFUL_WEBHOOK_API_KEY=test \
-e NOTIFY_API_KEY=development_team-12345678-1234-1234-1234-abcd12345678-12345678-1234-1234-1234-abcd12345678 \
-e MS_GRAPH_TENANT=test \
-e MS_GRAPH_CLIENT_ID=test \
-e MS_GRAPH_CLIENT_SECRET=test \
-e MS_GRAPH_SHARED_MAILBOX_USER_ID=test \
-e MS_GRAPH_SHARED_MAILBOX_NAME=mailbox \
-e [email protected] \
-e CLAMAV_REST_SERVICE_URL=test \
-e DSI_ENV=test \
-e DFE_SIGN_IN_IDENTIFIER=service \
-e DFE_SIGN_IN_API_SECRET=secret \
-e PROC_OPS_TEAM="DSI Caseworkers" \
-e QUALTRICS_SURVEY_URL=https://dferesearch.fra1.qualtrics.com \
-e [email protected] \
-e FAF_FRAMEWORK_ENDPOINT=http://faf.test \
-e FAF_WEBHOOK_SECRET=test \
-e CI_NODE_TOTAL=${{ matrix.ci_node_total }} \
-e CI_NODE_INDEX=${{ matrix.ci_node_index }} \
${{ needs.build_test.outputs.docker_image }} \
bash -c "bundle exec rake 'knapsack:rspec[--tag ~flaky]'"
- name: Get coverage from container
run: |
mkdir coverage
docker cp test_container:/srv/app/coverage/.resultset.json coverage/.resultset-${{ matrix.ci_node_index }}.json
- name: Remove test container
run: docker rm test_container
- name: Store test coverage
uses: actions/[email protected]
with:
name: coverage-report-${{ matrix.ci_node_index }}
path: coverage/.resultset-${{ matrix.ci_node_index }}.json
rspec_quarentine:
name: Checks - Rspec (Quarantined tests)
needs: build_test
runs-on: ubuntu-20.04
services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
redis:
image: redis
ports:
- 6379:6379
chrome:
image: selenium/standalone-chrome:95.0-chromedriver-95.0
ports:
- 4444:4444
steps:
- name: Run Quarantined Rspec tests
continue-on-error: true
run: |
docker run \
--network ${{ job.container.network }} \
--name test_container \
-e RAILS_ENV=test \
-e DATABASE_URL=postgres://postgres:password@postgres:5432/buy-for-your-school-test \
-e DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL="true" \
-e DOCKER=true \
-e SELENIUM_HUB_URL=http://chrome:4444/wd/hub \
-e REDIS_URL=redis://redis:6379 \
-e APPLICATION_URL=http://localhost:3000 \
-e SECRET_KEY_BASE=test \
-e CONTENTFUL_SPACE=test \
-e CONTENTFUL_ENVIRONMENT=master \
-e CONTENTFUL_DELIVERY_TOKEN=123 \
-e CONTENTFUL_PREVIEW_TOKEN=123 \
-e CONTENTFUL_ENTRY_CACHING=false \
-e CONTENTFUL_WEBHOOK_API_KEY=test \
-e NOTIFY_API_KEY=development_team-12345678-1234-1234-1234-abcd12345678-12345678-1234-1234-1234-abcd12345678 \
-e MS_GRAPH_TENANT=test \
-e MS_GRAPH_CLIENT_ID=test \
-e MS_GRAPH_CLIENT_SECRET=test \
-e MS_GRAPH_SHARED_MAILBOX_USER_ID=test \
-e MS_GRAPH_SHARED_MAILBOX_NAME=mailbox \
-e [email protected] \
-e CLAMAV_REST_SERVICE_URL=test \
-e DSI_ENV=test \
-e DFE_SIGN_IN_IDENTIFIER=service \
-e DFE_SIGN_IN_API_SECRET=secret \
-e PROC_OPS_TEAM="DSI Caseworkers" \
-e QUALTRICS_SURVEY_URL=https://dferesearch.fra1.qualtrics.com \
-e [email protected] \
-e FAF_FRAMEWORK_ENDPOINT=http://faf.test \
-e FAF_WEBHOOK_SECRET=test \
${{ needs.build_test.outputs.docker_image }} \
bash -c "bundle exec rspec --tag flaky || bundle exec rspec --only-failure"
- name: Get coverage from container
run: |
mkdir coverage
docker cp test_container:/srv/app/coverage/.resultset.json coverage/.resultset-quarantine.json
- name: Remove test container
run: docker rm test_container
- name: Store test coverage
uses: actions/[email protected]
with:
name: coverage-report-quarantine
path: coverage/.resultset-quarantine.json
collate_test_coverage:
name: Checks - Produce test coverage report
needs: [build_test, rspec, rspec_quarentine]
runs-on: ubuntu-20.04
steps:
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Download all test coverage
uses: actions/[email protected]
with:
path: coverage
pattern: coverage-report-*
merge-multiple: true
- name: Generate collated test coverage
run: |
CONTAINER_ID=$(docker run -di ${{ needs.build_test.outputs.docker_image }} "/bin/sh")
docker cp coverage $CONTAINER_ID:/srv/app
docker exec $CONTAINER_ID bash -c "ruby lib/code_coverage_collate.rb"
docker cp $CONTAINER_ID:/srv/app/coverage/index.html coverage
docker cp $CONTAINER_ID:/srv/app/coverage/assets coverage
docker cp $CONTAINER_ID:/srv/app/coverage/.last_run.json coverage
docker stop $CONTAINER_ID
docker rm $CONTAINER_ID
- name: Store collated test coverage
uses: actions/[email protected]
with:
name: full-coverage-report
path: |
coverage/*
!coverage/.last_run.json
- name: Store last run
uses: actions/[email protected]
with:
name: last-run
path: coverage/.last_run.json
- name: Delete intermediate artifacts
uses: geekyeggo/[email protected]
with:
name: coverage-report-*
comment_coverage:
name: Comment coverage on PR
needs: collate_test_coverage
runs-on: ubuntu-20.04
if: ${{ github.event_name == 'pull_request' }}
steps:
- name: Download coverage from current run
uses: actions/[email protected]
with:
path: coverage/current
pattern: last-run
- run: echo current_coverage=$(cat coverage/current/last-run/.last_run.json) >> $GITHUB_ENV
- name: Store coverage from current run
id: current-run-coverage
run: |
echo branch=${{ fromJson(env.current_coverage).result.branch }} >> $GITHUB_OUTPUT
echo line=${{ fromJson(env.current_coverage).result.line }} >> $GITHUB_OUTPUT
- name: Post comment
uses: thollander/[email protected]
with:
message: |
# Test coverage
**Line:** ${{ steps.current-run-coverage.outputs.line }}%
**Branch:** ${{ steps.current-run-coverage.outputs.branch }}%
release_dev:
name: Deploy release (Dev)
runs-on: ubuntu-20.04
needs: build_release
environment: az-dev
if: github.ref == 'refs/heads/development'
steps:
- uses: actions/[email protected]
- uses: ./.github/workflows/actions/deploy-az
with:
docker_image_and_tag: ${{ needs.build_release.outputs.docker_image }}
az_credentials: ${{ secrets.AZURE_SP_CREDENTIALS }}
container_app_name: ${{ secrets.CONTAINER_APP_NAME }}
resource_group_name: ${{ secrets.RESOURCE_GROUP_NAME }}
release_staging:
name: Deploy release (Staging)
runs-on: ubuntu-20.04
needs: build_release
environment: az-staging
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/[email protected]
- uses: ./.github/workflows/actions/deploy-az
with:
docker_image_and_tag: ${{ needs.build_release.outputs.docker_image }}
az_credentials: ${{ secrets.AZURE_SP_CREDENTIALS }}
container_app_name: ${{ secrets.CONTAINER_APP_NAME }}
resource_group_name: ${{ secrets.RESOURCE_GROUP_NAME }}
release_production:
name: Deploy release (Production)
runs-on: ubuntu-20.04
needs: build_release
environment: az-production
if: github.ref == 'refs/heads/production'
steps:
- uses: actions/[email protected]
- uses: ./.github/workflows/actions/deploy-az
with:
docker_image_and_tag: ${{ needs.build_release.outputs.docker_image }}
az_credentials: ${{ secrets.AZURE_SP_CREDENTIALS }}
container_app_name: ${{ secrets.CONTAINER_APP_NAME }}
resource_group_name: ${{ secrets.RESOURCE_GROUP_NAME }}
data_regression_copy_to_original:
name: Data regression testing - trigger copy to pre-release-original-data
needs: release_production
runs-on: ubuntu-20.04
steps:
- uses: Azure/[email protected]
with:
azure-devops-project-url: "https://dfe-ssp.visualstudio.com/S174-Get%20Help%20Buying%20for%20Schools"
azure-pipeline-name: "Pre-release Original Data sync"
azure-devops-token: ${{ secrets.AZURE_DEVOPS_TOKEN }}
data_regression_copy_to_modified:
name: Data regression testing - trigger copy to pre-release-modified-data
needs: release_production
runs-on: ubuntu-20.04
steps:
- uses: Azure/[email protected]
with:
azure-devops-project-url: "https://dfe-ssp.visualstudio.com/S174-Get%20Help%20Buying%20for%20Schools"
azure-pipeline-name: "Pre-release Modified Data sync"
azure-devops-token: ${{ secrets.AZURE_DEVOPS_TOKEN }}
data_regression_migrate_modified:
name: Data regression testing - apply migrations to pre-release-modified-data
needs: [build_release, release_staging]
runs-on: ubuntu-20.04
env:
PRE_RELEASE_MODIFIED_DATA_DB_URL: ${{ secrets.PRE_RELEASE_MODIFIED_DATA_DB_URL }}
steps:
- name: Run migrations against pre-release-modified-data
run: |
docker run --rm \
-e RAILS_ENV=production \
-e DATABASE_URL=${{ env.PRE_RELEASE_MODIFIED_DATA_DB_URL }} \
-e DOCKER=true \
-e SECRET_KEY_BASE=production \
-e APPLICATION_URL=https://www.get-help-buying-for-schools.service.gov.uk \
${{ needs.build_release.outputs.docker_image }} \
bash -c "bundle exec rails db:migrate"