|
| 1 | +# |
| 2 | +# Copyright (C) 2015 Red Hat, Inc. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# |
| 16 | + |
| 17 | +name: Sonar PR Report Publish |
| 18 | + |
| 19 | +on: |
| 20 | + workflow_run: |
| 21 | + workflows: [Sonar PR Report Request] |
| 22 | + types: |
| 23 | + - completed |
| 24 | + |
| 25 | +concurrency: |
| 26 | + # Only run once for latest commit per ref and cancel other (previous) runs. |
| 27 | + group: ci-sonar-kubernetes-client-${{ github.ref }} |
| 28 | + cancel-in-progress: true |
| 29 | + |
| 30 | +permissions: |
| 31 | + contents: read |
| 32 | + |
| 33 | +jobs: |
| 34 | + sonar: |
| 35 | + name: Sonar |
| 36 | + runs-on: ubuntu-latest |
| 37 | + env: |
| 38 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 39 | + BASE_BRANCH: main |
| 40 | + PR_BRANCH: ${{ github.event.workflow_run.head_branch }} |
| 41 | + PR_AUTHOR: ${{ github.event.sender.login }} |
| 42 | + GITHUB_REPO: ${{ github.repository }} |
| 43 | + SONAR_LOGIN_TOKEN: ${{ secrets.SONAR_LOGIN_TOKEN }} |
| 44 | + steps: |
| 45 | + - name: Checkout |
| 46 | + uses: actions/checkout@v4 |
| 47 | + with: |
| 48 | + # Shallow clones should be disabled for a better relevancy of analysis |
| 49 | + fetch-depth: 0 |
| 50 | + - name: Setup Java 17 |
| 51 | + uses: actions/setup-java@v4 |
| 52 | + with: |
| 53 | + java-version: '17' |
| 54 | + distribution: 'temurin' |
| 55 | + - name: Get PR number |
| 56 | + run: | |
| 57 | + PR_QUERY_RESULT=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ |
| 58 | + "https://api.github.com/repos/$GITHUB_REPO/pulls?head=$PR_AUTHOR:$PR_BRANCH&state=open" | jq '.[0].number') |
| 59 | + if [ "$PR_QUERY_RESULT" = "null" ] || [ -z "$PR_QUERY_RESULT" ]; then |
| 60 | + echo "Could not find PR number for $PR_AUTHOR:$PR_BRANCH" |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | + echo "PR_NUMBER=$PR_QUERY_RESULT" >> $GITHUB_ENV |
| 64 | + - name: Sonar |
| 65 | + run: make sonar-pr-report |
0 commit comments