Skip to content

Commit d079d5e

Browse files
feat: adding support for SonarQube sonar cli (related to #3)
1 parent d5d24a8 commit d079d5e

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- support for mongo 8 (`install_mongo8`)
1313
- added `get_flavor_from_git_ref` `get_version_from_git_ref` `get_custom_from_git_ref` helpers to parse git ref names (tag or branch names).
14+
- added `install_sona_scanner_cli` to install SonarQube scanner cli tool
1415

1516
### Removed
1617

kash.sh

+30-5
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,25 @@ fi
5656

5757
if [ -n "$CI_ID" ]; then
5858
CI=true
59-
echo "Running in CI mode ($CI_ID)..."
59+
echo "Running in CI mode ($CI_ID) ..."
6060

6161
# Make sure we have the requirements to run kash functions
6262
set +e
63-
command -v curl >/dev/null 2>&1 && command -v git >/dev/null 2>&1 && command -v sha256sum >/dev/null 2>&1
63+
command -v curl >/dev/null 2>&1 && command -v git >/dev/null 2>&1 && command -v sha256sum >/dev/null 2>&1 && command -v unzip >/dev/null 2>&1
6464
RC=$?
6565
set -e
6666

6767
if [ "$RC" -ne 0 ]; then
6868
case "$OS_ID" in
6969
debian | ubuntu)
7070
if [ "$(id -u)" -eq 0 ]; then
71-
apt-get update && apt-get --no-install-recommends --yes install sudo curl ca-certificates coreutils git
71+
apt-get update && apt-get --no-install-recommends --yes install sudo curl ca-certificates coreutils git unzip
7272
else
73-
sudo apt-get update && sudo apt-get --no-install-recommends --yes install curl ca-certificates coreutils git
73+
sudo apt-get update && sudo apt-get --no-install-recommends --yes install curl ca-certificates coreutils git unzip
7474
fi
7575
;;
7676
alpine)
77-
apk update && apk add curl ca-certificates coreutils git
77+
apk update && apk add curl ca-certificates coreutils git unzip
7878
;;
7979
*)
8080
;;
@@ -105,6 +105,12 @@ if [ -d "$HOME/.nvm" ]; then
105105
. "$HOME/.nvm/nvm.sh"
106106
fi
107107

108+
# If sonar-scanner-cli is present, add it to PATH
109+
# See install_sonar_scanner_cli
110+
if [ -d "$HOME/.local/sonar-scanner" ]; then
111+
export PATH=$PATH:$HOME/.local/sonar-scanner/bin
112+
fi
113+
108114
# Define a TMP_DIR to operate with temp files
109115
if [ -n "${RUNNER_TEMP:-}" ]; then # RUNNER_TEMP is Github Action specific
110116
TMP_DIR="$RUNNER_TEMP"
@@ -143,6 +149,9 @@ NODE22_VERSION=22.3.0
143149
MONGODB7_VERSION=7.0.15
144150
MONGODB8_VERSION=8.0.3
145151

152+
# https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/scanners/sonarscanner/
153+
SONAR_SCANNER_CLI_VERSION=6.2.1.4610
154+
146155
# Install yq in ~/.local/bin
147156
# Arg1: a writable folder where to write downloaded files
148157
install_yq() {
@@ -366,6 +375,22 @@ install_mongo8() {
366375
cd ~-
367376
}
368377

378+
# Install sonar-scanner in ~/.local/sonar-scanner-cli
379+
# Arg1: a writable folder where to write downloaded files
380+
install_sonar_scanner_cli() {
381+
local DL_ROOT=$1
382+
local DL_PATH="$DL_ROOT/sonarscannercli"
383+
if [ ! -d "$DL_PATH" ]; then
384+
mkdir -p "$DL_PATH" && cd "$DL_PATH"
385+
curl -OLsS https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_CLI_VERSION}-linux-x64.zip
386+
unzip sonar-scanner-cli-${SONAR_SCANNER_CLI_VERSION}-linux-x64.zip
387+
cd ~-
388+
fi
389+
cd "$DL_PATH"
390+
mv sonar-scanner-${SONAR_SCANNER_CLI_VERSION}-linux-x64 ~/.local/sonar-scanner
391+
cd ~-
392+
}
393+
369394
# Install kubectl in ~/.local/bin
370395
# Expected args:
371396
# 1. a writable folder where to write downloaded files

scripts/run_tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ROOT_DIR=$(dirname "$THIS_DIR")
1111
### Github Actions
1212

1313
init_github() {
14-
install_reqs yq age sops nvm node16 node18 node20 cc_test_reporter
14+
install_reqs yq age sops nvm node16 node18 node20 cc_test_reporter sonar_scanner_cli
1515

1616
# mongo is not available for alpine hosts
1717
if [ "$OS_ID" != "alpine" ]; then

0 commit comments

Comments
 (0)