Skip to content

Commit e0dc03f

Browse files
jimschubertjoschi
andauthored
Add sonar coverage reporting to master build (#184)
* Add sonar coverage reporting to master build * Run SonarCloud analysis for PRs * Add SonarCloud badge to README.md * Remove duplicate SONAR_TOKEN environment variable Co-authored-by: Jochen Schalanda <jochen@schalanda.name>
1 parent 0e83247 commit e0dc03f

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

.github/workflows/maven.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,21 @@ jobs:
3939
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
4040
restore-keys: |
4141
${{ runner.os }}-maven-
42+
- name: Cache SonarCloud packages
43+
uses: actions/cache@v2.1.2
44+
if: matrix.java_version == '11'
45+
with:
46+
path: ~/.sonar/cache
47+
key: ${{ runner.os }}-sonar
48+
restore-keys: ${{ runner.os }}-sonar
4249
- name: Run tests
43-
run: ./mvnw -V -B -ntp -ff verify
50+
run: ./mvnw -V -B -ntp -ff verify jacoco:report
51+
- name: Static Analysis (Sonar)
52+
if: matrix.java_version == '11'
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
56+
run: ./mvnw -B -ntp -ff org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
4457
- name: Release Snapshot
4558
if: matrix.java_version == '11'
4659
run: ./mvnw -V -B -ntp -ff deploy

.github/workflows/pr.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,18 @@ jobs:
3232
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
3333
restore-keys: |
3434
${{ runner.os }}-maven-
35+
- name: Cache SonarCloud packages
36+
uses: actions/cache@v2.1.2
37+
if: matrix.java_version == '11'
38+
with:
39+
path: ~/.sonar/cache
40+
key: ${{ runner.os }}-sonar
41+
restore-keys: ${{ runner.os }}-sonar
3542
- name: Run tests
3643
run: ./mvnw -V -B -ntp -ff verify
44+
- name: Static Analysis (Sonar)
45+
if: matrix.java_version == '11'
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
49+
run: ./mvnw -B -ntp -ff org.sonarsource.scanner.maven:sonar-maven-plugin:sonar

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Compare two OpenAPI specifications (3.x) and render the difference to HTML plaintext, or Markdown files.
44

55
[![Build](https://github.com/OpenAPITools/openapi-diff/workflows/Main%20Build/badge.svg)](https://github.com/OpenAPITools/openapi-diff/actions?query=branch%3Amaster+workflow%3A"Main+Build")
6+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=OpenAPITools_openapi-diff&metric=alert_status)](https://sonarcloud.io/dashboard?id=OpenAPITools_openapi-diff)
67
[![Maven Central](https://img.shields.io/maven-central/v/org.openapitools.openapidiff/openapi-diff-core)](https://search.maven.org/artifact/org.openapitools.openapidiff/openapi-diff-core)
78
[![Join the Slack chat room](https://img.shields.io/badge/Slack-Join%20the%20chat%20room-orange)](https://join.slack.com/t/openapi-generator/shared_invite/enQtNzAyNDMyOTU0OTE1LTY5ZDBiNDI5NzI5ZjQ1Y2E5OWVjMjZkYzY1ZGM2MWQ4YWFjMzcyNDY5MGI4NjQxNDBiMTlmZTc5NjY2ZTQ5MGM)
89

pom.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@
6969
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
7070
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
7171
<project.scm.id>github</project.scm.id>
72+
73+
<sonar.organization>openapitools</sonar.organization>
74+
<sonar.projectKey>OpenAPITools_openapi-diff</sonar.projectKey>
75+
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
76+
<sonar.moduleKey>${project.artifactId}</sonar.moduleKey>
77+
7278
<swagger-parser.version>2.0.22</swagger-parser.version>
7379
<slf4j.version>1.7.30</slf4j.version>
7480
</properties>
@@ -300,6 +306,16 @@
300306
<version>1.6.8</version>
301307
<extensions>true</extensions>
302308
</plugin>
309+
<plugin>
310+
<groupId>org.jacoco</groupId>
311+
<artifactId>jacoco-maven-plugin</artifactId>
312+
<version>0.8.6</version>
313+
</plugin>
314+
<plugin>
315+
<groupId>org.sonarsource.scanner.maven</groupId>
316+
<artifactId>sonar-maven-plugin</artifactId>
317+
<version>3.7.0.1746</version>
318+
</plugin>
303319
</plugins>
304320
</pluginManagement>
305321
<plugins>
@@ -341,6 +357,18 @@
341357
</execution>
342358
</executions>
343359
</plugin>
360+
<plugin>
361+
<groupId>org.jacoco</groupId>
362+
<artifactId>jacoco-maven-plugin</artifactId>
363+
<executions>
364+
<execution>
365+
<id>jacoco-initialize</id>
366+
<goals>
367+
<goal>prepare-agent</goal>
368+
</goals>
369+
</execution>
370+
</executions>
371+
</plugin>
344372
</plugins>
345373
</build>
346374
</project>

0 commit comments

Comments
 (0)