diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 4573af8925bed9..543587cc631ff1 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -21,8 +21,8 @@ on: push: branches: - master - pull_request: - types: [opened, synchronize, reopened] + pull_request_target: + jobs: build: name: Build @@ -32,26 +32,40 @@ jobs: SONAR_SERVER_URL: "https://sonarcloud.io" BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Changed Java Files + id: java-changes + uses: tj-actions/changed-files@a59f800cbb60ed483623848e31be67659a2940f8 + with: + sha: "${{ github.pull_request.sha }}" + base_sha: "${{ github.sha }}" + files: | + **/*.java + **/*.xml + - name: Set up JDK 11 - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 + if: steps.java-changes.outputs.any_changed == 'true' with: java-version: 11 - name: Cache SonarCloud packages - uses: actions/cache@v1 + uses: actions/cache@v3 with: path: ~/.sonar/cache key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar + - name: Cache Maven packages - uses: actions/cache@v1 + uses: actions/cache@v3 with: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2 - name: Setup thrift + if: steps.java-changes.outputs.any_changed == 'true' run: | sudo apt-get update sudo DEBIAN_FRONTEND=noninteractive apt-get install -y thrift-compiler=0.13.0-2build2 @@ -59,9 +73,10 @@ jobs: mkdir -p thirdparty/installed/bin/ cd thirdparty/installed/bin/ && ln -s /usr/bin/thrift thrift - name: Analyze FE + if: steps.java-changes.outputs.any_changed == 'true' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: | cd fe mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=apache_incubator-doris -DskipTests