Skip to content

Commit 51b1d5f

Browse files
SONARJAVA-5850 Migrate Windows Build from Cirrus to GitHub action (#5346)
1 parent 03bdc73 commit 51b1d5f

File tree

6 files changed

+105
-57
lines changed

6 files changed

+105
-57
lines changed

.cirrus.yml

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ log_develocity_url_script: &log_develocity_url_script |
5151

5252
common_build_definition: &COMMON_BUILD_DEFINITION
5353
eks_container:
54-
<<: *CONTAINER_DEFINITION
55-
image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j23-latest
54+
<<: *CONTAINER_WITH_DOCKER_DEFINITION
5655
cpu: 4
5756
memory: 4G
5857
env:
@@ -63,6 +62,7 @@ common_build_definition: &COMMON_BUILD_DEFINITION
6362
SONAR_HOST_URL: https://next.sonarqube.com/sonarqube
6463
#allow deployment of pull request artifacts to repox
6564
DEPLOY_PULL_REQUEST: true
65+
JAVA_HOME: /opt/java/openjdk-latest
6666
maven_cache:
6767
folder: ${CIRRUS_WORKING_DIR}/.m2/repository
6868

@@ -86,7 +86,33 @@ build_task:
8686
build_script:
8787
- *log_develocity_url_script
8888
- source cirrus-env BUILD
89-
- regular_mvn_build_deploy_analyze -Dmaven.test.skip=true -Dsonar.skip=true -pl '!java-checks-test-sources/default,!java-checks-test-sources/aws'
89+
- regular_mvn_build_deploy_analyze -Dmaven.test.skip=true -Dsonar.skip=true -pl '!java-checks-test-sources/default,!java-checks-test-sources/aws,!java-checks-test-sources/spring-web-4.0'
90+
cleanup_before_cache_script: cleanup_maven_repository
91+
92+
sonar_shadow_scan_and_issue_replication_task:
93+
<<: *COMMON_BUILD_DEFINITION
94+
depends_on:
95+
- build
96+
# Only run when triggered by the cirrus-ci cron job named "nightly"
97+
only_if: $CIRRUS_CRON == "nightly"
98+
env:
99+
SONAR_PROJECT_KEY: "org.sonarsource.java:java"
100+
SHADOW_ORGANIZATION: "sonarsource"
101+
SHADOW_PROJECT_KEY: "SonarSource_sonar-java"
102+
# to replicate issue states from next
103+
SONAR_TOKEN: VAULT[development/kv/data/next data.token]
104+
SONAR_HOST_URL: https://next.sonarqube.com/sonarqube
105+
matrix:
106+
- name: "sonarcloud.io"
107+
SHADOW_SONAR_TOKEN: VAULT[development/kv/data/sonarcloud data.token]
108+
SHADOW_SONAR_HOST_URL: "https://sonarcloud.io"
109+
- name: "sonarqube.us"
110+
SHADOW_SONAR_TOKEN: VAULT[development/kv/data/sonarqube-us data.token]
111+
SHADOW_SONAR_HOST_URL: "https://sonarqube.us"
112+
build_and_shadow_scan_script:
113+
- *log_develocity_url_script
114+
- source cirrus-env BUILD
115+
- ./shadow-scan-and-issue-replication.sh -Dsonar.analysisCache.enabled=true -Dsonar.sca.exclusions="**/test/files/**, **/test/resources/**, its/plugin/projects/**, java-checks-test-sources/**, its/sources/**,"
90116
cleanup_before_cache_script: cleanup_maven_repository
91117

92118
# Migrated to GHA.
@@ -96,36 +122,14 @@ test_analyze_task:
96122
- *log_develocity_url_script
97123
- source cirrus-env BUILD
98124
# ignore duplications in the SE engine plugin, as it will be moved away from sonar-java at some point
99-
- PULL_REQUEST_SHA=$GIT_SHA1 regular_mvn_build_deploy_analyze -P-deploy-sonarsource,-release,-sign -Dmaven.deploy.skip=true -Dsonar.analysisCache.enabled=true -Dsonar.cpd.exclusions=java-symbolic-execution/**
125+
- PULL_REQUEST_SHA=$GIT_SHA1 regular_mvn_build_deploy_analyze -P-deploy-sonarsource,-release,-sign -Dmaven.deploy.skip=true -Dsonar.analysisCache.enabled=true -Dsonar.sca.exclusions="**/test/files/**, **/test/resources/**, its/plugin/projects/**, java-checks-test-sources/**, its/sources/**,"
100126
- cd docs/java-custom-rules-example
101127
- mvn clean package -f pom_SQ_10_6_LATEST.xml --batch-mode
102128
- cd "${CIRRUS_WORKING_DIR}"
103129
- ./check-license-compliance.sh
104130
cleanup_before_cache_script: cleanup_maven_repository
105131

106-
ws_scan_task:
107-
<<: *ONLY_SONARSOURCE_QA
108-
eks_container:
109-
<<: *CONTAINER_DEFINITION
110-
image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j17-latest
111-
cpu: 4
112-
memory: 4G
113-
# run only on master and long-term branches
114-
only_if: $CIRRUS_USER_COLLABORATOR == 'true' && ($CIRRUS_BRANCH == "master" || $CIRRUS_BRANCH =~ "branch-.*" || $CIRRUS_BRANCH =~ "mend-.*")
115-
env:
116-
WS_APIKEY: VAULT[development/kv/data/mend data.apikey]
117-
maven_cache:
118-
folder: ${CIRRUS_WORKING_DIR}/.m2/repository
119-
whitesource_script:
120-
- source cirrus-env QA
121-
- source set_maven_build_version $BUILD_NUMBER
122-
- mvn clean install --batch-mode -Dmaven.test.skip=true -pl '!java-checks-test-sources,!java-checks-test-sources/default,!java-checks-test-sources/aws,!java-checks-test-sources/spring-3.2'
123-
- source ws_scan.sh
124-
allow_failures: "true"
125-
always:
126-
ws_artifacts:
127-
path: "whitesource/**/*"
128-
132+
# Migrated to GHA.
129133
qa_os_win_task:
130134
ec2_instance:
131135
image: base-windows-jdk21-v*
@@ -146,13 +150,19 @@ plugin_qa_task:
146150
- build
147151
<<: *ONLY_SONARSOURCE_QA
148152
eks_container:
149-
<<: *CONTAINER_DEFINITION
150-
image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j17-latest
153+
<<: *CONTAINER_WITH_DOCKER_DEFINITION
151154
cpu: 14
152-
memory: 6G
155+
memory: 16G
153156
<<: *ORCHESTRATOR_CACHE_PREPARATION_DEFINITION
154-
orchestrator_LATEST_RELEASE_cache:
155-
<<: *ORCHESTRATOR_CACHE_ELEMENTS_DEFINITION
157+
matrix:
158+
- env:
159+
SQ_VERSION: LATEST_RELEASE
160+
orchestrator_LATEST_RELEASE_cache:
161+
<<: *ORCHESTRATOR_CACHE_ELEMENTS_DEFINITION
162+
- env:
163+
SQ_VERSION: DEV
164+
orchestrator_DEV_cache:
165+
<<: *ORCHESTRATOR_CACHE_ELEMENTS_DEFINITION
156166

157167
maven_cache:
158168
folder: ${CIRRUS_WORKING_DIR}/.m2/repository
@@ -163,7 +173,7 @@ plugin_qa_task:
163173
- source cirrus-env QA
164174
- source set_maven_build_version $BUILD_NUMBER
165175
- cd its/plugin
166-
- mvn package --batch-mode -Pit-plugin -Dsonar.runtimeVersion=LATEST_RELEASE[2025.1] -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dparallel=classes -DuseUnlimitedThreads=true
176+
- mvn package --batch-mode -Pit-plugin -Dsonar.runtimeVersion=${SQ_VERSION} -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dparallel=classes -DuseUnlimitedThreads=true
167177
cleanup_before_cache_script: cleanup_maven_repository
168178

169179
# Migrated to GHA.
@@ -172,12 +182,13 @@ sanity_task:
172182
- build
173183
<<: *ONLY_SONARSOURCE_QA
174184
eks_container:
175-
<<: *CONTAINER_DEFINITION
176-
image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j23-latest
185+
<<: *CONTAINER_WITH_DOCKER_DEFINITION
177186
cpu: 4
178-
memory: 4G
187+
memory: 16G
179188
maven_cache:
180189
folder: ${CIRRUS_WORKING_DIR}/.m2/repository
190+
env:
191+
JAVA_HOME: /opt/java/openjdk-latest
181192
sanity_script:
182193
- *log_develocity_url_script
183194
- source cirrus-env QA
@@ -194,10 +205,9 @@ ruling_task:
194205
- build
195206
<<: *ONLY_SONARSOURCE_QA
196207
eks_container:
197-
<<: *CONTAINER_DEFINITION
198-
image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j17-latest
208+
<<: *CONTAINER_WITH_DOCKER_DEFINITION
199209
cpu: 14
200-
memory: 6G
210+
memory: 16G
201211
maven_cache:
202212
folder: ${CIRRUS_WORKING_DIR}/.m2/repository
203213
<<: *ORCHESTRATOR_CACHE_PREPARATION_DEFINITION
@@ -215,7 +225,7 @@ ruling_task:
215225
- source cirrus-env QA
216226
- source set_maven_build_version $BUILD_NUMBER
217227
- cd its/ruling
218-
- mvn package --batch-mode "-Pit-ruling,$PROFILE" -Dsonar.runtimeVersion=LATEST_RELEASE[2025.1] -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dparallel=methods -DuseUnlimitedThreads=true
228+
- mvn package --batch-mode "-Pit-ruling,$PROFILE" -Dsonar.runtimeVersion=LATEST_RELEASE -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dparallel=methods -DuseUnlimitedThreads=true
219229
cleanup_before_cache_script: cleanup_maven_repository
220230
on_failure:
221231
actual_artifacts:
@@ -246,7 +256,7 @@ ruling_win_task:
246256
- init_git_submodules its/sources
247257
- git submodule update --init --recursive
248258
- cd its/ruling
249-
- mvn package --batch-mode "-Pit-ruling,$PROFILE" -Dsonar.runtimeVersion=LATEST_RELEASE[2025.1] -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dparallel=methods -DuseUnlimitedThreads=true
259+
- mvn package --batch-mode "-Pit-ruling,$PROFILE" -Dsonar.runtimeVersion=LATEST_RELEASE -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dparallel=methods -DuseUnlimitedThreads=true
250260
cleanup_before_cache_script: cleanup_maven_repository
251261

252262
# Migrated to GHA.
@@ -257,11 +267,11 @@ autoscan_task:
257267
eks_container:
258268
<<: *CONTAINER_WITH_DOCKER_DEFINITION
259269
# For now, this autoscan_task need to execute two mvn commands:
260-
# * The build of java-checks-test-sources module which requires Java 23.
261-
# * The tests using Orchestrator and SonarQube that, for now, fail to work using Java 23
262-
# This is why we have a local Dockerfile that provide the 2 versions of Java, 17 and 23.
270+
# * The build of java-checks-test-sources module which requires Java 24.
271+
# * The tests using Orchestrator and SonarQube that, for now, fail to work using Java 24
272+
# This is why we have a local Dockerfile that provide the 2 versions of Java, 17 and 24.
263273
cpu: 14
264-
memory: 6G
274+
memory: 16G
265275
maven_cache:
266276
folder: ${CIRRUS_WORKING_DIR}/.m2/repository
267277
<<: *ORCHESTRATOR_CACHE_PREPARATION_DEFINITION
@@ -272,9 +282,9 @@ autoscan_task:
272282
- source cirrus-env QA
273283
- source set_maven_build_version $BUILD_NUMBER
274284
- cd java-checks-test-sources
275-
- JAVA_HOME="${JAVA_LATEST_HOME}" mvn clean compile test-compile --batch-mode
285+
- JAVA_HOME=/opt/java/openjdk-latest mvn clean compile test-compile --batch-mode
276286
- cd ../its/autoscan
277-
- mvn clean package --batch-mode --errors --show-version --activate-profiles it-autoscan -Dsonar.runtimeVersion=LATEST_RELEASE[25.1] -Dmaven.test.redirectTestOutputToFile=false -Dparallel=methods -DuseUnlimitedThreads=true
287+
- mvn clean package --batch-mode --errors --show-version --activate-profiles it-autoscan -Dsonar.runtimeVersion=LATEST_RELEASE -Dmaven.test.redirectTestOutputToFile=false -Dparallel=methods -DuseUnlimitedThreads=true
278288
cleanup_before_cache_script: cleanup_maven_repository
279289
on_failure:
280290
actual_artifacts:
@@ -283,18 +293,17 @@ autoscan_task:
283293
promote_task:
284294
depends_on:
285295
- build
296+
- sonar_shadow_scan_and_issue_replication
286297
- test_analyze
287298
- qa_os_win
288299
- sanity
289300
- ruling
290301
- ruling_win
291302
- plugin_qa
292-
- ws_scan
293303
- autoscan
294304
<<: *ONLY_SONARSOURCE_QA
295305
eks_container:
296-
<<: *CONTAINER_DEFINITION
297-
image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j17-latest
306+
<<: *CONTAINER_WITH_DOCKER_DEFINITION
298307
cpu: 2
299308
memory: 1G
300309
env:

.github/workflows/build.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,42 @@ jobs:
271271
-Dmaven.test.redirectTestOutputToFile=false
272272
-Dparallel=methods
273273
-DuseUnlimitedThreads=true
274+
275+
qa-os-win:
276+
name: Build and Unit Test on Windows
277+
# No dependency on build step, because we do not need the build number.
278+
runs-on: github-windows-latest-m
279+
permissions:
280+
id-token: write # Required for Vault OIDC authentication
281+
contents: write # Required for repository access and tagging
282+
steps:
283+
- name: Config Git
284+
run: git config --global core.autocrlf input
285+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
286+
- uses: jdx/mise-action@5ac50f778e26fac95da98d50503682459e86d566 # v3.2.0
287+
with:
288+
version: 2025.7.12
289+
- name: Run Maven
290+
run: mvn clean verify --batch-mode
291+
292+
promote:
293+
needs:
294+
- build
295+
- ruling-qa
296+
- plugin-qa
297+
- sanity
298+
- test-analyze
299+
- autoscan
300+
- qa-os-win
301+
if: ${{ needs.build.outputs.deployed }}
302+
runs-on: github-ubuntu-latest-s # Public repo uses custom GitHub-hosted runners
303+
name: Promote
304+
permissions:
305+
id-token: write
306+
contents: write
307+
env:
308+
BUILD_NUMBER: ${{ needs.build.outputs.build-number }}
309+
steps:
310+
- uses: SonarSource/ci-github-actions/promote@v1
311+
with:
312+
promote-pull-request: true

java-checks-test-sources/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
<fileSeparator>/</fileSeparator>
4141
<pathSeparator>:${line.separator}</pathSeparator>
4242
<includeScope>test</includeScope>
43-
<!-- $$ to not evaluate M2_REPO now, this will become ${M2_REPO} in the output file -->
44-
<localRepoProperty>$${M2_REPO}</localRepoProperty>
43+
<localRepoProperty>M2_REPO</localRepoProperty>
4544
<outputEncoding>UTF-8</outputEncoding>
4645
<outputFile>${project.build.directory}/test-classpath.txt</outputFile>
4746
</configuration>

java-checks-test-sources/test-classpath-reader/src/main/java/org/sonar/java/test/classpath/TestClasspathUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ public static List<File> loadFromFile(String classpathTextFilePath) {
9696
String mavenRepository = findMavenLocalRepository(System::getenv, System::getProperty);
9797
try {
9898
String content = Files.readString(toPath(classpathTextFilePath), UTF_8);
99-
Arrays.stream(content.split(":"))
99+
// Split on ":", but not when it follows Windows drive letter (e.g. "C:\").
100+
Arrays.stream(content.split("(?<![A-Z]):"))
100101
.map(String::trim)
101102
.filter(line -> !line.isBlank())
102103
.map(TestClasspathUtils::fixSeparator)
103-
.map(line -> line.replace("${M2_REPO}", mavenRepository))
104+
.map(line -> line.replace("M2_REPO", mavenRepository))
104105
.map(Paths::get)
105106
.forEach(dependencyPath -> {
106107
if (!Files.exists(dependencyPath)) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
${M2_REPO}/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar:
1+
M2_REPO/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar:
22

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
${M2_REPO}/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar:
2-
${M2_REPO}/org/bad/luck/missing-artifact/666/missing-artifact-666.jar:
1+
M2_REPO/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar:
2+
M2_REPO/org/bad/luck/missing-artifact/666/missing-artifact-666.jar:

0 commit comments

Comments
 (0)