Sonar #272
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: Sonar | |
on: | |
workflow_run: | |
workflows: [Mautic tests and validations] | |
types: [completed] | |
jobs: | |
sonar: | |
name: Sonar | |
runs-on: ubuntu-latest | |
if: github.event.workflow_run.conclusion == 'success' | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
repository: ${{ github.event.workflow_run.head_repository.full_name }} | |
ref: ${{ github.event.workflow_run.pull_requests[0].head.sha }} | |
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 == "test-results" | |
})[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}/test-results.zip`, Buffer.from(download.data)); | |
- name: 'Unzip code coverage' | |
run: | | |
unzip test-results.zip -d coverage | |
- name: Fix code coverage paths | |
run: sed -i | |
's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage/coverage.xml | |
- name: "Get PR information" | |
uses: potiuk/get-workflow-origin@v1_3 | |
id: source-run-info | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
sourceRunId: ${{ github.event.workflow_run.id }} | |
- name: SonarCloud Scan | |
uses: sonarsource/sonarcloud-github-action@master | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
with: | |
args: > | |
-Dsonar.organization=mautic | |
-Dsonar.projectKey=mautic_mautic | |
-Dsonar.links.homepage=https://github.com/mautic/mautic | |
-Dsonar.links.ci=https://github.com/mautic/mautic/actions/workflows/tests.yml | |
-Dsonar.links.scm=https://github.com/mautic/mautic | |
-Dsonar.links.issue=https://github.com/mautic/mautic/issues | |
-Dsonar.sourceEncoding=UTF-8 | |
-Dsonar.sources=app,plugins | |
-Dsonar.inclusions=app/*.php,app/**/*.php,plugins/*.php,plugins/**/*.php | |
-Dsonar.exclusions=app/migrations/**/*,app/bundles/*Bundle/Config/**/*,app/bundles/*Bundle/DataFixtures/**/*,app/bundles/*Bundle/Tests/**/*,app/bundles/*Bundle/Translations/**/*,app/bundles/*Bundle/Views/**/*,app/middlewares/Test/**/*,app/bundles/CoreBundle/Test/**/*,plugins/*Bundle/Config/**/*,plugins/*Bundle/Tests/**/*,plugins/*Bundle/Translations/**/*,plugins/*Bundle/Views/**/* | |
-Dsonar.cpd.exclusions=**/* | |
-Dsonar.tests=tests | |
-Dsonar.php.coverage.reportPaths=coverage/coverage.xml | |
-Dsonar.php.tests.reportPath=coverage/junit.xml | |
-Dsonar.scm.disabled=false | |
-Dsonar.verbose=true | |
-Dsonar.scm.revision=${{ steps.source-run-info.outputs.sourceHeadSha }} | |
-Dsonar.pullrequest.key=${{ steps.source-run-info.outputs.pullRequestNumber }} | |
-Dsonar.pullrequest.branch=${{ steps.source-run-info.outputs.sourceHeadBranch }} | |
-Dsonar.pullrequest.base=${{ steps.source-run-info.outputs.targetBranch }} | |
-Dsonar.newCode.referenceBranch=${{ steps.source-run-info.outputs.targetBranch }} |