Skip to content

Sonar for PRs

Sonar for PRs #632

Workflow file for this run

name: Sonar for PRs
on:
workflow_run:
workflows: ['PRs']
types: [completed]
jobs:
sonar:
name: Sonar
runs-on: ubuntu-latest
timeout-minutes: 30
if: github.event.workflow_run.conclusion == 'success'
permissions:
actions: read
contents: read
pull-requests: read
steps:
- uses: actions/checkout@v6
- name: Resolve PR
id: resolve-pr
uses: ./.github/actions/resolve-pr-from-workflow-run
- uses: actions/checkout@v6
with:
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 0
- name: Download reports
uses: actions/github-script@v7
with:
script: |
async function downloadArtifact(artifactName) {
console.log(`Looking for artifact: ${artifactName}`);
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
console.log(
'Available artifacts:',
allArtifacts.data.artifacts.map((artifact) => artifact.name)
);
const matchArtifact = allArtifacts.data.artifacts.find(
(artifact) => artifact.name === artifactName
);
if (!matchArtifact) {
throw new Error(`Artifact "${artifactName}" not found!`);
}
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync(
`${process.env.GITHUB_WORKSPACE}/${artifactName}.zip`,
Buffer.from(download.data)
);
}
await Promise.all([
downloadArtifact('ngx-deploy-npm-coverage-report'),
downloadArtifact('lint-report'),
]);
- name: Extract reports
run: |
mkdir -p coverage/packages/ngx-deploy-npm
unzip ngx-deploy-npm-coverage-report.zip -d coverage/packages/ngx-deploy-npm
mkdir -p reports
unzip lint-report.zip -d reports
- name: SonarCloud Scan
uses: SonarSource/sonarqube-scan-action@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONARQUBE_SCANNER }}
with:
args: >
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}
-Dsonar.pullrequest.key=${{ steps.resolve-pr.outputs.pr-number }}
-Dsonar.pullrequest.branch=${{ steps.resolve-pr.outputs.pr-head-ref }}
-Dsonar.pullrequest.base=${{ steps.resolve-pr.outputs.pr-base-ref }}