Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/cicd-1-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ name: "1. CI - Pull Request"
# The total recommended execution time for the "CI/CD Pull Request" workflow is around 20 minutes.

on:
push:
push: ## Only trigger on pushes to main branch to prevent unnecessary runs on feature branches, as the pull_request trigger will handle PR events.
branches:
- "**"
- main
pull_request:
types: [opened, reopened]
types: [opened, reopened, synchronize]
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true

jobs:
metadata:
name: "Set CI/CD metadata"
Expand Down
29 changes: 25 additions & 4 deletions scripts/reports/perform-static-analysis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,50 @@ function main() {

function run-sonar-scanner-natively() {

local -a context_args
context_args=($(build-sonar-context-args))

sonar-scanner \
-Dproject.settings="$PWD/scripts/config/sonar-scanner.properties" \
-Dsonar.branch.name="${BRANCH_NAME:-$(git rev-parse --abbrev-ref HEAD)}" \
-Dsonar.organization="$SONAR_ORGANISATION_KEY" \
-Dsonar.projectKey="$SONAR_PROJECT_KEY" \
-Dsonar.token="$SONAR_TOKEN"
-Dsonar.token="$SONAR_TOKEN" \
"${context_args[@]}"
}

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

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

local -a context_args
context_args=($(build-sonar-context-args))

# shellcheck disable=SC2155
local image=$(name=sonarsource/sonar-scanner-cli docker-get-image-version-and-pull)
docker run --rm --platform linux/amd64 \
--volume "$PWD":/usr/src \
"$image" \
-Dproject.settings=/usr/src/scripts/config/sonar-scanner.properties \
-Dsonar.branch.name="${BRANCH_NAME:-$(git rev-parse --abbrev-ref HEAD)}" \
-Dsonar.organization="$SONAR_ORGANISATION_KEY" \
-Dsonar.projectKey="$SONAR_PROJECT_KEY" \
-Dsonar.token="$SONAR_TOKEN"
-Dsonar.token="$SONAR_TOKEN" \
"${context_args[@]}"
}

# ==============================================================================

function build-sonar-context-args() {

if [[ "${GITHUB_EVENT_NAME:-}" == "pull_request" ]]; then
local pr_number
pr_number=$(echo "${GITHUB_REF:-}" | grep -oP 'refs/pull/\K[0-9]+')
echo "-Dsonar.pullrequest.key=${pr_number}"
echo "-Dsonar.pullrequest.branch=${GITHUB_HEAD_REF:-${BRANCH_NAME}}"
echo "-Dsonar.pullrequest.base=${GITHUB_BASE_REF:-main}"
else
echo "-Dsonar.branch.name=${BRANCH_NAME:-$(git rev-parse --abbrev-ref HEAD)}"
fi
}

# ==============================================================================
Expand Down