Skip to content

Commit

Permalink
CQI-10: use sonarcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
olewandowski1 committed Nov 3, 2023
1 parent 1bd644d commit d33ddc2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 83 deletions.
37 changes: 37 additions & 0 deletions .github/sonar-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: SonarCloud OpenLMIS-cce Pipeline
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: SonarCloud Analyze
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu'
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew sonarqube --info
41 changes: 1 addition & 40 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -133,52 +133,13 @@ pipeline {
}
}
}
stage('Parallel: Sonar analysis and contract tests') {
stage('Parallel: Contract tests') {
when {
expression {
return VERSION.endsWith("SNAPSHOT")
}
}
parallel {
stage('Sonar analysis') {
agent any
environment {
PATH = "/usr/local/bin/:$PATH"
}
steps {
withSonarQubeEnv('Sonar OpenLMIS') {
withCredentials([string(credentialsId: 'SONAR_LOGIN', variable: 'SONAR_LOGIN'), string(credentialsId: 'SONAR_PASSWORD', variable: 'SONAR_PASSWORD')]) {
script {
sh(script: "./ci-sonarAnalysis.sh")

// workaround: Sonar plugin retrieves the path directly from the output
sh 'echo "Working dir: ${WORKSPACE}/build/sonar"'
}
}
}
timeout(time: 1, unit: 'HOURS') {
script {
def gate = waitForQualityGate()
if (gate.status != 'OK') {
echo 'Quality Gate FAILED'
currentBuild.result = 'UNSTABLE'
}
}
}
}
post {
unstable {
script {
notifyAfterFailure()
}
}
failure {
script {
notifyAfterFailure()
}
}
}
}
stage('Contract tests') {
steps {
build job: "OpenLMIS-contract-tests-pipeline/${params.contractTestsBranch}", propagate: true, wait: true,
Expand Down
27 changes: 5 additions & 22 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {

plugins {
id "org.flywaydb.flyway" version "6.0.8"
id "org.sonarqube" version "2.6.2"
id "org.sonarqube" version "3.3"
id "com.moowork.node" version "0.12"
}

Expand Down Expand Up @@ -197,32 +197,15 @@ checkstyle {
toolVersion = "8.12"
}

//Usage: gradle sonarqube
//NOTE: This plugin requires that this task be named 'sonarqube'. In fact, it is performing SonarCloud analysis.
sonarqube {
properties {
def branch = System.getenv("SONAR_BRANCH")
if (branch && branch != 'master') {
property "sonar.branch", branch
}
property "sonar.projectName", "OpenLMIS CCE Service"
property "sonar.projectKey", "org.sonarqube:$rootProject.name"
property "sonar.projectVersion", version
property "sonar.login", System.getenv("SONAR_LOGIN")
property "sonar.password", System.getenv("SONAR_PASSWORD")
property "sonar.host.url", "http://sonar.openlmis.org"
property "sonar.java.coveragePlugin", "jacoco"
//Tells SonarQube where the unit tests execution reports are
property "sonar.junit.reportsPath", "build/test-results/test"
//Tells SonarQube where the unit tests code coverage report is
property "sonar.jacoco.reportPath", "build/jacoco/test.exec"
//Tells SonarQube where the integration tests code coverage report is
property "sonar.jacoco.itReportPath", "build/jacoco/integrationTest.exec"
properties["sonar.tests"] += sourceSets.integrationTest.java
property "sonar.projectKey", "OpenLMIS_openlmis-cce"
property "sonar.organization", "openlmis"
property "sonar.host.url", "https://sonarcloud.io"
}
}

project.tasks["sonarqube"].dependsOn integrationTest

pmd {
toolVersion = '5.4.0'
consoleOutput= true
Expand Down
21 changes: 0 additions & 21 deletions ci-sonarAnalysis.sh

This file was deleted.

0 comments on commit d33ddc2

Please sign in to comment.