Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLVS-1662 Run sonarcloud analysis for long lived branches and PRs #5857

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions .cirrus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ build_task:
SONARSOURCE_SNK: VAULT[development/team/languages/kv/data/strong_named_key data.SonarSourceSecret_snk]
clone_script: |
git config --global core.autocrlf true
git init
git remote add origin https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git
git fetch origin
git reset --hard $CIRRUS_CHANGE_IN_REPO
if [ -z "$CIRRUS_PR" ]; then
git clone --recursive --branch=$CIRRUS_BRANCH https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR
git reset --hard $CIRRUS_CHANGE_IN_REPO
else
git clone --recursive https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR
git fetch origin pull/$CIRRUS_PR/head:pull/$CIRRUS_PR
git checkout pull/$CIRRUS_PR
git reset --hard $CIRRUS_CHANGE_IN_REPO
fi
calculate_version_script: *CALCULATE_VERSION_SCRIPT_DEFINITION
prepare_signing_script: |
if [[ "${CIRRUS_BRANCH}" == "${CIRRUS_DEFAULT_BRANCH}" ]] || echo "${CIRRUS_BRANCH}" | grep -qE "^branch-.*" || echo "${CIRRUS_BRANCH}" | grep -qE "^sign-.*"; then
Expand All @@ -71,7 +76,7 @@ build_task:
dotnet_restore_script: |
dotnet restore "${SOLUTION_PATH}" --locked-mode
prepare_analysis_script: |
dotnet sonarscanner begin -d:sonar.token=${SONAR_TOKEN} -d:sonar.host.url="${SONAR_URL}" -k:"${CIRRUS_REPO_NAME}" -o:"sonarsource" -d:sonar.cs.vscoveragexml.reportsPaths="${COVERAGE_FILE}" -d:sonar.scanner.scanAll=false
.cirrus/sonarqube-cloud-analysis.sh
build_solution_script: |
msbuild.exe "${SOLUTION_PATH}" -p:VsVersion=17.0 -p:VsTargetVersion=2022 -p:SignArtifacts=${SHOULD_SIGN} -p:AssemblyOriginatorKeyFile="${SONARSOURCE_SNK_FILE}" -p:DeployExtension=false -p:Sha1="${CIRRUS_CHANGE_IN_REPO}" -p:BuildNumber="${CI_BUILD_NUMBER}" -p:Configuration=Release
sign_artifact_script: |
Expand Down
34 changes: 34 additions & 0 deletions .cirrus/sonarqube-cloud-analysis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

set -xeuo pipefail

SONAR_PARAMS=(
-k:"${CIRRUS_REPO_NAME}"
-o:"sonarsource"
-d:sonar.host.url="${SONAR_URL}"
-d:sonar.token="${SONAR_TOKEN}"
-d:sonar.analysis.buildNumber="${CI_BUILD_NUMBER}"
-d:sonar.analysis.pipeline="$CIRRUS_BUILD_ID"
-d:sonar.analysis.sha1="${CIRRUS_CHANGE_IN_REPO}"
-d:sonar.cs.vscoveragexml.reportsPaths="${COVERAGE_FILE}"
-d:sonar.scanner.scanAll=false
)

if [ "$CIRRUS_BRANCH" == "master" ] && [ "$CIRRUS_PR" == "false" ]; then
echo '======= Analyze master branch'
dotnet sonarscanner begin "${SONAR_PARAMS[@]}"

elif [[ "$CIRRUS_BRANCH" == "branch-"* || "$CIRRUS_BRANCH" == "feature/"* ]] && [ "$CIRRUS_PR" == "false" ]; then
echo '======= Analyze long lived branch'
dotnet sonarscanner begin "${SONAR_PARAMS[@]}" -d:sonar.branch.name="${CIRRUS_BRANCH}"

elif [ "$CIRRUS_PR" != "false" ]; then
echo '======= Analyze pull request'
dotnet sonarscanner begin "${SONAR_PARAMS[@]}" \
-d:sonar.pullrequest.key="${CIRRUS_PR}" \
-d:sonar.pullrequest.branch="${CIRRUS_BRANCH}" \
-d:sonar.pullrequest.base="${CIRRUS_BASE_BRANCH}"

else
echo '======= No analysis'
fi