Skip to content

Commit c273d76

Browse files
authored
Merge branch 'main' into feature/CCM-17337-Publish-Supplier-Configuration-Event
2 parents 8628339 + 80bea49 commit c273d76

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ name: "1. CI - Pull Request"
33
# The total recommended execution time for the "CI/CD Pull Request" workflow is around 20 minutes.
44

55
on:
6-
push:
6+
push: ## Only trigger on pushes to main branch to prevent unnecessary runs on feature branches, as the pull_request trigger will handle PR events.
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
jobs:
1519
metadata:
1620
name: "Set CI/CD metadata"

scripts/reports/perform-static-analysis.sh

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,50 @@ function main() {
3535

3636
function run-sonar-scanner-natively() {
3737

38+
local -a context_args
39+
context_args=($(build-sonar-context-args))
40+
3841
sonar-scanner \
3942
-Dproject.settings="$PWD/scripts/config/sonar-scanner.properties" \
40-
-Dsonar.branch.name="${BRANCH_NAME:-$(git rev-parse --abbrev-ref HEAD)}" \
4143
-Dsonar.organization="$SONAR_ORGANISATION_KEY" \
4244
-Dsonar.projectKey="$SONAR_PROJECT_KEY" \
43-
-Dsonar.token="$SONAR_TOKEN"
45+
-Dsonar.token="$SONAR_TOKEN" \
46+
"${context_args[@]}"
4447
}
4548

4649
function run-sonar-scanner-in-docker() {
4750

4851
# shellcheck disable=SC1091
4952
source ./scripts/docker/docker.lib.sh
5053

54+
local -a context_args
55+
context_args=($(build-sonar-context-args))
56+
5157
# shellcheck disable=SC2155
5258
local image=$(name=sonarsource/sonar-scanner-cli docker-get-image-version-and-pull)
5359
docker run --rm --platform linux/amd64 \
5460
--volume "$PWD":/usr/src \
5561
"$image" \
5662
-Dproject.settings=/usr/src/scripts/config/sonar-scanner.properties \
57-
-Dsonar.branch.name="${BRANCH_NAME:-$(git rev-parse --abbrev-ref HEAD)}" \
5863
-Dsonar.organization="$SONAR_ORGANISATION_KEY" \
5964
-Dsonar.projectKey="$SONAR_PROJECT_KEY" \
60-
-Dsonar.token="$SONAR_TOKEN"
65+
-Dsonar.token="$SONAR_TOKEN" \
66+
"${context_args[@]}"
67+
}
68+
69+
# ==============================================================================
70+
71+
function build-sonar-context-args() {
72+
73+
if [[ "${GITHUB_EVENT_NAME:-}" == "pull_request" ]]; then
74+
local pr_number
75+
pr_number=$(echo "${GITHUB_REF:-}" | grep -oP 'refs/pull/\K[0-9]+')
76+
echo "-Dsonar.pullrequest.key=${pr_number}"
77+
echo "-Dsonar.pullrequest.branch=${GITHUB_HEAD_REF:-${BRANCH_NAME}}"
78+
echo "-Dsonar.pullrequest.base=${GITHUB_BASE_REF:-main}"
79+
else
80+
echo "-Dsonar.branch.name=${BRANCH_NAME:-$(git rev-parse --abbrev-ref HEAD)}"
81+
fi
6182
}
6283

6384
# ==============================================================================

0 commit comments

Comments
 (0)