diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 02eeb7cc..e3a5d868 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -4,7 +4,7 @@ on: branches-ignore: - master pull_request: - + types: [opened, synchronize, reopened] jobs: validation: name: Gradle Wrapper Validation @@ -49,3 +49,32 @@ jobs: if: matrix.os == 'windows-latest' shell: cmd run: gradlew --info check + build: + name: Sonar analysis + needs: validation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Cache SonarCloud packages + uses: actions/cache@v1 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Cache Gradle packages + uses: actions/cache@v1 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: Build and analyze + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: ./gradlew build jacocoTestReport sonarqube --info diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index 64eb3090..d758ef4c 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -66,3 +66,32 @@ jobs: BINTRAY_USER: ${{ secrets.BINTRAY_USER }} BINTRAY_PASS: ${{ secrets.BINTRAY_PASSWORD }} run: ./gradlew artifactoryPublish -Dsnapshot=true -Dbuild.number=${{ env.GITHUB_RUN_NUMBER }} + sonar: + name: Sonar analysis + needs: validation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Cache SonarCloud packages + uses: actions/cache@v1 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Cache Gradle packages + uses: actions/cache@v1 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: Build and analyze + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: ./gradlew build jacocoTestReport sonarqube --info diff --git a/build.gradle b/build.gradle index 9f961355..7cc8695b 100644 --- a/build.gradle +++ b/build.gradle @@ -37,10 +37,22 @@ plugins { id 'io.franzbecker.gradle-lombok' version '3.2.0' apply false id "com.jfrog.artifactory" version "4.11.0" apply false id "biz.aQute.bnd.builder" version "5.1.2" apply false + id "org.sonarqube" version "3.0" + id "jacoco" +} + +sonarqube { + properties { + property "sonar.projectKey", "graphql-java-kickstart_graphql-java-servlet" + property "sonar.organization", "graphql-java-kickstart" + property "sonar.host.url", "https://sonarcloud.io" + } } subprojects { apply plugin: 'idea' + apply plugin: 'jacoco' + apply plugin: 'org.sonarqube' apply plugin: 'java' apply plugin: 'maven-publish' apply plugin: "com.jfrog.bintray" @@ -75,6 +87,13 @@ subprojects { sha256 = "" } + jacocoTestReport { + reports { + xml.enabled = true + html.enabled = false + csv.enabled = false + } + } if (!it.name.startsWith('example')) {