Skip to content

Commit

Permalink
Add Sonar analysis (#115)
Browse files Browse the repository at this point in the history
* Add Sonar analyse

* Add Jacoco

* Add key
  • Loading branch information
loicgreffier authored Feb 11, 2025
1 parent 78fbb72 commit b2195f5
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 3 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ jobs:
distribution: 'temurin'
cache: maven

- name: Cache SonarQube packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Check style
run: mvn checkstyle:check

Expand All @@ -41,6 +55,13 @@ jobs:
name: docsource-jar
path: target/docsource.jar

- name: Sonar
if: env.SONAR_TOKEN != ''
run: mvn verify sonar:sonar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- name: Docker
run: mvn clean package -DskipTests jib:dockerBuild

Expand Down Expand Up @@ -73,6 +94,13 @@ jobs:
java-version: '21.0.1'
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Check style
run: mvn checkstyle:check

Expand Down
40 changes: 37 additions & 3 deletions .github/workflows/push_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,28 @@ jobs:
distribution: 'temurin'
cache: maven

- name: Cache SonarQube packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Check style
run: mvn checkstyle:check

- name: Build and test
run: mvn clean package
id: build
run: |
mvn clean package
echo current_version=$(echo $(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)) >> $GITHUB_OUTPUT
- name: Publish test report
if: always()
Expand All @@ -40,7 +57,14 @@ jobs:
name: docsource-jar
path: target/docsource.jar

- name: Sonar
run: mvn verify sonar:sonar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- name: Docker
if: endsWith(steps.build.outputs.current_version, '-SNAPSHOT')
run: mvn clean package -DskipTests jib:build -Djib.to.auth.username=$DOCKER_USER -Djib.to.auth.password=$DOCKER_TOKEN
env:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
Expand Down Expand Up @@ -75,11 +99,21 @@ jobs:
java-version: '21.0.1'
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Check style
run: mvn checkstyle:check

- name: Build and test
run: mvn clean package -Pnative -PnativeTest
id: build
run: |
mvn clean package -Pnative -PnativeTest
echo current_version=$(echo $(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)) >> $GITHUB_OUTPUT
- name: Publish native test report
if: always()
Expand All @@ -94,7 +128,7 @@ jobs:
path: target/docsource${{ matrix.extension }}

- name: Docker
if: matrix.os == 'ubuntu-latest'
if: endsWith(steps.build.outputs.current_version, '-SNAPSHOT') && matrix.os == 'ubuntu-latest'
run: mvn clean package -DskipTests -Pnative jib:build -Djib.to.auth.username=$DOCKER_USER -Djib.to.auth.password=$DOCKER_TOKEN
env:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ jobs:
distribution: temurin
cache: maven

- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Build and test
run: mvn clean package

Expand Down Expand Up @@ -93,6 +100,13 @@ jobs:
java-version: '21.0.1'
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Build and test
run: mvn clean package -Pnative -PnativeTest

Expand Down
38 changes: 38 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@
<properties>
<checkstyle.version>10.21.2</checkstyle.version>
<commons-io.version>2.18.0</commons-io.version>
<jacoco.version>0.8.12</jacoco.version>
<jansi.version>2.4.1</jansi.version>
<jib-maven-plugin.version>3.4.4</jib-maven-plugin.version>
<lombok.version>1.18.36</lombok.version>
<java.version>21</java.version>
<picocli.version>4.7.6</picocli.version>
<picocli.jansi.graalvm.version>1.2.0</picocli.jansi.graalvm.version>
<maven.checkstyle.plugin>3.6.0</maven.checkstyle.plugin>
<sonar.organization>loicgreffier</sonar.organization>
<sonar.projectKey>loicgreffier_docsource</sonar.projectKey>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>

<dependencies>
Expand Down Expand Up @@ -114,6 +118,40 @@
</configuration>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>target/jacoco.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>target/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
Expand Down

0 comments on commit b2195f5

Please sign in to comment.