Skip to content

Commit 022479e

Browse files
committed
ci(workflows): improve security scanning and deploy workflows
- Integrate Trivy vulnerability scanning into maven-build workflow - Add PR comments with security scan results for pull requests - Upload SARIF to GitHub Security tab only on push to main - Fix SonarCloud conditional to skip gracefully when token missing - Add timeout and remove unused env vars in build workflow - Secure maven-deploy credentials using heredoc with env vars - Add batch mode flags and skip tests during deploy - Update maven-help-plugin to 3.5.1 - Remove redundant trivy.yml workflow
1 parent 3e42245 commit 022479e

File tree

3 files changed

+111
-44
lines changed

3 files changed

+111
-44
lines changed

.github/workflows/maven-build.yml

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@ on:
1414
env:
1515
JAVA_VERSION: '25'
1616
JAVA_DISTRO: 'zulu'
17-
GRAAL_VERSION: '25.0.1'
18-
GRAAL_DISTRIBUTION: 'graalvm-community'
17+
18+
permissions:
19+
contents: read
20+
security-events: write
21+
pull-requests: write
22+
1923
jobs:
2024
build:
2125
name: Build and analyze
2226
runs-on: ubuntu-latest
27+
timeout-minutes: 30
2328
steps:
24-
- uses: actions/checkout@v4
29+
- name: 'Checkout code'
30+
uses: actions/checkout@v4
2531

2632
- name: 'Set up JDK'
2733
uses: actions/setup-java@v5
@@ -41,9 +47,90 @@ jobs:
4147
- name: Grant execute permission to MVN Wrapper
4248
run: chmod +x ./mvnw
4349

44-
- name: Build and analyze
50+
- name: Build with Maven
51+
run: ./mvnw -ntp -B verify
52+
53+
- name: Analyze with SonarCloud
4554
env:
46-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4756
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
48-
SONAR_SKIP: ${{ secrets.SONAR_TOKEN && 'false' || 'true' }} # skip analysis if token is missing
49-
run: ./mvnw -ntp -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=streamthoughts_jikkou
57+
run: |
58+
if [ -n "$SONAR_TOKEN" ]; then
59+
./mvnw -ntp -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=streamthoughts_jikkou
60+
else
61+
echo "Skipping SonarCloud analysis (SONAR_TOKEN not set)"
62+
fi
63+
64+
- name: Run Trivy vulnerability scanner (SARIF)
65+
if: github.event_name == 'push'
66+
uses: aquasecurity/trivy-action@0.28.0
67+
with:
68+
scan-type: 'fs'
69+
scan-ref: '.'
70+
ignore-unfixed: true
71+
format: 'sarif'
72+
output: 'trivy-results.sarif'
73+
severity: 'CRITICAL,HIGH'
74+
75+
- name: Upload Trivy scan results to GitHub Security tab
76+
if: github.event_name == 'push'
77+
uses: github/codeql-action/upload-sarif@v3
78+
with:
79+
sarif_file: 'trivy-results.sarif'
80+
81+
- name: Run Trivy vulnerability scanner (Table)
82+
if: github.event_name == 'pull_request'
83+
uses: aquasecurity/trivy-action@0.28.0
84+
with:
85+
scan-type: 'fs'
86+
scan-ref: '.'
87+
ignore-unfixed: true
88+
format: 'table'
89+
output: 'trivy-results.txt'
90+
severity: 'CRITICAL,HIGH'
91+
92+
- name: Add vulnerability report to PR
93+
if: github.event_name == 'pull_request'
94+
uses: actions/github-script@v7
95+
with:
96+
script: |
97+
const fs = require('fs');
98+
const trivyResults = fs.readFileSync('trivy-results.txt', 'utf8');
99+
100+
let body = '## Security Scan Results\n\n';
101+
102+
if (trivyResults.trim().length === 0) {
103+
body += 'No vulnerabilities found with CRITICAL or HIGH severity.\n';
104+
} else {
105+
body += 'Vulnerabilities detected:\n\n';
106+
body += '```\n' + trivyResults + '\n```\n';
107+
}
108+
109+
body += '\n\n<sub>Scanned by [Trivy](https://github.com/aquasecurity/trivy)</sub>';
110+
111+
const { data: comments } = await github.rest.issues.listComments({
112+
owner: context.repo.owner,
113+
repo: context.repo.repo,
114+
issue_number: context.issue.number,
115+
});
116+
117+
const botComment = comments.find(comment =>
118+
comment.user.type === 'Bot' &&
119+
comment.body.includes('Security Scan Results')
120+
);
121+
122+
if (botComment) {
123+
await github.rest.issues.updateComment({
124+
owner: context.repo.owner,
125+
repo: context.repo.repo,
126+
comment_id: botComment.id,
127+
body: body
128+
});
129+
} else {
130+
await github.rest.issues.createComment({
131+
owner: context.repo.owner,
132+
repo: context.repo.repo,
133+
issue_number: context.issue.number,
134+
body: body
135+
});
136+
}

.github/workflows/maven-deploy.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,26 @@ jobs:
4646

4747
- name: 'Set env VERSION'
4848
run: |
49-
VERSION=$(./mvnw org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout)
49+
VERSION=$(./mvnw org.apache.maven.plugins:maven-help-plugin:3.5.1:evaluate -Dexpression=project.version -q -DforceStdout)
5050
echo "VERSION=$VERSION" >> $GITHUB_ENV
5151
5252
- name: 'Set up Maven settings'
5353
run: |
54-
echo "<settings><interactiveMode>false</interactiveMode><servers><server><id>sonatype-central</id><username>${{ secrets.OSSRH_USERNAME }}</username><password>${{ secrets.OSSRH_PASSWORD }}</password></server></servers></settings>" > ./settings.xml
54+
cat > ./settings.xml << 'EOF'
55+
<settings>
56+
<interactiveMode>false</interactiveMode>
57+
<servers>
58+
<server>
59+
<id>sonatype-central</id>
60+
<username>${env.OSSRH_USERNAME}</username>
61+
<password>${env.OSSRH_PASSWORD}</password>
62+
</server>
63+
</servers>
64+
</settings>
65+
EOF
66+
env:
67+
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
68+
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
5569

5670
- name: 'Deploy Maven Central'
57-
run: |
58-
./mvnw -s ./settings.xml deploy -Possrh
71+
run: ./mvnw -s ./settings.xml -B -ntp deploy -DskipTests -Possrh

.github/workflows/trivy.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)