Skip to content

Commit ee2a286

Browse files
NUTCH-3186 Split SonarQube workflow in unprivileged build and privileged analysis part (#940)
* NUTCH-3186 Split SonarQube workflow in unprivileged build and privileged analysis part - Cache / upload in master / PR ci build: - build artifacts (class files and dependency jars) - coverage reports - Do not run builds or tests in "sonarcloud" workflow - Download cached artifacts and call Sonarcloud scan - Do not clean before running integration tests (protocol and indexer) to avoid that test results are removed * NUTCH-3186 Split SonarQube workflow in unprivileged build and privileged analysis part - Fix yamllint error * NUTCH-3186 Split SonarQube workflow in unprivileged build and privileged analysis part - Allow checkout on PR branch in sonarcloud workflow * NUTCH-3186 Split SonarQube workflow in unprivileged build and privileged analysis part - Fix yamllint error
1 parent 545362c commit ee2a286

2 files changed

Lines changed: 55 additions & 19 deletions

File tree

‎.github/workflows/master-build.yml‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ concurrency:
2525
group: master-build-${{ github.ref }}
2626
cancel-in-progress: true
2727

28+
# Explicitly drop all permissions.
29+
# Permissions will be granted to individual jobs as needed.
30+
permissions: {}
31+
2832
# Java Version Strategy:
2933
# - Requires Java 17+ to build, test, and run (Hadoop 3.5+ client + JUnit 6).
3034
# - Default bytecode: javac.version=17 (see default.properties).
@@ -247,11 +251,14 @@ jobs:
247251
# run indexer integration tests when indexer plugin files change (Docker required, ubuntu-latest only)
248252
- name: test indexer integration
249253
if: ${{ steps.filter.outputs.indexer_plugins == 'true' && matrix.os == 'ubuntu-latest' }}
250-
run: ant clean test-indexer-integration -buildfile build.xml
254+
run: ant test-indexer-integration -buildfile build.xml
251255
# run protocol integration tests when protocol plugin files change (Docker required, ubuntu-latest only)
252256
- name: test protocol integration
253257
if: ${{ steps.filter.outputs.protocol_plugins == 'true' && matrix.os == 'ubuntu-latest' }}
254-
run: ant clean test-protocol-integration -buildfile build.xml
258+
run: ant test-protocol-integration -buildfile build.xml
259+
- name: Generate JaCoCo XML report
260+
run: ant jacoco-report -buildfile build.xml
261+
continue-on-error: true
255262
- name: Check for test results
256263
id: check_tests
257264
if: always() && matrix.os == 'ubuntu-latest'
@@ -263,6 +270,20 @@ jobs:
263270
else
264271
echo "has_results=false" >> $GITHUB_OUTPUT
265272
fi
273+
- name: Upload Build and Test Artifacts (Binaries)
274+
uses: actions/upload-artifact@v7
275+
if: always() && matrix.os == 'ubuntu-latest' && matrix.java == '17' && steps.check_tests.outputs.has_results == 'true'
276+
with:
277+
name: build-artifacts-${{ matrix.os }}-jdk${{ matrix.java }}
278+
path: |
279+
# core class files
280+
./build/classes/**/*.class
281+
# plugin and test class files
282+
./build/**/classes/**/*.class
283+
# dependencies
284+
./build/lib/*.jar
285+
./build/test/lib/*.jar
286+
retention-days: 1
266287
- name: Upload Test Report
267288
uses: actions/upload-artifact@v7
268289
if: always() && matrix.os == 'ubuntu-latest' && matrix.java == '17' && steps.check_tests.outputs.has_results == 'true'

‎.github/workflows/sonarcloud.yml‎

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,30 @@ on:
1919
workflows: [master pull request ci]
2020
types: [completed]
2121

22+
# Explicitly drop all permissions.
23+
# Permissions will be granted to individual jobs as needed.
24+
permissions: {}
25+
2226
concurrency:
2327
group: sonarcloud-${{ github.event.workflow_run.pull_requests[0].number || github.event.workflow_run.head_sha }}
2428
cancel-in-progress: true
2529

2630
jobs:
27-
analysis:
28-
if: github.event.workflow_run.conclusion == 'success'
31+
# WARNING: this job runs with access to repository secrets: do not execute untrusted code here.
32+
# It is triggered after the Build workflow completes; avoid running any code from the pull request itself.
33+
sonarcloud-scan:
34+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
2935
runs-on: ubuntu-latest
36+
3037
steps:
3138
- uses: actions/checkout@v7
3239
with:
3340
repository: ${{ github.event.workflow_run.head_repository.full_name }}
3441
ref: ${{ github.event.workflow_run.head_sha }}
35-
fetch-depth: 0
42+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
43+
allow-unsafe-pr-checkout: true # Explicitely allow (no code is compiled or run in this workflow)
44+
persist-credentials: false
45+
3646
- name: Fetch target branch for PR analysis
3747
if: github.event.workflow_run.event == 'pull_request'
3848
run: |
@@ -43,16 +53,17 @@ jobs:
4353
with:
4454
java-version: '17'
4555
distribution: 'temurin'
46-
- name: Cache Ivy dependencies
47-
uses: actions/cache@v6
48-
with:
49-
path: ~/.ivy2/cache
50-
key: ${{ runner.os }}-ivy-${{ hashFiles('ivy/ivy.xml', 'src/plugin/**/ivy.xml') }}
51-
restore-keys: |
52-
${{ runner.os }}-ivy-
53-
- name: Compile (no tests)
54-
run: ant compile compile-plugins resolve-test -buildfile build.xml
56+
5557
# Coverage and JUnit XML come only from the master-build Ubuntu JDK 17 matrix job.
58+
- name: Download Binary Artifacts (Ubuntu JDK 17)
59+
uses: dawidd6/action-download-artifact@v21
60+
with:
61+
name: build-artifacts-ubuntu-latest-jdk17
62+
workflow: master-build.yml
63+
run_id: ${{ github.event.workflow_run.id }}
64+
path: ./build/
65+
continue-on-error: true
66+
5667
- name: Download coverage data (Ubuntu JDK 17)
5768
uses: dawidd6/action-download-artifact@v21
5869
with:
@@ -61,22 +72,24 @@ jobs:
6172
run_id: ${{ github.event.workflow_run.id }}
6273
path: ./build/coverage/
6374
continue-on-error: true
75+
6476
- name: Download test reports (Ubuntu JDK 17)
6577
uses: dawidd6/action-download-artifact@v21
6678
with:
6779
name: junit-test-results-ubuntu-latest-jdk17
6880
workflow: master-build.yml
6981
run_id: ${{ github.event.workflow_run.id }}
70-
path: ./build/test-jdk17/
82+
path: |
83+
./build/test/TEST-*.xml
84+
./build/**/test/TEST-*.xml
7185
continue-on-error: true
86+
7287
- name: Flatten test reports (JDK 17 only)
7388
run: |
7489
mkdir -p ./build/test-reports
75-
find ./build/test-jdk17 -name 'TEST-*.xml' -exec cp {} ./build/test-reports/ \; 2>/dev/null || true
76-
continue-on-error: true
77-
- name: Generate JaCoCo XML report
78-
run: ant jacoco-report -buildfile build.xml
90+
find ./build/test ./build/*/test/ -name 'TEST-*.xml' -exec cp {} ./build/test-reports/ \; 2>/dev/null || true
7991
continue-on-error: true
92+
8093
- name: Resolve PR number
8194
id: pr
8295
run: |
@@ -109,6 +122,7 @@ jobs:
109122
fi
110123
env:
111124
GH_TOKEN: ${{ github.token }}
125+
112126
- name: SonarCloud Scan (PR)
113127
if: steps.pr.outputs.is_pr == 'true'
114128
uses: SonarSource/sonarqube-scan-action@713881670b6b3676cda39549040e2d88c70d582e
@@ -120,6 +134,7 @@ jobs:
120134
env:
121135
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
122136
SONAR_HOST_URL: https://sonarcloud.io
137+
123138
- name: SonarCloud Scan (branch)
124139
if: steps.pr.outputs.is_pr == 'false' && steps.pr.outputs.skip != 'true'
125140
uses: SonarSource/sonarqube-scan-action@713881670b6b3676cda39549040e2d88c70d582e

0 commit comments

Comments
 (0)