Sonarcloud Scan #2
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: Sonarcloud Scan | |
on: | |
workflow_run: | |
workflows: [ "Check, Build and Test" ] | |
types: [ completed ] | |
jobs: | |
sonar: | |
runs-on: ubuntu-latest | |
if: github.event.workflow_run.conclusion == 'success' | |
steps: | |
- name: Dump GitHub context | |
env: | |
GITHUB_CONTEXT: ${{ toJson(github) }} | |
STEPS_CONTEXT: ${{ toJson(steps) }} | |
RUNNER_CONTEXT: ${{ toJson(runner) }} | |
STRATEGY_CONTEXT: ${{ toJson(strategy) }} | |
run: | | |
echo "{\"github\": $GITHUB_CONTEXT, \"steps\": $STEPS_CONTEXT, \"runner\": $RUNNER_CONTEXT, \"strategy\": $STRATEGY_CONTEXT}" | |
echo | |
env | |
- name: Download Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
run_id: ${{ github.event.workflow_run.id }} | |
repository: ${{ github.event.workflow_run.repository.name }} | |
- name: Request GitHub API for PR data | |
uses: octokit/request-action@v2 | |
id: get_pr_data | |
with: | |
route: GET /repos/${{ github.event.repository.full_name }}/pulls/${{ github.event.workflow_run.pull_requests[0].id }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
repository: ${{ github.event.workflow_run.head_repository.full_name }} | |
ref: ${{ github.event.workflow_run.head_branch }} | |
fetch-depth: 0 | |
- name: Checkout base branch | |
run: | | |
git remote add upstream ${{ github.event.repository.clone_url }} | |
git fetch upstream | |
git checkout -B ${{ github.event.workflow_run.pull_requests[0].base.ref }} upstream/${{ github.event.workflow_run.pull_requests[0].base.ref }} | |
git checkout ${{ github.event.workflow_run.head_branch }} | |
git clean -ffdx && git reset --hard HEAD | |
git reset --hard upstream/${{ github.event.workflow_run.pull_requests[0].base.ref }} sonar-project.properties | |
- name: SonarCloud Scan | |
uses: sonarsource/sonarcloud-github-action@v2.1 | |
with: | |
projectBaseDir: '.' | |
args: > | |
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} | |
-Dsonar.pullrequest.key=${{ github.event.workflow_run.pull_requests[0].number }} | |
-Dsonar.pullrequest.branch=${{ github.event.workflow_run.pull_requests[0].head.ref }} | |
-Dsonar.pullrequest.base=${{ github.event.workflow_run.pull_requests[0].base.ref }} | |
-Dproject.settings=sonar-project.properties | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |