From: Jérôme Benoit Date: Sat, 11 Jun 2022 06:28:29 +0000 (+0200) Subject: Add a script to sync sonar properties X-Git-Tag: v2.2.1~67 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3ffada528b1ca9f062534bf09dd9772d1b2d4673;p=poolifier.git Add a script to sync sonar properties Signed-off-by: Jérôme Benoit --- diff --git a/.gitignore b/.gitignore index 8ddca4be..8cf99a8d 100644 --- a/.gitignore +++ b/.gitignore @@ -57,3 +57,4 @@ build/config.gypi .history/ .scannerwork lib +*.bak diff --git a/package.json b/package.json index 5e921e8c..5012ac2a 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "lint": "eslint . --cache", "lint:fix": "eslint . --cache --fix", "typedoc": "typedoc", + "sonar:properties": "./updateSonarProps.sh", "prepublishOnly": "npm run build:prod" }, "repository": { diff --git a/sonar-project.properties b/sonar-project.properties index fbb18042..4907570e 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,7 +2,7 @@ sonar.projectKey=pioardi_poolifier sonar.organization=pioardi sonar.javascript.lcov.reportPaths=coverage/lcov.info sonar.projectName=poolifier -sonar.projectVersion=2.0.0 +sonar.projectVersion=2.2.0 sonar.host.url=https://sonarcloud.io sonar.sources=src sonar.tests=tests diff --git a/updateSonarProps.sh b/updateSonarProps.sh new file mode 100755 index 00000000..d29ed6ab --- /dev/null +++ b/updateSonarProps.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +#title : updateSonarProps.sh +#description : +# This script parses the project's name and version from its package.json and automagically +# updates the version and package name in the SonarQube configuration properties file. +# It can be used as a pre step before running the sonar-scanner command +# +#prerequisites : NodeJS based project with package.json, sonar*.properties file in the cwd +#author : Christian-André Giehl +#modified by : Daniel Duarte +#date : 20180220 +#version : 1.1 +#usage : sh updateSonarProps.sh +#============================================================================== +echo "Updating the SonarQube properties..." + +# Get the project name from package.json +PACKAGE_NAME=$(cat package.json \ + | grep name \ + | head -1 \ + | awk -F: '{ print $2 }' \ + | sed 's/[",]//g' \ + | tr -d '[[:space:]]') +echo "Project: ${PACKAGE_NAME}" + +# Get the version from package.json +PACKAGE_VERSION=$(cat package.json \ + | grep version \ + | head -1 \ + | awk -F: '{ print $2 }' \ + | sed 's/[",]//g' \ + | tr -d '[[:space:]]') +echo "Version: ${PACKAGE_VERSION}" + +# Get the Sonar properties file +SONAR_FILE=$(find . -iname sonar*.properties -type f) +echo "Sonar file: ${SONAR_FILE}" + +SED_EXTRA_OPTS="-i.bak" + +# Update the version +REPLACE='^sonar.projectVersion=.*$' +WITH="sonar.projectVersion=${PACKAGE_VERSION}" +sed $SED_EXTRA_OPTS -e "s/${REPLACE}/${WITH}/g" ${SONAR_FILE} + +# Update the project name +REPLACE='^sonar.projectName=.*$' +WITH="sonar.projectName=${PACKAGE_NAME}" +sed $SED_EXTRA_OPTS -e "s/${REPLACE}/${WITH}/g" ${SONAR_FILE}