name: Pull request check

on:
  pull_request:
    branches: [ master ]

jobs:
  build:
    name: Build, test and analyze
    runs-on: ubuntu-latest
    permissions:
      checks: write

    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of SonarQube 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 check sonarqube --info
      - name: Publish unit test results
        uses: EnricoMi/publish-unit-test-result-action@v1.30
        if: always()
        with:
          files: '**/build/test-results/test/*.xml'

name: Pull request check

on:
  pull_request:
    branches: [ master ]

jobs:
  build:
    name: Build, test and analyze
    runs-on: ubuntu-latest
    permissions:
      checks: write
      issues: write

    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of SonarQube 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 check sonarqube --info
      - name: Publish unit test results
        uses: EnricoMi/publish-unit-test-result-action@v1.30
        if: always()
        with:
          files: '**/build/test-results/test/*.xml'

Add permission to write issues
Add permission to write issues

To allow the publish unit tests action to add a comment to the PR.
