-
Notifications
You must be signed in to change notification settings - Fork 9
91 lines (88 loc) · 2.7 KB
/
unit-tests.yaml
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
---
name: Tests
on:
- push
- pull_request
jobs:
test-app:
name: Unit Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: app
outputs:
HAS_CC_SECRETS: ${{ steps.check-secrets.outputs.HAS_CC_SECRETS }}
timeout-minutes: 10
strategy:
fail-fast: true
matrix:
node-version:
- '14.x'
- '16.x'
- '18.x'
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Check CodeClimate Secrets
id: check-secrets
run: |
echo "HAS_CC_SECRETS=${{ secrets.CC_TEST_REPORTER_ID != '' }}" >> $GITHUB_OUTPUT
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
uses: actions/cache@v3
id: cache-app
env:
cache-name: cache-node-modules
with:
path: ${{ github.workspace }}/app/node_modules
key: ${{ runner.os }}-app-${{ env.cache-name }}-${{ hashFiles('**/app/package-lock.json') }}
restore-keys: |
${{ runner.os }}-app-${{ env.cache-name }}-
${{ runner.os }}-app-
${{ runner.os }}-
- name: Install dependencies
if: steps.cache-app.outputs.cache-hit != 'true'
run: npm ci
- name: Test
run: npm run test
env:
CI: true
- name: Save Coverage Results
if: matrix.node-version == '18.x'
uses: actions/upload-artifact@v3
with:
name: coverage-app
path: ${{ github.workspace }}/app/coverage
retention-days: 1
- name: Monitor Coverage
if: "matrix.node-version == '18.x' && ! github.event.pull_request.head.repo.fork"
uses: slavcodev/coverage-monitor-action@v1
with:
comment_mode: update
comment_footer: false
coverage_path: app/coverage/clover.xml
github_token: ${{ secrets.GITHUB_TOKEN }}
threshold_alert: 50
threshold_warning: 80
test-coverage:
name: Publish to Code Climate
needs: test-app
if: needs.test-app.outputs.HAS_CC_SECRETS == 'true'
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Restore Coverage Results
uses: actions/download-artifact@v3
- name: Publish code coverage
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
coverageLocations: |
${{ github.workspace }}/**/lcov.info:lcov
prefix: ${{ github.workplace }}