sonar.yaml 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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: set env vars
  40. run: |
  41. echo "SONAR_PR_NUM=$(cat coverage/pr_num.txt)" >> $GITHUB_ENV
  42. echo "SONAR_BASE=$(cat coverage/base.txt)" >> $GITHUB_ENV
  43. echo "SONAR_HEAD=$(cat coverage/head.txt)" >> $GITHUB_ENV
  44. - name: SonarCloud Scan
  45. uses: sonarsource/sonarcloud-github-action@master
  46. env:
  47. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  48. SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
  49. with:
  50. args: >
  51. -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}
  52. -Dsonar.pullrequest.key=${{ env.SONAR_PR_NUM }}
  53. -Dsonar.pullrequest.branch=${{ env.SONAR_HEAD }}
  54. -Dsonar.pullrequest.base=${{ env.SONAR_BASE }}
  55. -Dsonar.projectKey=opencost_opencost
  56. -Dsonar.organization=opencost