|
1 | 1 | name: QA |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
5 | | - branches: |
6 | | - - develop |
7 | | - - master |
8 | | - pull_request: |
| 4 | + workflow_run: |
| 5 | + workflows: [Pre-QA] |
| 6 | + types: [completed] |
9 | 7 |
|
10 | 8 | jobs: |
| 9 | + |
11 | 10 | QA: |
12 | 11 | runs-on: ubuntu-latest |
13 | | - if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.event.repository.full_name |
| 12 | + if: github.event.workflow_run.conclusion == 'success' |
14 | 13 | steps: |
15 | | - |
| 14 | + - name: Download PR number artifact |
| 15 | + if: github.event.workflow_run.event == 'pull_request' |
| 16 | + uses: dawidd6/action-download-artifact@v2 |
| 17 | + with: |
| 18 | + workflow: ${{ github.event.workflow_run.name }} |
| 19 | + run_id: ${{ github.event.workflow_run.id }} |
| 20 | + name: PR_NUMBER |
| 21 | + - name: Read PR_NUMBER.txt |
| 22 | + if: github.event.workflow_run.event == 'pull_request' |
| 23 | + id: pr_number |
| 24 | + uses: juliangruber/read-file-action@v1 |
| 25 | + with: |
| 26 | + path: ./PR_NUMBER.txt |
| 27 | + - name: Request GitHub API for PR data |
| 28 | + if: github.event.workflow_run.event == 'pull_request' |
| 29 | + |
| 30 | + id: get_pr_data |
16 | 31 | with: |
17 | | - fetch-depth: '' |
18 | | - - run: | |
19 | | - git fetch --prune --unshallow |
| 32 | + route: GET /repos/{full_name}/pulls/{number} |
| 33 | + number: ${{ steps.pr_number.outputs.content }} |
| 34 | + full_name: ${{ github.event.repository.full_name }} |
| 35 | + env: |
| 36 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + - uses: actions/checkout@v3 |
| 38 | + with: |
| 39 | + repository: ${{ github.event.workflow_run.head_repository.full_name }} |
| 40 | + ref: ${{ github.event.workflow_run.head_branch }} |
| 41 | + fetch-depth: 0 |
| 42 | + - name: Checkout base branch |
| 43 | + if: github.event.workflow_run.event == 'pull_request' |
| 44 | + run: | |
| 45 | + git remote add upstream ${{ github.event.repository.clone_url }} |
| 46 | + git fetch upstream |
| 47 | + git checkout -B ${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} upstream/${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} |
| 48 | + git checkout ${{ github.event.workflow_run.head_branch }} |
| 49 | + git clean -ffdx && git reset --hard HEAD |
20 | 50 | - name: Set up JDK 11 |
21 | | - uses: actions/setup-java@v2 |
| 51 | + uses: actions/setup-java@v3 |
22 | 52 | with: |
23 | 53 | java-version: 11 |
24 | | - distribution: 'adopt' |
25 | | - - name: SonarCloud Scan |
26 | | - run: ./gradlew check sonarqube |
| 54 | + distribution: 'temurin' |
| 55 | + - name: SonarCloud Scan on PR |
| 56 | + if: github.event.workflow_run.event == 'pull_request' |
| 57 | + run: ./gradlew check sonarqube -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} -Dsonar.pullrequest.key=${{ fromJson(steps.get_pr_data.outputs.data).number }} -Dsonar.pullrequest.branch=${{ fromJson(steps.get_pr_data.outputs.data).head.ref }} -Dsonar.pullrequest.base=${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} |
| 58 | + env: |
| 59 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 60 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + - name: SonarCloud Scan on push |
| 62 | + if: github.event.workflow_run.event == 'push' && github.event.workflow_run.head_repository.full_name == github.event.repository.full_name |
| 63 | + run: ./gradlew check sonarqube -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} -Dsonar.branch.name=${{ github.event.workflow_run.head_branch }} |
27 | 64 | env: |
28 | 65 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
29 | 66 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments