forked from forem/forem
-
Notifications
You must be signed in to change notification settings - Fork 0
433 lines (406 loc) · 13.9 KB
/
ci.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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
name: CI
on:
pull_request:
branches:
- main
merge_group:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
env:
COVERAGE: true
RAILS_ENV: test
NODE_ENV: test
DATABASE_URL_TEST: postgres://postgres:postgres@localhost:5432/Forem_test
DATABASE_NAME_TEST: Forem_test
KNAPSACK_PRO_FIXED_QUEUE_SPLIT: true
POSTGRES_PASSWORD: postgres
KNAPSACK_PRO_LOG_LEVEL: info
jobs:
bundle_install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
yarn_install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Look up if node_module cache exist
id: cache
uses: actions/cache/restore@v4
with:
lookup-only: true
path: node_modules
key: ${{ runner.os }}-node-modules-v2-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-node-modules-v2-
- name: Cache node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-v2-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-node-modules-v2-
if: steps.cache.outputs.cache-hit != 'true'
- uses: actions/setup-node@v4
if: steps.cache.outputs.cache-hit != 'true'
with:
node-version-file: '.nvmrc'
cache: yarn
- run: yarn install --immutable
if: steps.cache.outputs.cache-hit != 'true'
precompile_assets:
needs: [bundle_install, yarn_install]
runs-on: ubuntu-latest
env:
E2E: true
steps:
- uses: actions/checkout@v4
- name: Look up if compiled assets exist
uses: actions/cache@v4
id: cache
with:
fail-on-cache-miss: false
path: |
public/assets
key: ${{ runner.os }}-compiled-assets-v3-${{ hashFiles('app/assets/**', 'app/javascript/**', '**/package.json', '**/yarn.lock') }}
restore-keys: ${{ runner.os }}-compiled-assets-v3-
- name: setup ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
if: steps.cache.outputs.cache-hit != 'true'
- name: Cache node_modules
uses: actions/cache/restore@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-v2-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-node-modules-v2-
if: steps.cache.outputs.cache-hit != 'true'
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn
if: steps.cache.outputs.cache-hit != 'true'
- run: bundle exec rails assets:precompile
if: steps.cache.outputs.cache-hit != 'true'
audit:
runs-on: ubuntu-latest
needs: [bundle_install, yarn_install]
steps:
- uses: actions/checkout@v4
- name: setup ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn
- name: Restore node_modules
uses: actions/cache/restore@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-v2-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-node-modules-v2-
- name: rubocop
uses: reviewdog/action-rubocop@v2
with:
rubocop_version: gemfile
rubocop_extensions: rubocop-performance:gemfile rubocop-rails:gemfile rubocop-rspec:gemfile rubocop-capybara:gemfile
reporter: github-pr-review # Default is github-pr-check
- run: yarn lint:frontend
- run: bundle exec bundle-audit check --update --ignore CVE-2023-26141
rspec:
runs-on: ubuntu-latest
needs: [precompile_assets]
timeout-minutes: 20
env:
KNAPSACK_PRO_CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
KNAPSACK_PRO_CI_NODE_INDEX: ${{ matrix.ci_node_index }}
KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC }}
services:
postgres:
image: postgres:13-alpine
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
redis:
image: redis
ports:
- 6379:6379
strategy:
fail-fast: false
matrix:
ci_node_total: [8]
ci_node_index: [0, 1, 2, 3, 4, 5, 6, 7]
steps:
- uses: actions/checkout@v4
- name: Restore compiled assets
uses: actions/cache/restore@v4
with:
fail-on-cache-miss: true
path: |
public/assets
key: ${{ runner.os }}-compiled-assets-v3-${{ hashFiles('app/assets/**', 'app/javascript/**', '**/package.json', '**/yarn.lock') }}
restore-keys: ${{ runner.os }}-compiled-assets-v3-
- name: Restore node_modules
uses: actions/cache/restore@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-v2-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-node-modules-v2-
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn
- name: setup ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- run: bundle exec rails db:test:prepare
- name: RSpec
run: bin/knapsack_pro_rspec
- name: Upload RSpec artifacts
uses: actions/upload-artifact@v4
if: failure()
with:
name: rspec-artifacts-${{ matrix.ci_node_index }}
path: tmp/capybara
- name: Rename folder
run: mv coverage/simplecov coverage/simplecov-${{ matrix.ci_node_index }}
- name: Upload test coverage result
uses: actions/upload-artifact@v4
with:
name: coverage-rspec-${{ matrix.ci_node_index }}
path: coverage/
- name: Upload test results to BuildPulse for flaky test detection
if: '!cancelled()' # Run this step even when the tests fail. Skip if the workflow is cancelled.
uses: Workshop64/buildpulse-action@master
with:
account: ${{ secrets.BUILDPULSE_ACCOUNT }}
repository: ${{ secrets.BUILDPULSE_REPOSITORY }}
path: tmp/rspec_final_results.xml
key: ${{ secrets.BUILDPULSE_ACCESS_KEY_ID }}
secret: ${{ secrets.BUILDPULSE_SECRET_ACCESS_KEY }}
jest:
runs-on: ubuntu-latest
needs: [yarn_install]
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- name: Restore node_modules
uses: actions/cache/restore@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-v2-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-node-modules-v2-
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn
- run: yarn test --colors --ci --reporters="jest-junit" --reporters="default"
- name: Upload test results to BuildPulse for flaky test detection
if: '!cancelled()' # Run this step even when the tests fail. Skip if the workflow is cancelled.
uses: Workshop64/buildpulse-action@master
with:
account: ${{ secrets.BUILDPULSE_ACCOUNT }}
repository: ${{ secrets.BUILDPULSE_REPOSITORY }}
path: junit.xml
key: ${{ secrets.BUILDPULSE_ACCESS_KEY_ID }}
secret: ${{ secrets.BUILDPULSE_SECRET_ACCESS_KEY }}
- name: Upload test coverage result
uses: actions/upload-artifact@v4
with:
name: coverage-jest
path: coverage/
storybook:
runs-on: ubuntu-latest
needs: [yarn_install]
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- name: Restore node_modules
uses: actions/cache/restore@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-v2-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-node-modules-v2-
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn
- run: yarn build-storybook
build_test:
runs-on: ubuntu-latest
needs: [bundle_install, yarn_install]
timeout-minutes: 20
env:
RAILS_ENV: production
NODE_ENV: production
DATABASE_URL: postgres://postgres:postgres@localhost:5432/Forem_prod_test
DATABASE_NAME: Forem_prod_test
APP_PROTOCOL: http://
APP_DOMAIN: localhost:3000
HEROKU_APP_URL: practicaldev.herokuapp.com
SECRET_KEY_BASE: dummydummydummy
GITHUB_KEY: dummy
GITHUB_SECRET: dummy
services:
postgres:
image: postgres:13-alpine
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
redis:
image: redis
ports:
- 6379:6379
steps:
- uses: actions/checkout@v4
- name: Restore node_modules
uses: actions/cache/restore@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-v2-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-node-modules-v2-
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn
- name: setup ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- run: bundle exec rails assets:precompile
- run: RAILS_ENV=test bin/test-console-check
cypress:
runs-on: ubuntu-latest
timeout-minutes: 20
needs: [precompile_assets]
env:
E2E: true
services:
postgres:
image: postgres:13-alpine
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
redis:
image: redis
ports:
- 6379:6379
strategy:
fail-fast: false
matrix:
ci_node_total: [8]
ci_node_index: [0, 1, 2, 3, 4, 5, 6, 7, non-seed]
steps:
- uses: actions/checkout@v4
- name: Restore compiled assets
uses: actions/cache/restore@v4
with:
fail-on-cache-miss: true
path: |
public/assets
key: ${{ runner.os }}-compiled-assets-v3-${{ hashFiles('app/assets/**', 'app/javascript/**', '**/package.json', '**/yarn.lock') }}
restore-keys: ${{ runner.os }}-compiled-assets-v3-
- name: Restore node_modules
uses: actions/cache/restore@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-v2-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-node-modules-v2-
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn
- name: setup ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- run: bundle exec rails db:test:prepare
- name: Cache cypress binary
uses: actions/cache@v4
with:
path: ~/.cache/Cypress
key: ${{ runner.os }}-cypress-binary-${{ hashFiles('**/yarn.lock') }}
- run: yarn cypress install
- name: cypress
env:
CYPRESS_RAILS_HOST: localhost
CYPRESS_RAILS_PORT: 3000
KNAPSACK_PRO_CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
KNAPSACK_PRO_CI_NODE_INDEX: ${{ matrix.ci_node_index }}
KNAPSACK_PRO_TEST_SUITE_TOKEN_CYPRESS: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_CYPRESS }}
KNAPSACK_PRO_TEST_FILE_PATTERN: "cypress/e2e/seededFlows/**/*.spec.js"
run: bin/knapsack_pro_cypress
if: ${{ matrix.ci_node_index != 'non-seed' }}
- name: cypress non-seed
run: CREATOR_ONBOARDING_SEED_DATA=1 E2E_FOLDER=creatorOnboardingFlows E2E=true bin/rails cypress:run
if: ${{ matrix.ci_node_index == 'non-seed' }}
- name: Upload Cypress artifacts
uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-artifacts-${{ matrix.ci_node_index }}
path: |
tmp/cypress_screenshots
cypress/logs
- name: Upload test results to BuildPulse for flaky test detection
if: '!cancelled()' # Run this step even when the tests fail. Skip if the workflow is cancelled.
uses: Workshop64/buildpulse-action@master
with:
account: ${{ secrets.BUILDPULSE_ACCOUNT }}
repository: ${{ secrets.BUILDPULSE_REPOSITORY }}
path: cypress/results
key: ${{ secrets.BUILDPULSE_ACCESS_KEY_ID }}
secret: ${{ secrets.BUILDPULSE_SECRET_ACCESS_KEY }}
upload-coverage:
runs-on: ubuntu-latest
needs: [rspec, jest, cypress]
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: coverage-*
merge-multiple: true
- run: |
mkdir coverage coverage/simplecov coverage/cypress
mv simplecov-* coverage/simplecov
mv jest coverage/jest
- uses: Wandalen/wretry.action@master
with:
action: codecov/codecov-action@v4
with: |
flags: ruby
directory: coverage/simplecov
fail_ci_if_error: ${{ github.ref != 'refs/heads/main' }}
token: ${{ secrets.CODECOV_TOKEN }}
attempt_limit: 5
attempt_delay: 60000
- uses: Wandalen/wretry.action@master
with:
action: codecov/codecov-action@v4
with: |
flags: jest, javascript
directory: coverage/jest
fail_ci_if_error: ${{ github.ref != 'refs/heads/main' }}
token: ${{ secrets.CODECOV_TOKEN }}
attempt_limit: 5
attempt_delay: 60000
CI-status-report:
runs-on: ubuntu-latest
needs: [rspec, jest, cypress, build_test, audit, storybook]
if: always()
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}