sonar #612
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: sonar | |
on: | |
workflow_run: | |
workflows: [tests] | |
types: [completed] | |
jobs: | |
get-info: | |
if: github.event.workflow_run.conclusion == 'success' | |
runs-on: ubuntu-latest | |
outputs: | |
sourceHeadBranch: ${{ fromJSON(steps.workflow-run-info.outputs.data).head_branch }} | |
sourceHeadSha: ${{ fromJSON(steps.workflow-run-info.outputs.data).head_sha }} | |
pullRequestNumber: ${{ steps.pr-number.outputs.number }} | |
steps: | |
- uses: octokit/[email protected] | |
id: workflow-run-info | |
with: | |
route: GET /repos/{owner}/{repo}/actions/runs/{run_id} | |
owner: harrel56 | |
repo: json-schema | |
run_id: ${{ github.event.workflow_run.id }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- uses: octokit/[email protected] | |
if: fromJSON(steps.workflow-run-info.outputs.data).event == 'pull_request' | |
id: pr-info | |
with: | |
route: GET /repos/{owner}/{repo}/pulls | |
owner: harrel56 | |
repo: json-schema | |
state: all | |
head: 'harrel56:${{ fromJSON(steps.workflow-run-info.outputs.data).head_branch }}' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract PR number | |
id: pr-number | |
if: steps.pr-info.outputs.data != '' | |
run: echo "number=${{ fromJSON(steps.pr-info.outputs.data)[0].number }}" >> $GITHUB_OUTPUT | |
sonar-cloud: | |
if: github.event.workflow_run.conclusion == 'success' | |
needs: get-info | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
repository: ${{ github.event.workflow_run.head_repository.full_name }} | |
ref: ${{ github.event.workflow_run.head_branch }} | |
fetch-depth: 0 | |
- name: Download code coverage | |
uses: dawidd6/action-download-artifact@v6 | |
with: | |
workflow: tests.yml | |
commit: ${{ github.event.workflow_run.head_sha }} | |
name: report-output | |
path: build | |
- name: Setup java | |
uses: actions/setup-java@v4 | |
with: | |
distribution: ${{ vars.JAVA_VENDOR }} | |
java-version: ${{ vars.JAVA_VERSION }} | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@v4 | |
with: | |
gradle-version: wrapper | |
- name: SonarCloud analyze master | |
if: needs.get-info.outputs.pullRequestNumber == '' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: ./gradlew sonar --no-daemon | |
- name: SonarCloud analyze PR | |
if: needs.get-info.outputs.pullRequestNumber != '' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: > | |
./gradlew sonar --no-daemon | |
-Dsonar.scm.revision=${{ needs.get-info.outputs.sourceHeadSha }} | |
-Dsonar.pullrequest.key=${{ needs.get-info.outputs.pullRequestNumber }} | |
-Dsonar.pullrequest.branch=${{ needs.get-info.outputs.sourceHeadBranch }} | |
-Dsonar.pullrequest.base=master |