Repository navigation
81 lines (71 loc) · 2.42 KB
/
Copy pathgithub-actions-build.yml
File metadata and controls
81 lines (71 loc) · 2.42 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
name: Java CI
# Trigger workflow on push or pull_request
# Note - the first pull_request from a forked repo will need to be given approval to run
on:
push:
pull_request:
workflow_dispatch: # Adds a "Run workflow" button in GitHub Actions
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0 # Required by SonarCloud for accurate blame & new code detection
- name: Set up JDK 8
uses: actions/setup-java@v6
with:
java-version: '8'
distribution: 'temurin'
cache: 'maven'
- name: Build Test and Verify for JDK8
run: mvn -B -U clean verify
- name: Set up JDK 17
uses: actions/setup-java@v6
with:
java-version: '17'
distribution: 'temurin'
- name: Build Test and Verify for JDK17
run: mvn -B -U clean verify
# Upload SBOM
- name: Upload SBOM as GitHub Artifact
uses: actions/upload-artifact@v7
with:
name: ${{ github.event.repository.name }}-sbom-${{ github.run_number }}
path: target/bom.json
overwrite: true
retention-days: 7
# Scan Project for vulnernabilities (Scanning the SBOM with trivy does not play nice with sonarcloud)
- name: Run Trivy vulnerability scanner
with:
scan-type: 'fs'
scan-ref: '.'
scanners: 'vuln'
format: 'sarif'
output: 'target/trivy-results.sarif'
# Upload sarif
- name: Upload Trivy sarif
uses: actions/upload-artifact@v7
with:
name: ${{ github.event.repository.name }}-trivy-sarif-${{ github.run_number }}
path: target/trivy-results.sarif
overwrite: true
retention-days: 7
# Sonar Scan
- name: SonarCloud Scan
run: |
if ["$SONAR_TOKEN" == ""]; then
echo "Sonar secure variables NOT available"
else
echo "Sonar secure variables ARE available"
mvn -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \
-Dsonar.projectKey="bordertech-java-common" \
-Dsonar.organization="bordertech-github" \
-Dsonar.host.url="https://sonarcloud.io" \
-Dsonar.qualitygate.wait=true \
-Dsonar.sarifReportPaths="target/trivy-results.sarif"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}