-
-
Notifications
You must be signed in to change notification settings - Fork 114
68 lines (58 loc) · 2.79 KB
/
sonar.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: Sonar Analysis
on:
workflow_run:
workflows: ["Test application"]
types:
- completed
jobs:
sonar:
name: SonarQube Analysis
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
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: actions/github-script@v6
with:
script: |
console.log('Workflow run ID:', context.payload.workflow_run.id);
const artifactsResponse = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
console.log('Available artifacts:', artifactsResponse.data.artifacts.map(a => a.name));
const matchArtifact = artifactsResponse.data.artifacts.find(artifact =>
artifact.name === "coverage-report"
);
if (!matchArtifact) {
core.setFailed('No coverage-report artifact found. Available artifacts: ' +
artifactsResponse.data.artifacts.map(a => a.name).join(', '));
return;
}
console.log('Found coverage artifact:', matchArtifact.name, 'ID:', matchArtifact.id);
const 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}/coverage-report.zip`, Buffer.from(download.data));
- name: Extract coverage report
run: unzip coverage-report.zip
- name: SonarQube Scan
uses: SonarSource/[email protected]
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}
-Dsonar.coverage.jacoco.xmlReportPaths=coverage.xml
${{ github.event.workflow_run.pull_requests != null && format('-Dsonar.pullrequest.key={0}', github.event.workflow_run.pull_requests[0].number) || '' }}
${{ github.event.workflow_run.pull_requests != null && format('-Dsonar.pullrequest.branch={0}', github.event.workflow_run.pull_requests[0].head.ref) || '' }}
${{ github.event.workflow_run.pull_requests != null && format('-Dsonar.pullrequest.base={0}', github.event.workflow_run.pull_requests[0].base.ref) || '' }}