sonar.yaml 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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: Dump context
  40. uses: crazy-max/ghaction-dump-context@v2
  41. - name: SonarCloud Scan
  42. uses: sonarsource/sonarcloud-github-action@master
  43. env:
  44. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  45. SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
  46. with:
  47. args: >
  48. -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}
  49. -Dsonar.pullrequest.key=${{ github.event.workflow_run.pull_requests[0].number }}
  50. -Dsonar.pullrequest.branch=${{ github.event.workflow_run.pull_requests[0].head.ref }}
  51. -Dsonar.pullrequest.base=${{ github.event.workflow_run.pull_requests[0].base.ref }}
  52. -Dsonar.projectKey=opencost_opencost
  53. -Dsonar.organization=opencost