|
| 1 | +# Copyright © 2020 Cask Data, Inc. |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 3 | +# use this file except in compliance with the License. You may obtain a copy of |
| 4 | +# the License at |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# Unless required by applicable law or agreed to in writing, software |
| 7 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 8 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 9 | +# License for the specific language governing permissions and limitations under |
| 10 | +# the License. |
| 11 | + |
| 12 | +# This workflow will build a Java project with Maven |
| 13 | +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven |
| 14 | +# Note: Any changes to this workflow would be used only after merging into develop |
| 15 | +name: Build with test coverage and Sonar |
| 16 | + |
| 17 | +on: |
| 18 | + workflow_run: |
| 19 | + workflows: |
| 20 | + - Trigger build |
| 21 | + types: |
| 22 | + - completed |
| 23 | + |
| 24 | +jobs: |
| 25 | + build: |
| 26 | + runs-on: k8s-runner-build |
| 27 | + |
| 28 | + if: ${{ github.event.workflow_run.conclusion != 'skipped' }} |
| 29 | + |
| 30 | + steps: |
| 31 | + # Pinned 1.0.0 version |
| 32 | + - uses: haya14busa/action-workflow_run-status@967ed83efa565c257675ed70cfe5231f062ddd94 |
| 33 | + |
| 34 | + - uses: actions/checkout@v3 |
| 35 | + with: |
| 36 | + ref: ${{ github.event.workflow_run.head_sha }} |
| 37 | + submodules: recursive |
| 38 | + |
| 39 | + - name: Cache |
| 40 | + uses: actions/cache@v3 |
| 41 | + with: |
| 42 | + path: ~/.m2/repository11 |
| 43 | + key: ${{ runner.os }}-maven-${{ github.workflow }}-${{ hashFiles('**/pom.xml') }} |
| 44 | + restore-keys: | |
| 45 | + ${{ runner.os }}-maven-${{ github.workflow }} |
| 46 | +
|
| 47 | + - name: Cache SonarCloud packages |
| 48 | + uses: actions/cache@v3 |
| 49 | + with: |
| 50 | + path: ~/.sonar/cache |
| 51 | + key: ${{ runner.os }}-sonar |
| 52 | + restore-keys: ${{ runner.os }}-sonar |
| 53 | + |
| 54 | + - name: Build with Maven |
| 55 | + run: >- |
| 56 | + mvn clean verify -fae -T 2 -B -V -Dmaven.test.failure.ignore |
| 57 | + -Dmaven.repo.local=$HOME/.m2/repository11 |
| 58 | + -DcloudBuild |
| 59 | + -Pcoverage |
| 60 | + -Dmaven.wagon.http.retryHandler.count=3 |
| 61 | + -Dmaven.wagon.httpconnectionManager.ttlSeconds=25 |
| 62 | +
|
| 63 | + - name: Archive build artifacts |
| 64 | + uses: actions/upload-artifact@v3 |
| 65 | + if: always() |
| 66 | + with: |
| 67 | + name: Build debug files |
| 68 | + path: | |
| 69 | + **/target/rat.txt |
| 70 | + **/target/surefire-reports/* |
| 71 | +
|
| 72 | + - name: Validate PR |
| 73 | + id: validate_pr |
| 74 | + # For whatever reason we get PR 69 for develop branch with both head and base as develop. |
| 75 | + if: ${{ github.event.workflow_run.pull_requests[0].head.ref != github.event.workflow_run.pull_requests[0].base.ref }} |
| 76 | + run: | |
| 77 | + echo ":set-output pr-key=${{ github.event.workflow_run.pull_requests[0].number }}" |
| 78 | + echo ":set-output pr-branch=${{ github.event.workflow_run.pull_requests[0].head.ref }}" |
| 79 | + echo ":set-output pr-base=${{ github.event.workflow_run.pull_requests[0].base.ref }}" |
| 80 | +
|
| 81 | + - name: Sonar report |
| 82 | + env: |
| 83 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 84 | + JAVA_HOME: /usr/lib/jvm/java-11-openjdk-amd64 |
| 85 | + run: >- |
| 86 | + mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -fae -T 2 -B -V |
| 87 | + -Dmaven.repo.local=$HOME/.m2/repository11 |
| 88 | + -DcloudBuild |
| 89 | + -Pcoverage |
| 90 | + -Dmaven.wagon.http.retryHandler.count=3 |
| 91 | + -Dmaven.wagon.httpconnectionManager.ttlSeconds=25 |
| 92 | + -Dsonar.pullrequest.key=${{ steps.validate_pr.outputs.pr-key }} |
| 93 | + -Dsonar.pullrequest.branch=${{ steps.validate_pr.outputs.pr-branch }} |
| 94 | + -Dsonar.pullrequest.base=${{ steps.validate_pr.outputs.pr-base }} |
| 95 | + -Dsonar.branch.name=${{ github.event.workflow_run.head_branch }} |
| 96 | +
|
| 97 | + - name: Archive build artifacts |
| 98 | + uses: actions/upload-artifact@v3 |
| 99 | + if: always() |
| 100 | + with: |
| 101 | + name: Build debug files |
| 102 | + path: | |
| 103 | + **/target/rat.txt |
| 104 | + **/target/surefire-reports/* |
| 105 | +
|
| 106 | + - name: Surefire Report |
| 107 | + # Pinned 3.5.2 version |
| 108 | + uses: mikepenz/action-junit-report@16a9560bd02f11e7e3bf6b3e2ef6bba6c9d07c32 |
| 109 | + if: always() |
| 110 | + with: |
| 111 | + report_paths: '**/target/surefire-reports/TEST-*.xml' |
| 112 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 113 | + detailed_summary: true |
| 114 | + commit: ${{ github.event.workflow_run.head_sha }} |
| 115 | + check_name: Sonar Build Test Report |
0 commit comments