-
Notifications
You must be signed in to change notification settings - Fork 0
237 lines (200 loc) · 6.91 KB
/
Copy pathci.yml
File metadata and controls
237 lines (200 loc) · 6.91 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
name: CI
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
permissions:
contents: read
checks: write
security-events: write
env:
JAVA_VERSION: '21'
MAVEN_OPTS: '-Xmx1024m'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: temurin
cache: maven
- name: Build & Unit Tests
run: ./mvnw -B clean verify -DskipITs
- name: Publish Test Results
uses: dorny/test-reporter@v1
if: always()
with:
name: Unit Tests
path: '**/target/surefire-reports/TEST-*.xml'
reporter: java-junit
integration-tests:
runs-on: ubuntu-latest
needs: build
# TODO: Remove continue-on-error once TestContainers tests are verified green in CI
continue-on-error: true
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: temurin
cache: maven
- name: Integration Tests
# -Dsurefire.skip skips unit tests (already ran in build job)
# Only examples/testing has *IT.java files (TestContainers-based)
run: ./mvnw -B verify -pl examples/testing -Dsurefire.skip=true
- name: Publish Integration Test Results
uses: dorny/test-reporter@v1
if: always()
with:
name: Integration Tests
path: '**/target/failsafe-reports/TEST-*.xml'
reporter: java-junit
quality-gates:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: temurin
cache: maven
- name: Static Analysis (SpotBugs + Checkstyle + PMD)
run: |
./mvnw -B verify -Psecurity-scan-quick -DskipTests || {
echo "=== PMD Violations ==="
find . -path "*/target/pmd.xml" -exec python3 -c "
import xml.etree.ElementTree as ET, sys
tree = ET.parse(sys.argv[1])
ns = {'p': 'http://pmd.sourceforge.net/report/2.0.0'}
for f in tree.findall('.//p:file', ns):
for v in f.findall('p:violation', ns):
print(f'{f.get(\"name\")}:{v.get(\"beginline\")} [{v.get(\"rule\")}] {v.text.strip()}')
" {} \;
exit 1
}
- name: JaCoCo Coverage Report
run: ./mvnw -B verify jacoco:report-aggregate
- name: Check Coverage Threshold
run: ./mvnw -B jacoco:check
dependency-scan:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: temurin
cache: maven
- name: OWASP Dependency-Check
run: >
./mvnw -B dependency-check:aggregate
-Dowasp.failBuildOnCVSS=${{ vars.OWASP_CVSS_THRESHOLD || '7' }}
${{ secrets.NVD_API_KEY && format('-DnvdApiKey={0}', secrets.NVD_API_KEY) || '' }}
continue-on-error: true
id: owasp
- name: Upload OWASP SARIF
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: target/dependency-check/dependency-check-report.sarif
category: owasp-dependency-check
continue-on-error: true
- name: Upload OWASP HTML Report
uses: actions/upload-artifact@v4
if: always()
with:
name: owasp-dependency-check-report
path: target/dependency-check/dependency-check-report.html
- name: Warn on OWASP findings
if: steps.owasp.outcome == 'failure'
run: |
echo "::warning::OWASP Dependency-Check found vulnerabilities above CVSS threshold — review the uploaded report"
container-scan:
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main' || github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: temurin
cache: maven
- name: Build JAR
run: ./mvnw -B package -pl examples/restful-api -am -DskipTests
- name: Build Docker Image
run: docker build -t java-template-api:${{ github.sha }} -f examples/restful-api/Dockerfile examples/restful-api
- name: Trivy Vulnerability Scan
uses: aquasecurity/trivy-action@v0.35.0
with:
image-ref: java-template-api:${{ github.sha }}
format: sarif
output: trivy-results.sarif
severity: CRITICAL,HIGH
exit-code: '1'
continue-on-error: true
id: trivy
- name: Upload Trivy SARIF
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: trivy-results.sarif
category: trivy-container-scan
- name: Trivy Table Report
uses: aquasecurity/trivy-action@v0.35.0
if: always()
with:
image-ref: java-template-api:${{ github.sha }}
format: table
severity: CRITICAL,HIGH,MEDIUM
- name: Warn on Trivy findings
if: steps.trivy.outcome == 'failure'
run: |
echo "::warning::Trivy found vulnerabilities in container image"
snyk-scan:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main'
continue-on-error: true # Don't block pipeline if Snyk is unconfigured
steps:
- uses: actions/checkout@v4
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/maven@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high --sarif-file-output=snyk-results.sarif
continue-on-error: true
- name: Upload Snyk SARIF
uses: github/codeql-action/upload-sarif@v3
if: always() && hashFiles('snyk-results.sarif') != ''
with:
sarif_file: snyk-results.sarif
category: snyk-dependency-scan
docker:
runs-on: ubuntu-latest
needs: [ quality-gates, dependency-scan, container-scan ]
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: temurin
cache: maven
- name: Build JAR
run: ./mvnw -B package -pl examples/restful-api -am -DskipTests
- name: Build Docker Image
run: docker build -t java-template-api:${{ github.sha }} -f examples/restful-api/Dockerfile examples/restful-api