diff --git a/.circleci/config.yml b/.circleci/config.yml index a41c0e8..c554529 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -123,6 +123,21 @@ jobs: - *restore_deps - run: yarn coverage --ci + - run: + name: Sonar scan + command: | + if [ -n "$CIRCLE_PULL_REQUEST" ]; then + PR_NUMBER=$(echo $CIRCLE_PULL_REQUEST | sed -E "s/.+\/([0-9]+)$/\1/g") + SONAR_ARGS="\ + sonar.pullrequest.key=${PR_NUMBER} \ + sonar.pullrequest.branch=${CIRCLE_BRANCH} \ + sonar.pullrequest.base=master" + else + SONAR_ARGS="\ + sonar.branch.name=${CIRCLE_BRANCH}" + fi + + node analyse.js $SONAR_ARGS - *publish_test_results - *store_test_results @@ -158,6 +173,7 @@ workflows: - build - test: + context: SonarQubeSAP requires: - build - lint: diff --git a/analyse.js b/analyse.js new file mode 100644 index 0000000..b2481a4 --- /dev/null +++ b/analyse.js @@ -0,0 +1,23 @@ +const scanner = require("sonarqube-scanner"); + +let options = { + "sonar.sources": "src", + "sonar.tests": "test", + "sonar.javascript.lcov.reportPaths": "coverage/lcov.info", + "sonar.projectKey": "com.sap.signavio.i18N" +} + +process.argv.slice(2).forEach(function (argument) { + const [key, value] = argument.split("="); + options[key] = value; +}); + +scanner( + { + serverUrl: "https://sonar.tools.sap/", + options: options, + }, + () => { + // callback is required + } +); \ No newline at end of file diff --git a/package.json b/package.json index e790334..ffb8563 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,8 @@ "prettier": "1.15.3", "react": "16.14.0", "react-dom": "16.14.0", - "rimraf": "2.7.1" + "rimraf": "2.7.1", + "sonarqube-scanner": "^3.3.0" }, "peerDependencies": { "@babel/core": "^7.0.0",