-
Notifications
You must be signed in to change notification settings - Fork 0
380 lines (326 loc) · 13.8 KB
/
Copy pathanalysis.yml
File metadata and controls
380 lines (326 loc) · 13.8 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
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
name: Analysis
on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review, converted_to_draft]
push:
branches: [main]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions: {}
jobs:
tests-backend-oracle:
name: Tests Backend Oracle
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
cache: maven
cache-dependency-path: backend/pom.xml
- name: Run tests
working-directory: backend
run: |
mkdir -p ~/.m2
if [ -f settings.xml ]; then
cp settings.xml ~/.m2/settings.xml
fi
./mvnw -s ~/.m2/settings.xml clean install -Dserver.primary-db=oracle --no-transfer-progress checkstyle:checkstyle -P all-tests
- name: Upload Oracle coverage artifact
uses: actions/upload-artifact@v4
if: success()
with:
name: coverage-oracle
path: backend/target/**/*.exec
retention-days: 1
tests-backend-postgres:
name: Tests Backend Postgres
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
cache: maven
cache-dependency-path: backend/pom.xml
- name: Run tests
working-directory: backend
run: |
mkdir -p ~/.m2
if [ -f settings.xml ]; then
cp settings.xml ~/.m2/settings.xml
fi
./mvnw -s ~/.m2/settings.xml clean install -Dflyway-environment=dev -Dserver.primary-db=postgres --no-transfer-progress checkstyle:checkstyle -P all-tests
- name: Upload Postgres coverage artifact
uses: actions/upload-artifact@v4
if: success()
with:
name: coverage-postgres
path: backend/target/**/*.exec
retention-days: 1
combine-backend-coverage:
name: Combine Backend Coverage
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
needs: [tests-backend-oracle, tests-backend-postgres]
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
cache: maven
cache-dependency-path: backend/pom.xml
- name: Download Oracle coverage
uses: actions/download-artifact@v4
with:
name: coverage-oracle
path: backend-target-oracle
- name: Download Postgres coverage
uses: actions/download-artifact@v4
with:
name: coverage-postgres
path: backend-target-postgres
- name: Compile classes
working-directory: backend
run: |
mkdir -p ~/.m2
if [ -f settings.xml ]; then
cp settings.xml ~/.m2/settings.xml
fi
# Compile to get classes for report generation
./mvnw -B -s ~/.m2/settings.xml clean compile --no-transfer-progress
- name: Merge coverage reports
working-directory: backend
run: |
set -e
mkdir -p target/coverage-reports
# Gather the already-merged execution data from each database run
ORACLE_EXEC=$(find ../backend-target-oracle -name "jacoco.exec" | head -n 1)
POSTGRES_EXEC=$(find ../backend-target-postgres -name "jacoco.exec" | head -n 1)
if [ -z "$ORACLE_EXEC" ] || [ -z "$POSTGRES_EXEC" ]; then
echo "ERROR: Could not locate jacoco.exec from one of the database runs"
echo "Oracle: $ORACLE_EXEC"
echo "Postgres: $POSTGRES_EXEC"
exit 1
fi
echo "Found Oracle exec: $ORACLE_EXEC"
echo "Found Postgres exec: $POSTGRES_EXEC"
cp "$ORACLE_EXEC" target/coverage-reports/jacoco-oracle.exec
cp "$POSTGRES_EXEC" target/coverage-reports/jacoco-postgres.exec
echo "Files to merge:"
ls -lh target/coverage-reports/jacoco-*.exec
# Download JaCoCo CLI
echo "Downloading JaCoCo CLI..."
curl -L -f -o /tmp/jacococli.jar \
https://repo1.maven.org/maven2/org/jacoco/org.jacoco.cli/0.8.14/org.jacoco.cli-0.8.14-nodeps.jar
if [ ! -f /tmp/jacococli.jar ]; then
echo "ERROR: Failed to download JaCoCo CLI"
exit 1
fi
echo "JaCoCo CLI downloaded successfully"
ls -lh /tmp/jacococli.jar
# Download and verify SHA1 checksum (Maven Central standard)
echo "Downloading SHA1 checksum for verification..."
curl -L -f -o /tmp/jacococli.jar.sha1 \
https://repo1.maven.org/maven2/org/jacoco/org.jacoco.cli/0.8.14/org.jacoco.cli-0.8.14-nodeps.jar.sha1
if [ ! -f /tmp/jacococli.jar.sha1 ]; then
echo "ERROR: Failed to download checksum file"
exit 1
fi
echo "Verifying JAR integrity..."
EXPECTED_SHA=$(cat /tmp/jacococli.jar.sha1)
ACTUAL_SHA=$(sha1sum /tmp/jacococli.jar | awk '{print $1}')
if [ "$EXPECTED_SHA" != "$ACTUAL_SHA" ]; then
echo "ERROR: Checksum verification failed!"
echo "Expected: $EXPECTED_SHA"
echo "Actual: $ACTUAL_SHA"
exit 1
fi
echo "Checksum verification successful"
# Merge Oracle and Postgres execution data into a single coverage file
echo "Merging coverage data..."
java -jar /tmp/jacococli.jar merge \
--destfile target/coverage-reports/jacoco-merged.exec \
target/coverage-reports/jacoco-oracle.exec \
target/coverage-reports/jacoco-postgres.exec
if [ ! -f target/coverage-reports/jacoco-merged.exec ]; then
echo "ERROR: Merge failed - jacoco-merged.exec not created"
exit 1
fi
echo "Merge successful:"
ls -lh target/coverage-reports/jacoco-merged.exec
# Generate XML report from merged coverage using pom.xml's merged-reports execution
echo "Generating JaCoCo XML report..."
cp target/coverage-reports/jacoco-merged.exec target/jacoco.exec
./mvnw org.jacoco:jacoco-maven-plugin:0.8.14:report@merged-reports \
-Djacoco.skip=false
# Validate XML report was generated successfully
if [ ! -f target/coverage-reports/merged-test-report/jacoco.xml ]; then
echo "ERROR: Report generation failed - jacoco.xml not created"
ls -la target/coverage-reports/merged-test-report/ || echo "Directory does not exist"
exit 1
fi
echo "Report generation successful:"
ls -lh target/coverage-reports/merged-test-report/jacoco.xml
echo "XML file size:"
wc -c target/coverage-reports/merged-test-report/jacoco.xml
- name: SonarCloud Scan
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main'
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_BACKEND }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
working-directory: backend
run: |
set -e
mkdir -p ~/.m2
if [ -f settings.xml ]; then
cp settings.xml ~/.m2/settings.xml
fi
# Verify the XML report exists before scanning
REPORT_FILE="target/coverage-reports/merged-test-report/jacoco.xml"
if [ ! -f "$REPORT_FILE" ]; then
echo "ERROR: SonarCloud report file not found: $REPORT_FILE"
ls -la target/coverage-reports/ || echo "coverage-reports directory not found"
exit 1
fi
echo "Found SonarCloud report file:"
ls -lh "$REPORT_FILE"
echo "Report file content preview (first 20 lines):"
head -20 "$REPORT_FILE"
echo ""
echo "Running SonarCloud scan..."
echo "SONAR_TOKEN length: ${#SONAR_TOKEN}"
echo "GITHUB_TOKEN length: ${#GITHUB_TOKEN}"
./mvnw -B -s ~/.m2/settings.xml \
org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.exclusions=**/configuration/**,**/dto/**,**/entity/**,**/exception/**,**/enums/**,**/repository/**,**/job/**,**/*$*Builder*,**/ResultsApplication.*,**/*Constants.*,**/security/** \
-Dsonar.coverage.jacoco.xmlReportPaths=target/coverage-reports/merged-test-report/jacoco.xml \
-Dsonar.organization=bcgov-sonarcloud \
-Dsonar.project.monorepo.enabled=true \
-Dsonar.projectKey=nr-silva-backend
SCAN_EXIT_CODE=$?
if [ $SCAN_EXIT_CODE -ne 0 ]; then
echo "ERROR: SonarCloud scan failed with exit code $SCAN_EXIT_CODE"
exit $SCAN_EXIT_CODE
fi
echo "SonarCloud scan completed successfully"
- name: Upload merged coverage artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-merged
path: backend/target/coverage-reports
retention-days: 7
lint-frontend:
name: Lint (Frontend)
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
runs-on: ubuntu-24.04
steps:
- uses: bcgov/action-test-and-analyse@87f88c90526b8b05cea760492ff33db4ba6e271b # v1.6.0
with:
commands: |
npm ci
npm run lint || true
dir: frontend
node_version: "20"
# Only use triggers for PRs
triggers: ${{ github.event_name == 'pull_request' && '("frontend/")' || '' }}
tests-frontend:
name: Tests (Frontend)
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
runs-on: ubuntu-24.04
container:
image: mcr.microsoft.com/playwright:v1.59.1-noble
steps:
- name: Fix safe.directory for GitHub Actions
run: git config --global --add safe.directory /__w/nr-silva/nr-silva
- name: Install unzip
run: |
apt-get update
apt-get install -y unzip
- uses: bcgov/action-test-and-analyse@87f88c90526b8b05cea760492ff33db4ba6e271b # v1.6.0
env:
VITE_ZONE: test
VITE_USER_POOLS_ID: ${{ vars.VITE_USER_POOLS_ID }}
VITE_USER_POOLS_WEB_CLIENT_ID: ${{ vars.VITE_USER_POOLS_WEB_CLIENT_ID }}
VITE_BACKEND_URL: http://localhost:8080
TEST_BCEID_USERNAME: ${{ secrets.TEST_BCEID_USERNAME }}
TEST_BCEID_PASSWORD: ${{ secrets.TEST_BCEID_PASSWORD }}
with:
commands: |
npm ci
npx playwright install-deps
npx playwright install
npm run coverage
dir: frontend
node_version: "24"
sonar_args: >
-Dsonar.organization=bcgov-sonarcloud
-Dsonar.projectKey=nr-silva-frontend
-Dsonar.javascript.lcov.reportPaths=.nyc_output/coverage/lcov.info
-Dsonar.typescript.tsconfigPaths=tsconfig.json
-Dsonar.sources=src/
-Dsonar.exclusions=src/__test__/**,src/__e2e__/**,src/amplifyconfiguration.*,src/**/*.scss,src/**/*.css,src/**/*.d.*,src/setupTests.*
-Dsonar.tests=src/__test__/,src/__e2e__/
-Dsonar.project.monorepo.enabled=true
sonar_token: ${{ secrets.SONAR_TOKEN_FRONTEND }}
# Only use triggers for PRs
triggers: ${{ github.event_name == 'pull_request' && '("frontend/")' || '' }}
# https://github.com/marketplace/actions/aqua-security-trivy
trivy:
name: Trivy Security Scan
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
permissions:
security-events: write
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- name: Run Trivy vulnerability scanner in repo mode
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
format: "sarif"
output: "trivy-results.sarif"
trivyignores: ".trivyignore"
skip-dirs: "common/postgis-playground"
ignore-unfixed: true
scan-type: "fs"
scanners: "vuln,secret,misconfig"
severity: "CRITICAL,HIGH"
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: "trivy-results.sarif"
# ==========================================================================
# WARNING: This job acts as the required merge gate for this workflow.
# If you add a new job to this workflow, you MUST add its ID to the 'needs'
# array below, otherwise its failure or cancellation will not block the PR!
# ==========================================================================
results:
name: Analysis Results
needs: [lint-frontend, tests-frontend, tests-backend-oracle, tests-backend-postgres, combine-backend-coverage] # Include trivy when/if it gets back to being reliable
if: always()
runs-on: ubuntu-24.04
timeout-minutes: 1
steps:
- name: Log Job Results Context
run: |
echo "=== Upstream Job Statuses ==="
echo '${{ toJson(needs) }}'
- name: Evaluate Overall Status
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: |
echo "❌ Critical Check Failure: At least one required job has failed or was cancelled."
exit 1
- name: Success Message
run: echo "✅ All critical checks passed or were intentionally skipped!"