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 | |
container: docker.io/ogdf/clang:15 | |
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: "Add workspace as a safe directory in containers" | |
run: git config --system --add safe.directory $GITHUB_WORKSPACE | |
- 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 PR base branch | |
if: github.event.workflow_run.event == 'pull_request' | |
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: 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.full_name }} | |
- name: Install sonar-scanner | |
uses: SonarSource/sonarcloud-github-c-cpp@v2 | |
- name: SonarCloud PR Scan | |
if: github.event.workflow_run.event == 'pull_request' | |
run: > | |
sonar-scanner | |
-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.head_branch }} | |
-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 }} | |
- name: SonarCloud non-PR Scan | |
if: github.event.workflow_run.event != 'pull_request' | |
run: > | |
sonar-scanner | |
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} | |
-Dproject.settings=sonar-project.properties | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |