Skip to content

Commit fbec984

Browse files
committed
ci: fix download reports on sonarqube
1 parent 0a54f12 commit fbec984

File tree

2 files changed

+118
-28
lines changed

2 files changed

+118
-28
lines changed

Diff for: .github/workflows/pr.yml

+72-26
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,75 @@ jobs:
4141
uses: ./.github/workflows/backwards-compatibility-test.yml
4242

4343
# Test sonarcloud analysis
44-
# pr-analysis:
45-
# name: SonarCloud Pr Analysis
46-
# runs-on: ubuntu-latest
47-
# needs: pr-test
48-
# steps:
49-
# - uses: actions/checkout@v4
50-
# with:
51-
# fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
52-
# # Download reports
53-
# - uses: ./.github/actions/download-coverage-report
54-
# - uses: ./.github/actions/download-lint-report
55-
# - name: 'Verify reports'
56-
# run: |
57-
# pwd
58-
# echo 'Lint report'
59-
# ls -la ./coverage/packages/ngx-deploy-npm/lcov.info
60-
# echo 'Coverage report'
61-
# ls -la ./reports/ngx-deploy-npm/lint-report.info
62-
# - name: SonarCloud Scan
63-
# uses: SonarSource/sonarqube-scan-action@v4.2.1
64-
# env:
65-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
66-
# SONAR_TOKEN: ${{ secrets.SONARQUBE_SCANNER }}
67-
# with:
68-
# args: >
69-
# -Dsonar.pullrequest.key=${{ github.env.PR_NUMBER }}
44+
pr-analysis:
45+
name: SonarCloud Pr Analysis
46+
runs-on: ubuntu-latest
47+
needs: pr-test
48+
steps:
49+
- uses: actions/checkout@v4
50+
with:
51+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
52+
53+
# Download reports
54+
- name: 'Download reports'
55+
uses: actions/github-script@v6
56+
with:
57+
script: |
58+
async function downloadArtifact(artifactName) {
59+
console.log(`Looking for artifact: ${artifactName}`);
60+
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
61+
owner: context.repo.owner,
62+
repo: context.repo.repo,
63+
run_id: context.payload.workflow_run.id,
64+
});
65+
console.log('Available artifacts:', allArtifacts.data.artifacts.map(a => a.name));
66+
67+
let matchArtifact = allArtifacts.data.artifacts.find((artifact) => {
68+
return artifact.name === artifactName;
69+
});
70+
71+
if (!matchArtifact) {
72+
throw new Error(`Artifact "${artifactName}" not found!`);
73+
}
74+
75+
let download = await github.rest.actions.downloadArtifact({
76+
owner: context.repo.owner,
77+
repo: context.repo.repo,
78+
artifact_id: matchArtifact.id,
79+
archive_format: 'zip',
80+
});
81+
82+
let fs = require('fs');
83+
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${artifactName}.zip`, Buffer.from(download.data));
84+
return artifactName;
85+
}
86+
87+
// Download both artifacts
88+
await Promise.all([
89+
downloadArtifact('ngx-deploy-npm-coverage-report'),
90+
downloadArtifact('lint-report')
91+
]);
92+
- name: 'Extract reports'
93+
run: |
94+
# Extract coverage report
95+
mkdir -p coverage/packages/ngx-deploy-npm
96+
unzip ngx-deploy-npm-coverage-report.zip -d coverage/packages/ngx-deploy-npm
97+
# Extract lint report
98+
mkdir -p reports
99+
unzip lint-report.zip -d reports
100+
101+
- name: 'Verify reports'
102+
run: |
103+
pwd
104+
echo 'Lint report'
105+
ls -la ./coverage/packages/ngx-deploy-npm/lcov.info
106+
echo 'Coverage report'
107+
ls -la ./reports/ngx-deploy-npm/lint-report.info
108+
- name: SonarCloud Scan
109+
uses: SonarSource/sonarqube-scan-action@v4.2.1
110+
env:
111+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
112+
SONAR_TOKEN: ${{ secrets.SONARQUBE_SCANNER }}
113+
with:
114+
args: >
115+
-Dsonar.pullrequest.key=${{ github.env.PR_NUMBER }}

Diff for: .github/workflows/sonar-pr.yml

+46-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,52 @@ jobs:
3535
JSON.stringify(${{ github.event.workflow_run }}, null, 2)
3636
3737
# Download reports
38-
- uses: ./.github/actions/download-coverage-report
39-
- uses: ./.github/actions/download-lint-report
38+
- name: 'Download reports'
39+
uses: actions/github-script@v6
40+
with:
41+
script: |
42+
async function downloadArtifact(artifactName) {
43+
console.log(`Looking for artifact: ${artifactName}`);
44+
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
45+
owner: context.repo.owner,
46+
repo: context.repo.repo,
47+
run_id: context.payload.workflow_run.id,
48+
});
49+
console.log('Available artifacts:', allArtifacts.data.artifacts.map(a => a.name));
50+
51+
let matchArtifact = allArtifacts.data.artifacts.find((artifact) => {
52+
return artifact.name === artifactName;
53+
});
54+
55+
if (!matchArtifact) {
56+
throw new Error(`Artifact "${artifactName}" not found!`);
57+
}
58+
59+
let download = await github.rest.actions.downloadArtifact({
60+
owner: context.repo.owner,
61+
repo: context.repo.repo,
62+
artifact_id: matchArtifact.id,
63+
archive_format: 'zip',
64+
});
65+
66+
let fs = require('fs');
67+
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${artifactName}.zip`, Buffer.from(download.data));
68+
return artifactName;
69+
}
70+
71+
// Download both artifacts
72+
await Promise.all([
73+
downloadArtifact('ngx-deploy-npm-coverage-report'),
74+
downloadArtifact('lint-report')
75+
]);
76+
- name: 'Extract reports'
77+
run: |
78+
# Extract coverage report
79+
mkdir -p coverage/packages/ngx-deploy-npm
80+
unzip ngx-deploy-npm-coverage-report.zip -d coverage/packages/ngx-deploy-npm
81+
# Extract lint report
82+
mkdir -p reports
83+
unzip lint-report.zip -d reports
4084
4185
- name: SonarCloud Scan
4286
uses: SonarSource/sonarqube-scan-action@v4.2.1

0 commit comments

Comments
 (0)