Skip to content

Commit 3e065b6

Browse files
SONARXML-252 Unify Platform Dogfooding of sonar-xml (#348)
1 parent 29fc3da commit 3e065b6

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

.cirrus.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ env:
1414
ARTIFACTORY_ACCESS_TOKEN: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-private-reader access_token]
1515
DEVELOCITY_TOKEN: VAULT[development/kv/data/develocity data.token]
1616
DEVELOCITY_ACCESS_KEY: develocity.sonar.build=${DEVELOCITY_TOKEN}
17+
SONAR_PROJECT_KEY: "org.sonarsource.xml:xml"
1718
# Use bash (instead of sh on linux or cmd.exe on windows)
1819
CIRRUS_SHELL: bash
1920

@@ -65,6 +66,35 @@ build_task:
6566
- regular_mvn_build_deploy_analyze
6667
cleanup_before_cache_script: cleanup_maven_repository
6768

69+
sonar_shadow_scan_and_issue_replication_task:
70+
depends_on:
71+
- build
72+
# Only run when triggered by the cirrus-ci cron job named "nightly"
73+
only_if: $CIRRUS_CRON == "nightly"
74+
eks_container:
75+
<<: *CONTAINER_DEFINITION
76+
cpu: 2
77+
memory: 2G
78+
env:
79+
SHADOW_ORGANIZATION: "sonarsource"
80+
SHADOW_PROJECT_KEY: "SonarSource_sonar-xml"
81+
# to replicate issue states from next
82+
SONAR_TOKEN: VAULT[development/kv/data/next data.token]
83+
SONAR_HOST_URL: https://next.sonarqube.com/sonarqube
84+
matrix:
85+
- name: "sonarcloud.io"
86+
SHADOW_SONAR_TOKEN: VAULT[development/kv/data/sonarcloud data.token]
87+
SHADOW_SONAR_HOST_URL: "https://sonarcloud.io"
88+
- name: "sonarqube.us"
89+
SHADOW_SONAR_TOKEN: VAULT[development/kv/data/sonarqube-us data.token]
90+
SHADOW_SONAR_HOST_URL: "https://sonarqube.us"
91+
maven_cache:
92+
folder: ${CIRRUS_WORKING_DIR}/.m2/repository
93+
build_script:
94+
- *log_develocity_url_script
95+
- ./shadow-scan-and-issue-replication.sh
96+
cleanup_before_cache_script: cleanup_maven_repository
97+
6898
ws_scan_task:
6999
depends_on:
70100
- build
@@ -159,6 +189,7 @@ ruling_win_task:
159189
promote_task:
160190
depends_on:
161191
- build
192+
- sonar_shadow_scan_and_issue_replication
162193
- build_win
163194
- ruling
164195
- ruling_win
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# IRIS: Issue Replication for Sonarqube
6+
IRIS_JAR_URL="${ARTIFACTORY_URL}/sonarsource-private-releases/com/sonarsource/iris/iris/\[RELEASE\]/iris-\[RELEASE\]-jar-with-dependencies.jar"
7+
IRIS_JAR_PATH="target/libs/iris.jar"
8+
9+
function build_and_analyze_the_project() {
10+
echo
11+
echo "===== Build and analyze the project targeting a shadow SonarQube instance"
12+
mvn \
13+
-Pcoverage \
14+
-Dmaven.test.redirectTestOutputToFile=false \
15+
-Dsonar.host.url="${SHADOW_SONAR_HOST_URL}" \
16+
-Dsonar.token="${SHADOW_SONAR_TOKEN}" \
17+
-Dsonar.organization="${SHADOW_ORGANIZATION}" \
18+
-Dsonar.projectKey="${SHADOW_PROJECT_KEY}" \
19+
-Dsonar.analysis.buildNumber="${BUILD_NUMBER}" \
20+
-Dsonar.analysis.repository="${GITHUB_REPO}" \
21+
--batch-mode --errors --show-version \
22+
verify sonar:sonar
23+
}
24+
25+
function download_iris() {
26+
echo
27+
echo "===== Download ${IRIS_JAR_URL}"
28+
mkdir -p target/libs
29+
curl --silent --fail-with-body --location --header "Authorization: Bearer ${ARTIFACTORY_PRIVATE_PASSWORD}" \
30+
--output "${IRIS_JAR_PATH}" "${IRIS_JAR_URL}"
31+
}
32+
33+
function run_iris() {
34+
local DRY_RUN="$1"
35+
java \
36+
-Diris.source.projectKey="${SONAR_PROJECT_KEY}" \
37+
-Diris.source.url="${SONAR_HOST_URL}" \
38+
-Diris.source.token="${SONAR_TOKEN}" \
39+
-Diris.destination.projectKey="${SHADOW_PROJECT_KEY}" \
40+
-Diris.destination.organization="${SHADOW_ORGANIZATION}" \
41+
-Diris.destination.url="${SHADOW_SONAR_HOST_URL}" \
42+
-Diris.destination.token="${SHADOW_SONAR_TOKEN}" \
43+
-Diris.dryrun="${DRY_RUN}" \
44+
-jar "${IRIS_JAR_PATH}"
45+
}
46+
47+
function run_iris_with_and_without_dry_run() {
48+
echo
49+
echo "===== Execute IRIS as dry-run"
50+
if run_iris true; then
51+
echo "===== Successful IRIS execution as dry-run"
52+
echo "===== Execute IRIS for real"
53+
if run_iris false; then
54+
echo "===== Successful IRIS execution for real"
55+
return 0
56+
else
57+
echo "===== Failed IRIS execution for real"
58+
return 1
59+
fi
60+
else
61+
echo "===== Failed IRIS execution as dry-run"
62+
return 1
63+
fi
64+
}
65+
66+
source cirrus-env BUILD
67+
. set_maven_build_version "$BUILD_NUMBER"
68+
build_and_analyze_the_project
69+
download_iris
70+
run_iris_with_and_without_dry_run

0 commit comments

Comments
 (0)