Skip to content

Commit

Permalink
Optimize analysis script
Browse files Browse the repository at this point in the history
  • Loading branch information
vnaskos-sonar committed Nov 29, 2024
1 parent 56f107b commit 023f3d9
Showing 2 changed files with 17 additions and 48 deletions.
1 change: 1 addition & 0 deletions .cirrus.yaml
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@ build_task:
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: |
64 changes: 16 additions & 48 deletions .cirrus/sonarqube-cloud-analysis.sh
Original file line number Diff line number Diff line change
@@ -2,65 +2,33 @@

set -xeuo pipefail

# Fetch all commit history so that SonarCloud has exact blame information
# for issue auto-assignment
# This command can fail with "fatal: --unshallow on a complete repository does not make sense"
# if there are not enough commits in the Git repository
# For this reason errors are ignored with "|| true"
git fetch --unshallow || true

# fetch references from github for PR analysis
if [ -n "${CIRRUS_BASE_BRANCH}" ]; then
git fetch origin "${CIRRUS_BASE_BRANCH}"
fi
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 \
-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
dotnet sonarscanner begin "${SONAR_PARAMS[@]}"

elif [[ "$CIRRUS_BRANCH" == "branch-"* || "$CIRRUS_BRANCH" == "feature/"* ]] && [ "$CIRRUS_PR" == "false" ]; then
echo '======= Analyze long lived branch'

dotnet sonarscanner begin \
-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.branch.name="${CIRRUS_BRANCH}" \
-d:sonar.cs.vscoveragexml.reportsPaths="${COVERAGE_FILE}" \
-d:sonar.scanner.scanAll=false
dotnet sonarscanner begin "${SONAR_PARAMS[@]}" -d:sonar.branch.name="${CIRRUS_BRANCH}"

elif [ "$CIRRUS_PR" != "false" ]; then
echo '======= Analyze pull request'

dotnet sonarscanner begin \
-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}" \
dotnet sonarscanner begin "${SONAR_PARAMS[@]}" \
-d:sonar.pullrequest.key="${CIRRUS_PR}" \
-d:sonar.pullrequest.branch="${CIRRUS_BRANCH}" \
-d:sonar.pullrequest.base="${CIRRUS_BASE_BRANCH}" \
-d:sonar.cs.vscoveragexml.reportsPaths="${COVERAGE_FILE}" \
-d:sonar.scanner.scanAll=false \
-d:sonar.verbose=true
-d:sonar.pullrequest.base="${CIRRUS_BASE_BRANCH}"

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

0 comments on commit 023f3d9

Please sign in to comment.