diff --git a/.cirrus.yaml b/.cirrus.yaml index 48b1c351d..ccf7cf3d5 100644 --- a/.cirrus.yaml +++ b/.cirrus.yaml @@ -25,7 +25,6 @@ build_task: ec2_instance: *INSTANCE_DEFINITION only_if: *ONLY_SONARSOURCE_QA env: - CIRRUS_CLONE_DEPTH: 50 ARTIFACTORY_DEPLOY_TOKEN: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-qa-deployer access_token] COVERAGE_FILE: coverage.xml LOCALAPPDATA: C:\sonar-ci\AppData\Local # Fixes unit test error @@ -55,6 +54,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: | diff --git a/.cirrus/sonarqube-cloud-analysis.sh b/.cirrus/sonarqube-cloud-analysis.sh index 9ba5daa6f..c9a0b6bec 100644 --- a/.cirrus/sonarqube-cloud-analysis.sh +++ b/.cirrus/sonarqube-cloud-analysis.sh @@ -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 \ No newline at end of file