Skip to content

Commit 6c31c3d

Browse files
stefanhahmannStefan Hahmann
authored andcommitted
Add SonarCloud analysis and PR decoration
* Add sonar properties to pom.xml * Use mvn test to create Jacoco Test Report * Add Jacoco Test Report generation
1 parent bccbc17 commit 6c31c3d

2 files changed

Lines changed: 106 additions & 0 deletions

File tree

.github/workflows/sonarcloud.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# This workflow helps you trigger a SonarCloud analysis of your code and populates
7+
# GitHub Code Scanning alerts with the vulnerabilities found.
8+
# Free for open source project.
9+
10+
# 1. Login to SonarCloud.io using your GitHub account
11+
12+
# 2. Import your project on SonarCloud
13+
# * Add your GitHub organization first, then add your repository as a new project.
14+
# * Please note that many languages are eligible for automatic analysis,
15+
# which means that the analysis will start automatically without the need to set up GitHub Actions.
16+
# * This behavior can be changed in Administration > Analysis Method.
17+
#
18+
# 3. Follow the SonarCloud in-product tutorial
19+
# * a. Copy/paste the Project Key and the Organization Key into the args parameter below
20+
# (You'll find this information in SonarCloud. Click on "Information" at the bottom left)
21+
#
22+
# * b. Generate a new token and add it to your Github repository's secrets using the name SONAR_TOKEN
23+
# (On SonarCloud, click on your avatar on top-right > My account > Security
24+
# or go directly to https://sonarcloud.io/account/security/)
25+
26+
# Feel free to take a look at our documentation (https://docs.sonarcloud.io/getting-started/github/)
27+
# or reach out to our community forum if you need some help (https://community.sonarsource.com/c/help/sc/9)
28+
29+
name: SonarCloud analysis
30+
31+
on:
32+
push:
33+
branches: [ "master" ]
34+
pull_request:
35+
branches: [ "master" ]
36+
workflow_dispatch:
37+
38+
permissions:
39+
pull-requests: read # allows SonarCloud to decorate PRs with analysis results
40+
41+
jobs:
42+
Sonar-Analysis-and-Report:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v3
46+
- name: Set up JDK 11
47+
uses: actions/setup-java@v3
48+
with:
49+
java-version: '11'
50+
distribution: 'temurin'
51+
cache: maven
52+
53+
- name: Jacoco Report and SonarCloud Analysis
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information
56+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # Generate a token on Sonarcloud.io, add it to the secrets of this repo with the name SONAR_TOKEN (Settings > Secrets > Actions > add new repository secret)
57+
run: mvn -B verify --file pom.xml -Pcoverage sonar:sonar -Dsonar.projectKey=mastodon-sc_mastodon-deep-lineage -Dsonar.organization=mastodon-sc
58+
59+
- name: Upload artifacts for subsequent review
60+
uses: actions/upload-artifact@master
61+
with:
62+
name: generated-reports
63+
path: |
64+
target/site
65+
target/dependency-check-report.html

pom.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>
2424

2525
<enforcer.skip>true</enforcer.skip>
26+
27+
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
28+
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
29+
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
30+
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/target/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
31+
<sonar.language>java</sonar.language>
32+
<sonar.verbose>false</sonar.verbose>
2633
</properties>
2734

2835
<name>Deep Lineage Project Mastodon Plugins</name>
@@ -119,4 +126,38 @@
119126
<url>https://maven.scijava.org/content/groups/public</url>
120127
</repository>
121128
</repositories>
129+
130+
<profiles>
131+
<profile>
132+
<id>coverage</id>
133+
<build>
134+
<plugins>
135+
<plugin>
136+
<groupId>org.jacoco</groupId>
137+
<artifactId>jacoco-maven-plugin</artifactId>
138+
<version>0.8.7</version>
139+
<executions>
140+
<execution>
141+
<id>prepare-agent</id>
142+
<goals>
143+
<goal>prepare-agent</goal>
144+
</goals>
145+
</execution>
146+
<execution>
147+
<id>report</id>
148+
<goals>
149+
<goal>report</goal>
150+
</goals>
151+
<configuration>
152+
<formats>
153+
<format>XML</format>
154+
</formats>
155+
</configuration>
156+
</execution>
157+
</executions>
158+
</plugin>
159+
</plugins>
160+
</build>
161+
</profile>
162+
</profiles>
122163
</project>

0 commit comments

Comments
 (0)