Skip to content

Commit

Permalink
feat: adding support for SonarQube sonar cli (related to #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbourianes-kalisio committed Jan 14, 2025
1 parent d5d24a8 commit d079d5e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- support for mongo 8 (`install_mongo8`)
- 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).
- added `install_sona_scanner_cli` to install SonarQube scanner cli tool

### Removed

Expand Down
35 changes: 30 additions & 5 deletions kash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,25 @@ fi

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

# Make sure we have the requirements to run kash functions
set +e
command -v curl >/dev/null 2>&1 && command -v git >/dev/null 2>&1 && command -v sha256sum >/dev/null 2>&1
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
RC=$?
set -e

if [ "$RC" -ne 0 ]; then
case "$OS_ID" in
debian | ubuntu)
if [ "$(id -u)" -eq 0 ]; then
apt-get update && apt-get --no-install-recommends --yes install sudo curl ca-certificates coreutils git
apt-get update && apt-get --no-install-recommends --yes install sudo curl ca-certificates coreutils git unzip
else
sudo apt-get update && sudo apt-get --no-install-recommends --yes install curl ca-certificates coreutils git
sudo apt-get update && sudo apt-get --no-install-recommends --yes install curl ca-certificates coreutils git unzip
fi
;;
alpine)
apk update && apk add curl ca-certificates coreutils git
apk update && apk add curl ca-certificates coreutils git unzip
;;
*)
;;
Expand Down Expand Up @@ -105,6 +105,12 @@ if [ -d "$HOME/.nvm" ]; then
. "$HOME/.nvm/nvm.sh"
fi

# If sonar-scanner-cli is present, add it to PATH
# See install_sonar_scanner_cli
if [ -d "$HOME/.local/sonar-scanner" ]; then
export PATH=$PATH:$HOME/.local/sonar-scanner/bin
fi

# Define a TMP_DIR to operate with temp files
if [ -n "${RUNNER_TEMP:-}" ]; then # RUNNER_TEMP is Github Action specific
TMP_DIR="$RUNNER_TEMP"
Expand Down Expand Up @@ -143,6 +149,9 @@ NODE22_VERSION=22.3.0
MONGODB7_VERSION=7.0.15
MONGODB8_VERSION=8.0.3

# https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/scanners/sonarscanner/
SONAR_SCANNER_CLI_VERSION=6.2.1.4610

# Install yq in ~/.local/bin
# Arg1: a writable folder where to write downloaded files
install_yq() {
Expand Down Expand Up @@ -366,6 +375,22 @@ install_mongo8() {
cd ~-
}

# Install sonar-scanner in ~/.local/sonar-scanner-cli
# Arg1: a writable folder where to write downloaded files
install_sonar_scanner_cli() {
local DL_ROOT=$1
local DL_PATH="$DL_ROOT/sonarscannercli"
if [ ! -d "$DL_PATH" ]; then
mkdir -p "$DL_PATH" && cd "$DL_PATH"
curl -OLsS https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_CLI_VERSION}-linux-x64.zip
unzip sonar-scanner-cli-${SONAR_SCANNER_CLI_VERSION}-linux-x64.zip
cd ~-
fi
cd "$DL_PATH"
mv sonar-scanner-${SONAR_SCANNER_CLI_VERSION}-linux-x64 ~/.local/sonar-scanner
cd ~-
}

# Install kubectl in ~/.local/bin
# Expected args:
# 1. a writable folder where to write downloaded files
Expand Down
2 changes: 1 addition & 1 deletion scripts/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ROOT_DIR=$(dirname "$THIS_DIR")
### Github Actions

init_github() {
install_reqs yq age sops nvm node16 node18 node20 cc_test_reporter
install_reqs yq age sops nvm node16 node18 node20 cc_test_reporter sonar_scanner_cli

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

0 comments on commit d079d5e

Please sign in to comment.