Skip to content

Commit cbbc698

Browse files
CCM-18946: Sonar PR Decoration Fixes
1 parent 01c6c67 commit cbbc698

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

.github/workflows/cicd-1-pull-request.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ name: "1. CI/CD pull request"
55
on:
66
push:
77
branches:
8-
- "**"
8+
- "main"
99
pull_request:
10-
types: [opened, reopened]
10+
types: [opened, reopened, synchronize]
1111
branches:
1212
- main
1313

14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
16+
cancel-in-progress: true
17+
1418
permissions:
1519
id-token: write
1620
contents: write

scripts/reports/perform-static-analysis.sh

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,40 +31,68 @@ function main() {
3131
else
3232
run-sonar-scanner-in-docker
3333
fi
34+
35+
return 0
3436
}
3537

3638
function run-sonar-scanner-natively() {
3739

40+
local -a context_args
41+
context_args=($(build-sonar-context-args))
42+
3843
sonar-scanner \
3944
-Dproject.settings="$PWD/scripts/config/sonar-scanner.properties" \
40-
-Dsonar.branch.name="${BRANCH_NAME:-$(git rev-parse --abbrev-ref HEAD)}" \
4145
-Dsonar.organization="$SONAR_ORGANISATION_KEY" \
4246
-Dsonar.projectKey="$SONAR_PROJECT_KEY" \
43-
-Dsonar.token="$SONAR_TOKEN"
47+
-Dsonar.token="$SONAR_TOKEN" \
48+
"${context_args[@]}"
49+
50+
return 0
4451
}
4552

4653
function run-sonar-scanner-in-docker() {
4754

4855
# shellcheck disable=SC1091
4956
source ./scripts/docker/docker.lib.sh
5057

58+
local -a context_args
59+
context_args=($(build-sonar-context-args))
60+
5161
# shellcheck disable=SC2155
5262
local image=$(name=sonarsource/sonar-scanner-cli docker-get-image-version-and-pull)
5363
docker run --rm --platform linux/amd64 \
5464
--volume "$PWD":/usr/src \
5565
"$image" \
5666
-Dproject.settings=/usr/src/scripts/config/sonar-scanner.properties \
57-
-Dsonar.branch.name="${BRANCH_NAME:-$(git rev-parse --abbrev-ref HEAD)}" \
5867
-Dsonar.organization="$SONAR_ORGANISATION_KEY" \
5968
-Dsonar.projectKey="$SONAR_PROJECT_KEY" \
60-
-Dsonar.token="$SONAR_TOKEN"
69+
-Dsonar.token="$SONAR_TOKEN" \
70+
"${context_args[@]}"
71+
72+
return 0
73+
}
74+
75+
# ==============================================================================
76+
77+
function build-sonar-context-args() {
78+
79+
if [[ "${GITHUB_EVENT_NAME:-}" == "pull_request" ]]; then
80+
local pr_number
81+
pr_number=$(echo "${GITHUB_REF:-}" | grep -oP 'refs/pull/\K[0-9]+')
82+
echo "-Dsonar.pullrequest.key=${pr_number}"
83+
echo "-Dsonar.pullrequest.branch=${GITHUB_HEAD_REF:-${BRANCH_NAME}}"
84+
echo "-Dsonar.pullrequest.base=${GITHUB_BASE_REF:-main}"
85+
else
86+
echo "-Dsonar.branch.name=${BRANCH_NAME:-$(git rev-parse --abbrev-ref HEAD)}"
87+
fi
6188
}
6289

6390
# ==============================================================================
6491

6592
function is-arg-true() {
93+
local arg="$1"
6694

67-
if [[ "$1" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$ ]]; then
95+
if [[ "$arg" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$ ]]; then
6896
return 0
6997
else
7098
return 1

0 commit comments

Comments
 (0)