sonar.yaml 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. name: Sonar Code Coverage Upload
  2. on:
  3. workflow_run:
  4. workflows: ["Build/Test"]
  5. types: [completed]
  6. jobs:
  7. sonar:
  8. name: Sonar
  9. runs-on: ubuntu-latest
  10. if: github.event.workflow_run.conclusion == 'success'
  11. steps:
  12. - uses: actions/checkout@v3
  13. with:
  14. repository: ${{ github.event.workflow_run.head_repository.full_name }}
  15. ref: ${{ github.event.workflow_run.head_branch }}
  16. fetch-depth: 0
  17. - name: 'Download code coverage'
  18. uses: actions/github-script@v6
  19. with:
  20. script: |
  21. let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
  22. owner: context.repo.owner,
  23. repo: context.repo.repo,
  24. run_id: context.payload.workflow_run.id,
  25. });
  26. let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
  27. return artifact.name == "oc-code-coverage"
  28. })[0];
  29. let download = await github.rest.actions.downloadArtifact({
  30. owner: context.repo.owner,
  31. repo: context.repo.repo,
  32. artifact_id: matchArtifact.id,
  33. archive_format: 'zip',
  34. });
  35. let fs = require('fs');
  36. fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/oc-code-coverage.zip`, Buffer.from(download.data));
  37. - name: 'Unzip code coverage'
  38. run: unzip oc-code-coverage.zip -d coverage
  39. - name: SonarCloud Scan
  40. uses: sonarsource/sonarcloud-github-action@master
  41. env:
  42. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  43. SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
  44. with:
  45. args: >
  46. -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}
  47. -Dsonar.pullrequest.key=${{ github.event.workflow_run.pull_requests[0].number }}
  48. -Dsonar.pullrequest.branch=${{ github.event.workflow_run.pull_requests[0].head.ref }}
  49. -Dsonar.pullrequest.base=${{ github.event.workflow_run.pull_requests[0].base.ref }}
  50. -Dsonar.projectKey=opencost_opencost
  51. -Dsonar.organization=opencost