2023-05-27 11:40:06 +02:00
|
|
|
name: Sonar scan
|
2022-11-23 14:58:54 +01:00
|
|
|
|
2022-11-23 14:43:12 +01:00
|
|
|
on:
|
|
|
|
workflow_run:
|
2022-11-23 14:58:54 +01:00
|
|
|
workflows: [CI]
|
2022-11-23 14:43:12 +01:00
|
|
|
types: [completed]
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
sonar:
|
2023-05-27 11:40:06 +02:00
|
|
|
name: Sonar scan on "${{ github.event.workflow_run.head_branch }}"
|
2022-11-23 14:43:12 +01:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
if: github.event.workflow_run.conclusion == 'success'
|
|
|
|
|
|
|
|
steps:
|
2023-04-25 14:59:59 +02:00
|
|
|
- uses: actions/checkout@v3.5.2
|
2022-11-23 14:43:12 +01:00
|
|
|
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: actions/github-script@v6
|
|
|
|
with:
|
|
|
|
script: |
|
|
|
|
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
|
|
|
run_id: context.payload.workflow_run.id,
|
|
|
|
});
|
|
|
|
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
|
|
|
|
return artifact.name == "code-coverage"
|
|
|
|
})[0];
|
|
|
|
let download = await github.rest.actions.downloadArtifact({
|
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
|
|
|
artifact_id: matchArtifact.id,
|
|
|
|
archive_format: 'zip',
|
|
|
|
});
|
|
|
|
let fs = require('fs');
|
|
|
|
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/code-coverage.zip`, Buffer.from(download.data));
|
|
|
|
|
|
|
|
- name: 'Unzip code coverage'
|
|
|
|
run: unzip code-coverage.zip -d coverage
|
|
|
|
|
|
|
|
- name: SonarCloud scan
|
|
|
|
uses: sonarsource/sonarcloud-github-action@master
|
|
|
|
env:
|
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
|
|
|
with:
|
|
|
|
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 }}
|