Skip to content

Commit

Permalink
Merge pull request #24 from OpenLMIS/feature/CQI-10
Browse files Browse the repository at this point in the history
CQI-10: use sonarcloud instead of sonarqube
  • Loading branch information
dszafranek authored Nov 16, 2023
2 parents b7f13c3 + 311b30b commit 2dcde76
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 91 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/sonar-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: SonarCloud OpenLMIS-fulfillment 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: Build with Docker Compose
continue-on-error: true
run: |
curl -o .env -L https://raw.githubusercontent.com/OpenLMIS/openlmis-ref-distro/master/settings-sample.env
docker-compose -f docker-compose.builder.yml run builder
sudo chown -R $(whoami) ./
cp ./build/reports/jacoco/test/jacocoTestReport.xml report.xml
rm -rf ./build
- name: Analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
sudo chown -R $(whoami) ./
./gradlew sonarqube --info
46 changes: 1 addition & 45 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -148,57 +148,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()
}
}
cleanup {
script {
sh "sudo rm -rf ${WORKSPACE}/{*,.*} || true"
}
}
}
}
stage('Contract tests') {
steps {
build job: "OpenLMIS-contract-tests-pipeline/${params.contractTestsBranch}", propagate: true, wait: true,
Expand Down
33 changes: 9 additions & 24 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 "1.2.0"
}

Expand Down Expand Up @@ -82,7 +82,7 @@ dependencies {
compile 'org.javers:javers-spring-boot-starter-sql:2.8.2'
compile "org.slf4j:slf4j-ext"

annotationProcessor 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
compile group: 'org.apache.poi', name: 'poi', version: '3.15'
compile group: 'javax.interceptor', name: 'javax.interceptor-api', version: '1.2'

Expand All @@ -100,7 +100,7 @@ dependencies {
testCompile "nl.jqno.equalsverifier:equalsverifier:2.4"
testCompile "be.joengenduvel.java.verifiers:to-string:1.0.2"
testCompile "com.github.tomakehurst:wiremock:1.58"
testAnnotationProcessor 'org.projectlombok:lombok:1.18.10'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'

runtime fileTree(dir: '/extensions/', include: '*.jar')

Expand Down Expand Up @@ -218,32 +218,17 @@ 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 Fulfillment"
property "sonar.projectKey", "org.sonarqube:openlmis-fulfillment"
property "sonar.host.url", "http://sonar.openlmis.org"
property "sonar.projectVersion", version
property "sonar.login", System.getenv("SONAR_LOGIN")
property "sonar.password", System.getenv("SONAR_PASSWORD")
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-fulfillment"
property "sonar.organization", "openlmis"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.java.source", "17"
property "sonar.coverage.jacoco.xmlReportPaths", "./report.xml"
}
}

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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"raml2html": "~2.4.0"
},
"scripts": {
"runApiHtmlConverter": "raml2html --input build/resources/main/api-definition-raml.yaml --output build/resources/main/api-definition.html"
"runApiHtmlConverter": "raml2html --input ./build/resources/main/api-definition-raml.yaml --output ./build/resources/main/api-definition.html"
},
"files": [
"consul/package.json"
Expand Down

0 comments on commit 2dcde76

Please sign in to comment.