Skip to content

Commit fc83178

Browse files
committed
Run SonarCloud analysis for PRs
1 parent 8212555 commit fc83178

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

.github/workflows/maven.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,21 @@ jobs:
4040
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
4141
restore-keys: |
4242
${{ runner.os }}-maven-
43+
- name: Cache SonarCloud packages
44+
uses: actions/cache@v2.1.2
45+
if: matrix.java_version == '11'
46+
with:
47+
path: ~/.sonar/cache
48+
key: ${{ runner.os }}-sonar
49+
restore-keys: ${{ runner.os }}-sonar
4350
- name: Run tests
4451
run: ./mvnw -V -B -ntp -ff verify jacoco:report
4552
- name: Static Analysis (Sonar)
46-
# Sonar will require at least Java 11 soon.
4753
if: matrix.java_version == '11'
48-
run: ./mvnw -B -ntp -ff jacoco:report-aggregate org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=OpenAPITools_openapi-diff -Dsonar.organization=openapitools -Dsonar.host.url=https://sonarcloud.io -Dsonar.branch.name=${GITHUB_REF##*/}
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
57+
run: ./mvnw -B -ntp -ff org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
4958
- name: Release Snapshot
5059
if: matrix.java_version == '11'
5160
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

pom.xml

Lines changed: 11 additions & 27 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>
@@ -311,6 +317,11 @@
311317
<artifactId>jacoco-maven-plugin</artifactId>
312318
<version>0.8.6</version>
313319
</plugin>
320+
<plugin>
321+
<groupId>org.sonarsource.scanner.maven</groupId>
322+
<artifactId>sonar-maven-plugin</artifactId>
323+
<version>3.7.0.1746</version>
324+
</plugin>
314325
</plugins>
315326
</pluginManagement>
316327
<plugins>
@@ -362,40 +373,13 @@
362373
<goal>prepare-agent</goal>
363374
</goals>
364375
</execution>
365-
<execution>
366-
<id>jacoco-site</id>
367-
<phase>test</phase>
368-
<goals>
369-
<goal>report</goal>
370-
</goals>
371-
</execution>
372376
<execution>
373377
<id>default-check</id>
374378
<goals>
375379
<goal>check</goal>
376380
</goals>
377-
<configuration>
378-
<rules>
379-
<rule>
380-
<element>PACKAGE</element>
381-
<limits>
382-
<limit>
383-
<counter>LINE</counter>
384-
<value>COVEREDRATIO</value>
385-
<minimum>0</minimum>
386-
</limit>
387-
</limits>
388-
</rule>
389-
</rules>
390-
</configuration>
391381
</execution>
392382
</executions>
393-
<configuration>
394-
<excludes>
395-
<!-- Example: -->
396-
<!-- <exclude>**/gradle-wrapper.jar</exclude> -->
397-
</excludes>
398-
</configuration>
399383
</plugin>
400384
</plugins>
401385
</build>

0 commit comments

Comments
 (0)