-
Notifications
You must be signed in to change notification settings - Fork 0
222 lines (215 loc) · 7.05 KB
/
Copy pathunit-tests.yaml
File metadata and controls
222 lines (215 loc) · 7.05 KB
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
---
name: Tests
on:
push:
branches:
- '**'
pull_request:
types:
- opened
- reopened
- synchronize
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
tests-preflight:
name: Preflight Check
runs-on: ubuntu-latest
outputs:
PR_EXISTS: ${{ steps.pr-check.outputs.PR_EXISTS }}
timeout-minutes: 10
permissions:
contents: read
steps:
- name: Short circuit if open PR exists for this branch (on push)
id: pr-check
if: github.event_name == 'push'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
sleep 10
prs=$(gh pr list --head "${{ github.ref_name }}" --state open --repo "${{ github.repository }}" --json number --jq '.[].number')
if [ -n "$prs" ]; then
echo "PR_EXISTS=true" >> $GITHUB_OUTPUT
else
echo "PR_EXISTS=false" >> $GITHUB_OUTPUT
fi
test-app:
name: Unit Tests (App)
needs: tests-preflight
if: needs.tests-preflight.outputs.PR_EXISTS != 'true'
runs-on: ubuntu-latest
defaults:
run:
working-directory: app
outputs:
HAS_SONAR_SECRETS: ${{ steps.check-secrets.outputs.HAS_SONAR_SECRETS }}
timeout-minutes: 10
strategy:
fail-fast: true
matrix:
node-version:
- '20.x'
- '22.x'
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Check Sonar Secrets
id: check-secrets
run: |
echo "HAS_SONAR_SECRETS=${{ secrets.SONAR_TOKEN_APP != '' }}" >> $GITHUB_OUTPUT
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
uses: actions/cache@v4
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: Generate Prisma Schema
run: npm run prisma:generate
- name: Test
run: npm run test
env:
CI: true
- name: Save Coverage Results
if: matrix.node-version == '22.x'
uses: actions/upload-artifact@v4
with:
name: coverage-app
path: ${{ github.workspace }}/app/coverage
retention-days: 1
- name: Monitor Coverage
if: "matrix.node-version == '22.x' && github.event_name == 'pull_request' && ! github.event.pull_request.head.repo.fork"
uses: slavcodev/coverage-monitor-action@398c4cbbb710e549a8407fdef96ae8b9454d0463 # 1.10.0
with:
comment_mode: update
comment_footer: false
comment_context: Coverage Report (Application)
coverage_path: app/coverage/clover.xml
github_token: ${{ secrets.GITHUB_TOKEN }}
threshold_alert: 50
threshold_warning: 80
test-frontend:
name: Unit Tests (Frontend)
needs: tests-preflight
if: needs.tests-preflight.outputs.PR_EXISTS != 'true'
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
outputs:
HAS_SONAR_SECRETS: ${{ steps.check-secrets.outputs.HAS_SONAR_SECRETS }}
timeout-minutes: 10
strategy:
fail-fast: true
matrix:
node-version:
- '20.x'
- '22.x'
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Check Sonar Secrets
id: check-secrets
run: |
echo "HAS_SONAR_SECRETS=${{ secrets.SONAR_TOKEN_FRONTEND != '' }}" >> $GITHUB_OUTPUT
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
uses: actions/cache@v4
id: cache-frontend
env:
cache-name: cache-node-modules
with:
path: ${{ github.workspace }}/frontend/node_modules
key: ${{ runner.os }}-frontend-${{ env.cache-name }}-${{ hashFiles('**/frontend/package-lock.json') }}
restore-keys: |
${{ runner.os }}-frontend-${{ env.cache-name }}-
${{ runner.os }}-frontend-
${{ runner.os }}-
- name: Install dependencies
if: steps.cache-frontend.outputs.cache-hit != 'true'
run: npm ci
- name: Test
run: npm run test
env:
CI: true
- name: Save Coverage Results
if: matrix.node-version == '22.x'
uses: actions/upload-artifact@v4
with:
name: coverage-frontend
path: ${{ github.workspace }}/frontend/coverage
retention-days: 1
- name: Monitor Coverage
if: "matrix.node-version == '22.x' && github.event_name == 'pull_request' && ! github.event.pull_request.head.repo.fork"
uses: slavcodev/coverage-monitor-action@398c4cbbb710e549a8407fdef96ae8b9454d0463 # 1.10.0
with:
comment_mode: update
comment_footer: false
comment_context: Coverage Report (Frontend)
coverage_path: frontend/coverage/clover.xml
github_token: ${{ secrets.GITHUB_TOKEN }}
threshold_alert: 50
threshold_warning: 80
test-coverage-app:
name: Publish App Coverage to SonarCloud
needs:
- test-app
if: needs.test-app.outputs.HAS_SONAR_SECRETS == 'true'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
- name: Checkout Repository
uses: actions/checkout@v4.2.2
- name: Restore Coverage Results
uses: actions/download-artifact@v4.3.0
with:
name: coverage-app
path: ${{ github.workspace }}/app/coverage
- name: SonarCloud Scan
uses: SonarSource/sonarqube-scan-action@8c71dc039c2dd71d3821e89a2b58ecc7fee6ced9 # v5.3.0
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_APP }}
with:
projectBaseDir: app
test-coverage-frontend:
name: Publish Frontend Coverage to SonarCloud
needs:
- test-frontend
if: needs.test-frontend.outputs.HAS_SONAR_SECRETS == 'true'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
- name: Checkout Repository
uses: actions/checkout@v4.2.2
- name: Restore Coverage Results
uses: actions/download-artifact@v4.3.0
with:
name: coverage-frontend
path: ${{ github.workspace }}/frontend/coverage
- name: SonarCloud Scan
uses: SonarSource/sonarqube-scan-action@8c71dc039c2dd71d3821e89a2b58ecc7fee6ced9 # v5.3.0
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_FRONTEND }}
with:
projectBaseDir: frontend