Skip to content

Commit

Permalink
SIGBMWDEX-122 Add SonarQube to Pipeline (#192)
Browse files Browse the repository at this point in the history
SIGBMWDEX-122 Add SonarQube to Pipeline
  • Loading branch information
valentin-sap committed Jan 3, 2024
1 parent bf56e81 commit 41850ce
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -158,6 +173,7 @@ workflows:
- build

- test:
context: SonarQubeSAP
requires:
- build
- lint:
Expand Down
23 changes: 23 additions & 0 deletions analyse.js
Original file line number Diff line number Diff line change
@@ -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
}
);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 41850ce

Please sign in to comment.