ci-scripts/sonar.sh

33 lines
999 B
Bash
Raw Normal View History

2024-06-24 16:54:05 +02:00
#!/bin/bash
set -e
2024-12-15 14:04:45 +01:00
function xargs() {
local cmd=$1
shift
for arg in "$@"; do
$cmd "$arg"
done
}
export -f xargs
2024-06-24 16:54:05 +02:00
sonarOpts=(-Dsonar.branch.name="${CI_COMMIT_BRANCH}")
if [[ -n "${CI_COMMIT_PULL_REQUEST}" ]]; then
2024-12-15 14:04:45 +01:00
sonarOpts=(-Dsonar.pullrequest.key="${CI_COMMIT_PULL_REQUEST}" -Dsonar.pullrequest.branch="${CI_COMMIT_SOURCE_BRANCH}" -Dsonar.pullrequest.base="${CI_COMMIT_TARGET_BRANCH}")
2024-06-24 16:54:05 +02:00
fi
2024-12-15 15:00:52 +01:00
version=
2024-12-15 14:04:45 +01:00
2024-12-15 15:00:52 +01:00
if [[ -f "package.json" ]]; then
version=$(awk -F'"' '/"version": ".+"/ { print $4; exit; }' package.json)
elif [[ -f "Cargo.toml" ]]; then
version=$(awk -F'"' '/^version =/ { print $2; exit; }' Cargo.toml)
elif [[ -d "gradle" ]]; then
2024-12-15 14:04:45 +01:00
version=$(./gradlew --gradle-user-home /tmp/.gradle --project-cache-dir /tmp/.cachegradle properties -PbuildDir=/tmp/.buildgradle -q | awk '/^version:/ {print $2}')
2024-12-15 11:55:42 +01:00
fi
2024-12-15 15:00:52 +01:00
sonarOpts+=(-Dsonar.projectVersion="${version}")
2024-12-15 14:04:45 +01:00
set -x
2024-06-24 16:54:05 +02:00
sonar-scanner -Dsonar.working.directory=/tmp/.scannerwork -Dsonar.qualitygate.wait=true "${sonarOpts[@]}" || true