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
8 changes: 6 additions & 2 deletions .github/workflows/cicd-1-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ name: "1. CI/CD pull request"
on:
push:
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

permissions:
id-token: write
contents: write
Expand Down
38 changes: 33 additions & 5 deletions scripts/reports/perform-static-analysis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,68 @@ function main() {
else
run-sonar-scanner-in-docker
fi

return 0
}

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[@]}"

return 0
}

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[@]}"

return 0
}

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

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
}

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

function is-arg-true() {
local arg="$1"

if [[ "$1" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$ ]]; then
if [[ "$arg" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$ ]]; then
return 0
else
return 1
Expand Down