Skip to content

Commit befcdd1

Browse files
authored
Merge pull request #286 from graphql-java-kickstart/feature/sonar-analysis-on-pr
Include Sonar analysis on PRs
2 parents c5609b7 + a5c0f1b commit befcdd1

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

.github/workflows/pull-request.yml

+30-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
branches-ignore:
55
- master
66
pull_request:
7-
7+
types: [opened, synchronize, reopened]
88
jobs:
99
validation:
1010
name: Gradle Wrapper Validation
@@ -49,3 +49,32 @@ jobs:
4949
if: matrix.os == 'windows-latest'
5050
shell: cmd
5151
run: gradlew --info check
52+
build:
53+
name: Sonar analysis
54+
needs: validation
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@v2
58+
with:
59+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
60+
- name: Set up JDK 11
61+
uses: actions/setup-java@v1
62+
with:
63+
java-version: 11
64+
- name: Cache SonarCloud packages
65+
uses: actions/cache@v1
66+
with:
67+
path: ~/.sonar/cache
68+
key: ${{ runner.os }}-sonar
69+
restore-keys: ${{ runner.os }}-sonar
70+
- name: Cache Gradle packages
71+
uses: actions/cache@v1
72+
with:
73+
path: ~/.gradle/caches
74+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
75+
restore-keys: ${{ runner.os }}-gradle
76+
- name: Build and analyze
77+
env:
78+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
79+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
80+
run: ./gradlew build jacocoTestReport sonarqube --info

.github/workflows/snapshot.yml

+29
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,32 @@ jobs:
6666
BINTRAY_USER: ${{ secrets.BINTRAY_USER }}
6767
BINTRAY_PASS: ${{ secrets.BINTRAY_PASSWORD }}
6868
run: ./gradlew artifactoryPublish -Dsnapshot=true -Dbuild.number=${{ env.GITHUB_RUN_NUMBER }}
69+
sonar:
70+
name: Sonar analysis
71+
needs: validation
72+
runs-on: ubuntu-latest
73+
steps:
74+
- uses: actions/checkout@v2
75+
with:
76+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
77+
- name: Set up JDK 11
78+
uses: actions/setup-java@v1
79+
with:
80+
java-version: 11
81+
- name: Cache SonarCloud packages
82+
uses: actions/cache@v1
83+
with:
84+
path: ~/.sonar/cache
85+
key: ${{ runner.os }}-sonar
86+
restore-keys: ${{ runner.os }}-sonar
87+
- name: Cache Gradle packages
88+
uses: actions/cache@v1
89+
with:
90+
path: ~/.gradle/caches
91+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
92+
restore-keys: ${{ runner.os }}-gradle
93+
- name: Build and analyze
94+
env:
95+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
96+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
97+
run: ./gradlew build jacocoTestReport sonarqube --info

build.gradle

+19
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,22 @@ plugins {
3737
id 'io.franzbecker.gradle-lombok' version '3.2.0' apply false
3838
id "com.jfrog.artifactory" version "4.11.0" apply false
3939
id "biz.aQute.bnd.builder" version "5.1.2" apply false
40+
id "org.sonarqube" version "3.0"
41+
id "jacoco"
42+
}
43+
44+
sonarqube {
45+
properties {
46+
property "sonar.projectKey", "graphql-java-kickstart_graphql-java-servlet"
47+
property "sonar.organization", "graphql-java-kickstart"
48+
property "sonar.host.url", "https://sonarcloud.io"
49+
}
4050
}
4151

4252
subprojects {
4353
apply plugin: 'idea'
54+
apply plugin: 'jacoco'
55+
apply plugin: 'org.sonarqube'
4456
apply plugin: 'java'
4557
apply plugin: 'maven-publish'
4658
apply plugin: "com.jfrog.bintray"
@@ -75,6 +87,13 @@ subprojects {
7587
sha256 = ""
7688
}
7789

90+
jacocoTestReport {
91+
reports {
92+
xml.enabled = true
93+
html.enabled = false
94+
csv.enabled = false
95+
}
96+
}
7897

7998
if (!it.name.startsWith('example')) {
8099

0 commit comments

Comments
 (0)