Skip to content

Commit

Permalink
Update default CLI version to 4.6.2.2472 (#19)
Browse files Browse the repository at this point in the history
* Update default CLI version to 4.6.2.2472

* Code cleanup

* Fix java version checking
  • Loading branch information
koral-- authored Aug 23, 2021
1 parent 4219f26 commit 0de979c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
3 changes: 3 additions & 0 deletions bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ workflows:
title: Step Test
run_if: "true"
inputs:
- is_debug: "true"
- scanner_properties: |-
sonar.sources=.
sonar.organization=droidsonroidssonarcloudpublicbot-github
Expand All @@ -106,6 +107,7 @@ workflows:
run_if: "true"
inputs:
- scanner_version: 3.0.0.702
- is_debug: "true"
- scanner_properties: |-
sonar.sources=.
sonar.organization=droidsonroidssonarcloudpublicbot-github
Expand All @@ -124,6 +126,7 @@ workflows:
JAVA_VERSION_MAJOR=$(javac -version 2>&1 | cut -d' ' -f2 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1)
if [ "${JAVA_VERSION_MAJOR}" -lt "11" ]; then
mkfifo fifo
export scanner_version=latest
bash step.sh >fifo &
grep -m1 'Version "8" has been detected' fifo
kill $!
Expand Down
19 changes: 6 additions & 13 deletions step.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,19 @@ if [[ "${is_debug}" == "true" ]]; then
set -x
fi


if [[ ! -z ${scanner_properties} ]]; then
if [[ -n ${scanner_properties} ]]; then
if [[ -e sonar-project.properties ]]; then
echo -e "\e[34mBoth sonar-project.properties file and step properties are provided. Appending properties to the file.\e[0m"
echo "" >> sonar-project.properties
fi
echo "${scanner_properties}" >> sonar-project.properties
fi


if [[ "$scanner_version" == "latest" ]]; then
scanner_version=$(curl --silent "https://api.github.com/repos/SonarSource/sonar-scanner-cli/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
echo "Use latest version: $scanner_version"
fi


# Identify minimum Java version required based on Sonarqube scanner used
MINIMUM_JAVA_VERSION_NEEDED="8"
if [[ $(echo "$scanner_version" | cut -d'.' -f1) -ge "4" ]]; then
Expand All @@ -29,31 +26,27 @@ if [[ $(echo "$scanner_version" | cut -d'.' -f1) -ge "4" ]]; then
fi
fi


# Check current Java version against the minimum one required
JAVA_VERSION_MAJOR=$(javac -version 2>&1 | cut -d' ' -f2 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1)
if [ ! -z "${JAVA_VERSION_MAJOR}" ]; then
if [ -n "${JAVA_VERSION_MAJOR}" ]; then
if [ "${JAVA_VERSION_MAJOR}" -lt "${MINIMUM_JAVA_VERSION_NEEDED}" ]; then
echo -e "\e[93mSonar Scanner CLI \"${scanner_version}\" requires JRE or JDK version ${MINIMUM_JAVA_VERSION_NEEDED} or newer. Version \"${JAVA_VERSION_MAJOR}\" has been detected, CLI may not work properly.\e[0m"
fi
else
echo -e "\e[91mSonar Scanner CLI \"${scanner_version}\" requires JRE or JDK version ${MINIMUM_JAVA_VERSION_NEEDED} or newer. None has been detected, CLI may not work properly.\e[0m"
fi


pushd $(mktemp -d)
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${scanner_version}.zip
unzip sonar-scanner-cli-${scanner_version}.zip
pushd "$(mktemp -d)"
wget "https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${scanner_version}.zip"
unzip "sonar-scanner-cli-${scanner_version}.zip"
TEMP_DIR=$(pwd)
popd



if [[ "${is_debug}" == "true" ]]; then
debug_flag="-X"
else
debug_flag=""
fi

${TEMP_DIR}/sonar-scanner-${scanner_version}/bin/sonar-scanner $debug_flag
"${TEMP_DIR}/sonar-scanner-${scanner_version}/bin/sonar-scanner" "${debug_flag}"

4 changes: 3 additions & 1 deletion step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ deps:
apt_get:
- name: unzip
- name: wget
- name: curl
brew:
- name: unzip
- name: wget
- name: curl
is_requires_admin_user: false
is_always_run: false
is_skippable: false
inputs:
- scanner_version: 4.3.0.2102
- scanner_version: 4.6.2.2472
opts:
title: Scanner CLI version
description: |-
Expand Down

0 comments on commit 0de979c

Please sign in to comment.