Sonar Scan and Coverage on PRs #230
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 Scan and Coverage on PRs | |
on: | |
workflow_run: | |
workflows: [ PR Tests ] | |
types: | |
- completed | |
jobs: | |
SonarCloud: | |
runs-on: ubuntu-latest | |
if: github.event.workflow_run.conclusion == 'success' && github.repository == 'jamshale/acapy' | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Download PR number artifact | |
uses: dawidd6/action-download-artifact@v7 | |
with: | |
workflow: Tests | |
run_id: ${{ github.event.workflow_run.id }} | |
name: PR_NUMBER | |
- name: Read PR_NUMBER | |
id: pr_number | |
uses: juliangruber/read-file-action@v1 | |
with: | |
path: ./PR_NUMBER | |
- name: Download Test Coverage | |
uses: dawidd6/action-download-artifact@v7 | |
with: | |
workflow: Tests | |
run_id: ${{ github.event.workflow_run.id }} | |
name: TEST_COV | |
- name: Request GitHub API for PR data | |
uses: octokit/[email protected] | |
id: get_pr_data | |
with: | |
route: GET /repos/${{ github.event.repository.full_name }}/pulls/${{ steps.pr_number.outputs.content }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Checkout base branch | |
run: | | |
echo forked repo = ${{ fromJson(steps.get_pr_data.outputs.data).head.repo.html_url }}.git | |
echo base repo = ${{ github.event.repository.clone_url }} | |
git remote add upstream ${{ fromJson(steps.get_pr_data.outputs.data).head.repo.html_url }}.git | |
git fetch --all | |
echo pr number = ${{ fromJson(steps.get_pr_data.outputs.data).number }} | |
echo forked branch = ${{ fromJson(steps.get_pr_data.outputs.data).head.ref }} | |
echo base branch = ${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} | |
git checkout -B temp-branch-for-scanning upstream/${{ fromJson(steps.get_pr_data.outputs.data).head.ref }} | |
# - name: Move Coverage Report And Adjust Source | |
# run: | | |
# echo 0000000000000000000000000000000000000000000 | |
# ls / | |
# echo 0000000000000000000000000000000000000000000 | |
# ls /home/ | |
# echo 0000000000000000000000000000000000000000000 | |
# ls /home/runner/ | |
# echo 0000000000000000000000000000000000000000000 | |
# ls /home/runner/work/ | |
# echo 0000000000000000000000000000000000000000000 | |
# echo ${{ github.workspace }} | |
# mkdir test-reports | |
# cat coverage.xml | |
# mv coverage.xml test-reports | |
- name: SonarCloud Scan | |
uses: SonarSource/sonarqube-scan-action@master | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
with: | |
args: > | |
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} | |
-Dsonar.pullrequest.key=${{ fromJson(steps.get_pr_data.outputs.data).number }} | |
-Dsonar.pullrequest.branch=${{ fromJson(steps.get_pr_data.outputs.data).head.ref }} | |
-Dsonar.pullrequest.base=${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} | |
-Dsonar.coverage.exclusions=**/tests/**,**/demo/**,**/docs/**,**/docker/**,**/scripts/**,**/scenarios/** | |
-Dsonar.cpd.exclusions=**/tests/**,**/demo/**,**/docs/**,**/docker/**,**/scripts/**,**/scenarios/** | |
-Dsonar.python.coverage.reportPaths=coverage.xml | |
-Dsonar.sources=./ |