Skip to content

Commit

Permalink
ci: sonar analysis (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
mghilardelli authored Oct 30, 2024
1 parent 35be0d0 commit 51b114c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ jobs:
cache: maven
- name: Run the Maven verify phase
run: mvn --batch-mode --update-snapshots verify
- name: SonarCloud scan for PR
uses: sonarsource/sonarcloud-github-action@383f7e52eae3ab0510c3cb0e7d9d150bbaeab838 # v3
if: github.event_name == 'pull_request'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: backend
args: |
-Dsonar.pullrequest.base=${{ github.base_ref }}
-Dsonar.pullrequest.branch=${{ github.head_ref }}
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
- name: SonarCloud scan for Push
uses: sonarsource/sonarcloud-github-action@383f7e52eae3ab0510c3cb0e7d9d150bbaeab838 # v3
if: github.event_name == 'push'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: backend
args: |
-Dsonar.branch.name=${{ github.head_ref }}
- name: Login to GitHub Container Registry
if: github.ref == 'refs/heads/main'
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
Expand Down
28 changes: 28 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,34 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.12</version>
<configuration>
<excludes>**/*.jar</excludes>
</configuration>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<formats>
<format>XML</format>
</formats>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
16 changes: 16 additions & 0 deletions backend/sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
sonar.projectKey=SchweizerischeBundesbahnen_DAS
sonar.organization=schweizerischebundesbahnen
sonar.host.url=https://sonarcloud.io

# --- optional properties ---

# defaults to project key
sonar.projectName=DAS/backend
# defaults to 'not provided'
#sonar.projectVersion=1.0

# Path is relative to the sonar-project.properties file. Defaults to .
#sonar.sources=.

# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
5 changes: 0 additions & 5 deletions sonar-project.properties

This file was deleted.

0 comments on commit 51b114c

Please sign in to comment.