Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sonar config and GH actions to match planetiler #31

Merged
merged 5 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Derived from planetiler (Apache License)
# https://github.com/onthegomap/planetiler/blob/main/.github/workflows/maven.yml

name: Maven CI

on:
Expand Down
81 changes: 81 additions & 0 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Derived from planetiler (Apache License)
# https://github.com/onthegomap/planetiler/blob/main/.github/workflows/sonar.yml

name: Analyze

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
sonar:
name: Analyze with Sonar
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v3
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
submodules: true
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
cache: 'maven'
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Analyze with SonarCloud
working-directory: tiles
run: |
mvn -Dspotless.check.skip -Pcoverage -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
env:
# Needed to get some information about the pull request, if any
GITHUB_TOKEN: ${{ github.token }}
# Read-only user, use this token to link SonarLint to SonarCloud as well
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Wait for SonarCloud API to update...
run: "sleep 10"
- name: Upload annotations on PRs
if: ${{ github.event_name == 'pull_request' }}
uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
script: |
const pr = context.payload.pull_request.number;
const url = `https://sonarcloud.io/api/issues/search?pullRequest=${pr}&s=FILE_LINE&resolved=false&sinceLeakPeriod=true&ps=100&facets=severities%2Ctypes&componentKeys=protomaps_basemaps&organization=protomaps&additionalFields=_all`;
console.log("Fetching " + url);
const response = await github.request(url);
console.log("Got " + JSON.stringify(response.data));
response.data.issues.forEach(issue => {
try {
if (issue.severity === 'INFO') return;
const textRange = issue.textRange;
const rule = encodeURIComponent(issue.rule);
const message = [
issue.message,
'',
`rule: ${issue.rule} (https://sonarcloud.io/organizations/protomaps/rules?open=${rule}&rule_key=${rule})`,
`issue url: https://sonarcloud.io/project/issues?pullRequest=${pr}&open=${encodeURIComponent(issue.key)}&id=protomaps_basemaps`
].join('\n');
const args = {
title: `${issue.severity} ${issue.type}`,
file: issue.component.replace(/^[^:]*:/, ''),
startLine: textRange.startLine,
endLine: textRange.endLine,
startColumn: textRange.startOffset,
endColumn: textRange.endOffset
};
core.warning(message, args);
console.log(args);
} catch (e) {
core.error(`Unable to parse sonar issue: ${JSON.stringify(issue)}`);
}
});
32 changes: 32 additions & 0 deletions tiles/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<planetiler.version>0.6-SNAPSHOT</planetiler.version>
<junit.version>5.9.2</junit.version>
<mainClass>com.protomaps.basemap.Basemap</mainClass>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.organization>protomaps</sonar.organization>
<sonar.projectKey>protomaps_basemaps</sonar.projectKey>
<sonar.moduleKey>${project.artifactId}</sonar.moduleKey>
</properties>

<groupId>com.protomaps.basemap</groupId>
Expand Down Expand Up @@ -155,4 +159,32 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>coverage</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
22 changes: 22 additions & 0 deletions tiles/sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
sonar.issue.ignore.multicriteria=js1659,js3358,js106,js125,js2699,js3776,js1121,js107,js1192
# subjective
sonar.issue.ignore.multicriteria.js1659.ruleKey=java:S1659
sonar.issue.ignore.multicriteria.js1659.resourceKey=**/*.java
sonar.issue.ignore.multicriteria.js3358.ruleKey=java:S3358
sonar.issue.ignore.multicriteria.js3358.resourceKey=**/*.java
sonar.issue.ignore.multicriteria.js106.ruleKey=java:S106
sonar.issue.ignore.multicriteria.js106.resourceKey=**/*.java
sonar.issue.ignore.multicriteria.js125.ruleKey=java:S125
sonar.issue.ignore.multicriteria.js125.resourceKey=**/*.java
sonar.issue.ignore.multicriteria.js3776.ruleKey=java:S3776
sonar.issue.ignore.multicriteria.js3776.resourceKey=**/*.java
sonar.issue.ignore.multicriteria.js1121.ruleKey=java:S1121
sonar.issue.ignore.multicriteria.js1121.resourceKey=**/*.java
sonar.issue.ignore.multicriteria.js107.ruleKey=java:S107
sonar.issue.ignore.multicriteria.js107.resourceKey=**/*.java
sonar.issue.ignore.multicriteria.js1192.ruleKey=java:S1192
sonar.issue.ignore.multicriteria.js1192.resourceKey=**/*.java

# tests use assertion helpers
sonar.issue.ignore.multicriteria.js2699.ruleKey=java:S2699
sonar.issue.ignore.multicriteria.js2699.resourceKey=**/*.java