generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 13
457 lines (401 loc) · 14.8 KB
/
continuous-integration.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
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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
name: "Continuous Integration"
on:
pull_request:
branches: [ "main" ]
workflow_dispatch:
inputs:
commit:
# this commit is what is actually going to be checked out
description: "Commit SHA of the code to be built"
required: true
build-release-artifacts:
description: "Build Release Artifacts"
required: false
type: boolean
default: false
sign-release-artifacts:
description: "Sign Release Artifacts"
required: false
type: boolean
default: false
run-blackduck-scan:
description: "Run BlackDuck Scan"
required: false
type: boolean
default: false
run-security-rating:
description: "Run Security Rating"
required: false
type: boolean
default: false
env:
M2_ROOT: ~/.m2/repository
RELEASE_ARTIFACT_NAME: "release-artifacts"
SDK_M2_NAME: "sdk-m2" # used for the installed SDK modules within the runner's maven repository
SDK_M2_PATH: |
~/.m2/repository/com/sap/cloud/sdk/**
~/.m2/repository/archetype-catalog.xml
SDK_TARGETS_NAME: "sdk-targets" # used for the SDK's target directories
SDK_TARGETS_PATH: |
./**/target/**
# keep the following two variables in sync with our 'cache-maven-dependencies.yaml' workflow
MAVEN_CACHE_KEY: maven-dependencies
MAVEN_CACHE_DIR: ~/.m2
MVN_MULTI_THREADED_ARGS: --batch-mode --no-transfer-progress --fail-at-end --show-version --threads 1C
MVN_SINGLE_THREADED_ARGS: --batch-mode --no-transfer-progress --fail-at-end --show-version --threads 1
MVN_SKIP_CI_PLUGINS: -DskipFormatting -Denforcer.skip -Djacoco.skip -Dmdep.analyze.skip
jobs:
context:
name: "Collect Context"
outputs:
commit: ${{ steps.calculate-commit-sha.outputs.COMMIT }}
runs-on: ubuntu-latest
steps:
- name: "Calculate Commit SHA"
id: calculate-commit-sha
run: |
if [[ -n "${{ github.event.inputs.commit }}" ]]; then
echo "COMMIT=${{ github.event.inputs.commit }}" >> $GITHUB_OUTPUT
exit 0
fi
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "COMMIT=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
exit 0
fi
echo "Unable to determine commit SHA as the workflow was not triggered by a pull request and the commit input was not provided"
exit 1
check-formatting:
name: "Check Formatting"
needs: [ context ]
runs-on: ubuntu-latest
steps:
- name: "Checkout Repository"
uses: actions/checkout@v4
with:
ref: ${{ needs.context.outputs.commit }}
- name: "Setup Java"
uses: actions/setup-java@v4
with:
distribution: "sapmachine"
java-version: 17
- name: "Run Maven Plugins"
run: |
MVN_GOALS="\
net.revelc.code.formatter:formatter-maven-plugin:validate \
net.revelc.code:impsort-maven-plugin:check \
com.github.ekryd.sortpom:sortpom-maven-plugin:verify"
MVN_ARGS="${{ env.MVN_MULTI_THREADED_ARGS }} $MVN_GOALS"
echo "[DEBUG] Running Maven with following arguments: $MVN_ARGS"
mvn $MVN_ARGS
build:
name: "Build"
needs: [ context, check-formatting ]
runs-on: ubuntu-latest
steps:
- name: "Checkout repository"
uses: actions/checkout@v4
with:
ref: ${{ needs.context.outputs.commit }}
- name: "Setup java"
uses: actions/setup-java@v4
with:
distribution: "sapmachine"
java-version: 17
- name: "Restore Dependencies"
id: restore-dependencies
uses: actions/cache/restore@v4
with:
key: ${{ env.MAVEN_CACHE_KEY }}
path: ${{ env.MAVEN_CACHE_DIR }}
- name: "Build SDK"
run: |
MVN_ARGS="${{ env.MVN_MULTI_THREADED_ARGS }} install -DskipTests -DskipFormatting"
if [[ "${{ github.event.inputs.build-release-artifacts }}" == "true" ]]; then
echo "[DEBUG] Building release artifacts"
python .pipeline/scripts/generate-javadoc-sourcepath-properties.py
MVN_ARGS="$MVN_ARGS javadoc:aggregate -Pdocs"
fi
echo "[DEBUG] Running Maven with following arguments: $MVN_ARGS"
mvn $MVN_ARGS
if [[ "${{ github.event.inputs.build-release-artifacts }}" == "true" ]]; then
VERSION=$(cat latest.json | jq -r .version)
mkdir -p $HOME/.sdk-release
PYTHON_ARGS="--version $VERSION --path-prefix $HOME/.sdk-release/${{ env.RELEASE_ARTIFACT_NAME }}"
if [[ "${{ github.event.inputs.sign-release-artifacts }}" == "true" ]]; then
echo "[DEBUG] Signing release artifacts"
PYTHON_ARGS="$PYTHON_ARGS --with-signing"
fi
python .pipeline/scripts/generate-release-artifacts.py $PYTHON_ARGS
else
echo "[DEBUG] Skipping release artifact generation"
fi
- name: "Build Module Inventory"
run: >
python ./scripts/create_module_inventory_file.py
--sdk-root-directory ./
--output-file ./module-inventory.json
--script-config ./scripts/common/_maven_module/maven_module_reader_configuration.json
- name: "Verify Local Changes"
run: |
CHANGED_FILES="$(git --no-pager diff --name-only)"
if [[ ! -z "$CHANGED_FILES" ]]; then
echo "There are local changes in the following files:"
echo "$CHANGED_FILES"
echo "Printing the git diff:"
git --no-pager diff
exit 1
fi
- name: "Upload Release Artifacts"
if: ${{ github.event.inputs.build-release-artifacts == 'true' }}
uses: actions/upload-artifact@v4
with:
name: ${{ env.RELEASE_ARTIFACT_NAME }}
path: ~/.sdk-release/${{ env.RELEASE_ARTIFACT_NAME }}
retention-days: 1
- name: "Upload SDK M2"
uses: actions/upload-artifact@v4
with:
name: ${{ env.SDK_M2_NAME }}
path: ${{ env.SDK_M2_PATH }}
retention-days: 1
- name: "Upload SDK Targets"
uses: actions/upload-artifact@v4
with:
name: ${{ env.SDK_TARGETS_NAME }}
path: ${{ env.SDK_TARGETS_PATH }}
retention-days: 1
test:
name: "Test"
needs: [ context, build ]
runs-on: ubuntu-latest
steps:
- name: "Checkout repository"
uses: actions/checkout@v4
with:
ref: ${{ needs.context.outputs.commit }}
- name: "Setup java"
uses: actions/setup-java@v4
with:
distribution: "sapmachine"
java-version: 17
- name: "Restore Dependencies"
id: restore-dependencies
uses: actions/cache/restore@v4
with:
key: ${{ env.MAVEN_CACHE_KEY }}
path: ${{ env.M2_ROOT }}
- name: "Restore SDK M2"
uses: actions/download-artifact@v4
with:
name: ${{ env.SDK_M2_NAME }}
path: ${{ env.M2_ROOT }}
- name: "Restore SDK Targets"
uses: actions/download-artifact@v4
with:
name: ${{ env.SDK_TARGETS_NAME }}
- name: "Run Unit Tests"
run: |
MVN_ARGS="${{ env.MVN_SINGLE_THREADED_ARGS }} org.jacoco:jacoco-maven-plugin:prepare-agent surefire:test org.jacoco:jacoco-maven-plugin:report --fail-at-end"
echo "[DEBUG] Running Maven with arguments: $MVN_ARGS"
mvn $MVN_ARGS
- name: "Coverage Report"
run: python .pipeline/scripts/print-coverage.py --jacoco-report-pattern "**/target/site/jacoco/jacoco.csv"
static-code-analysis:
needs: [ context, build ]
runs-on: ubuntu-latest
strategy:
matrix:
task:
- {
"name": "Checkstyle",
"mvn_goal": "-P!build-test-modules org.apache.maven.plugins:maven-checkstyle-plugin:checkstyle",
"report": ".pipeline/scripts/print-checkstyle.py"
}
- {
"name": "PMD",
"mvn_goal": "org.apache.maven.plugins:maven-pmd-plugin:pmd",
"report": ".pipeline/scripts/print-pmd.py"
}
- {
"name": "Spotbugs",
"mvn_goal": "com.github.spotbugs:spotbugs-maven-plugin:spotbugs",
"report": ".pipeline/scripts/print-spotbugs.py"
}
name: "Run ${{ matrix.task.name }} Analysis"
steps:
- name: "Checkout repository"
uses: actions/checkout@v4
with:
ref: ${{ needs.context.outputs.commit }}
- name: "Setup java"
uses: actions/setup-java@v4
with:
distribution: "sapmachine"
java-version: 17
- name: "Restore Dependencies"
id: restore-dependencies
uses: actions/cache/restore@v4
with:
key: ${{ env.MAVEN_CACHE_KEY }}
path: ${{ env.M2_ROOT }}
- name: "Restore SDK M2"
uses: actions/download-artifact@v4
with:
name: ${{ env.SDK_M2_NAME }}
path: ${{ env.M2_ROOT }}
- name: "Restore SDK Targets"
uses: actions/download-artifact@v4
with:
name: ${{ env.SDK_TARGETS_NAME }}
- name: "Run ${{ matrix.task.name }} Analysis"
run: |
MVN_ARGS="${{ env.MVN_MULTI_THREADED_ARGS }} ${{ env.MVN_SKIP_CI_PLUGINS }} ${{ matrix.task.mvn_goal }}"
echo "[DEBUG] Running Maven with arguments: $MVN_ARGS"
mvn $MVN_ARGS
python ${{ matrix.task.report }}
code-ql:
name: "Run CodeQL Analysis"
needs: [ context ]
runs-on: ubuntu-latest
steps:
- name: "Checkout repository"
uses: actions/checkout@v4
with:
ref: ${{ needs.context.outputs.commit }}
- name: "Setup java"
uses: actions/setup-java@v4
with:
distribution: "sapmachine"
java-version: 17
- name: "Restore Dependencies"
id: restore-dependencies
uses: actions/cache/restore@v4
with:
key: ${{ env.MAVEN_CACHE_KEY }}
path: ${{ env.MAVEN_CACHE_DIR }}
- name: "Initialize CodeQL"
uses: github/codeql-action/init@v3
with:
languages: "java"
queries: security-extended
- name: "Build SDK"
run: |
MVN_ARGS="${{ env.MVN_MULTI_THREADED_ARGS }} install -Dmaven.test.skip=true ${{ env.MVN_SKIP_CI_PLUGINS }}"
echo "[DEBUG] Running Maven with arguments: $MVN_ARGS"
mvn $MVN_ARGS
- name: "Perform CodeQL Analysis"
uses: github/codeql-action/analyze@v3
with:
category: "/language:java"
test-archetypes:
runs-on: ubuntu-latest
needs: [ context, build ]
strategy:
matrix:
task:
- {
"archetype": "spring-boot3",
"javaVersion": 17,
"startCommand": "mvn spring-boot:run -B",
}
name: "Test ${{ matrix.task.archetype }} Archetype"
steps:
- name: "Setup java"
uses: actions/setup-java@v4
with:
distribution: "sapmachine"
java-version: 17
- name: "Restore Dependencies"
id: restore-dependencies
uses: actions/cache/restore@v4
with:
key: ${{ env.MAVEN_CACHE_KEY }}
path: ${{ env.MAVEN_CACHE_DIR }}
- name: "Restore SDK M2"
uses: actions/download-artifact@v4
with:
name: ${{ env.SDK_M2_NAME }}
path: ${{ env.M2_ROOT }}
- name: "Generate ${{ matrix.task.archetype }}"
run: >
mvn archetype:generate -B
-DarchetypeCatalog=local
-DarchetypeGroupId=com.sap.cloud.sdk.archetypes
-DarchetypeArtifactId=${{ matrix.task.archetype }}
-DgroupId=com.sap.test
-DartifactId=example-${{ matrix.task.archetype }}
-Dversion=1.0-SNAPSHOT
-Dpackage=com.sap.test
-Dhttp.keepAlive=false
- name: "Verify ${{ matrix.task.archetype }}"
working-directory: ./example-${{ matrix.task.archetype }}
run: >
mvn clean verify -B
-Dhttp.keepAlive=false
-Dmaven.test.skip=true
- name: "Test ${{ matrix.task.name }}"
working-directory: ./example-${{ matrix.task.archetype }}
run: mvn test -B -Dsurefire.logLevel='error'
- name: "Spotbugs ${{ matrix.task.archetype }}"
working-directory: ./example-${{ matrix.task.archetype }}
run: >
mvn com.github.spotbugs:spotbugs-maven-plugin:check -B
-Dhttp.keepAlive=false
-Dmaven.wagon.http.pool=false
- name: "Start ${{ matrix.task.archetype }}"
working-directory: ./example-${{ matrix.task.archetype }}/application
run: |
logFilePath=log.txt
${{ matrix.task.startCommand }} > $logFilePath 2>&1 &
if ! curl -s --retry 60 --retry-delay 3 --retry-all-errors http://127.0.0.1:8080/hello ; then
echo "Project generated from archetype '${{ matrix.task.archetype }}' failed to start locally."
cat $logFilePath
exit 1
fi
if ! grep -q "I am running!" $logFilePath; then
echo "Project generated from archetype '${{ matrix.task.archetype }}' started locally, but did not contain the expected log output."
cat $logFilePath
exit 1
fi
if grep -iq "caused by" $logFilePath; then
echo "Project generated from archetype '${{ matrix.task.archetype }}' started locally, but an unexpected error occurred."
cat $logFilePath
exit 1
fi
- name: "Verify .gitignore ${{ matrix.task.archetype }}"
working-directory: ./example-${{ matrix.task.archetype }}
run: |
if [[ ! -f .gitignore ]]; then
ls -lah
echo "Project generated from archetype '${{ matrix.task.archetype }}' does not contain a .gitignore file."
exit 1
fi
blackduck:
name: "Run BlackDuck Scan"
if: ${{ github.event.inputs.run-blackduck-scan == 'true' }}
needs: [ context ]
runs-on: ubuntu-latest
steps:
- name: "Checkout repository"
uses: actions/checkout@v4
with:
ref: ${{ needs.context.outputs.commit }}
- name: "Scan With Black Duck"
uses: ./.github/actions/scan-with-blackduck
with:
token: ${{ secrets.BLACKDUCK_TOKEN }}
security-rating:
name: "Run Security Rating"
if: ${{ github.event.inputs.run-security-rating == 'true' }}
needs: [ context ]
runs-on: ubuntu-latest
steps:
- name: "Checkout repository"
uses: actions/checkout@v4
with:
ref: ${{ needs.context.outputs.commit }}
- name: "Run FOSStars Rating"
uses: SAP/[email protected]
with:
report-branch: fosstars-report
token: ${{ github.token }}