From f541857f6278e181ec43d9bab4c30389162eb9e7 Mon Sep 17 00:00:00 2001 From: Alexander Saprykin Date: Thu, 14 Nov 2024 15:10:24 +0100 Subject: [PATCH] Upload test coverage to SonarCloud (#308) --- .github/workflows/main.yml | 19 +++++++++- .github/workflows/sonar-pr.yaml | 63 +++++++++++++++++++++++++++++++++ .gitignore | 1 + .sonarcloud.properties | 6 ---- Makefile | 2 +- sonar-project.properties | 10 ++++++ 6 files changed, 93 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/sonar-pr.yaml delete mode 100644 .sonarcloud.properties create mode 100644 sonar-project.properties diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7a13b75e..3920c9b0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -44,7 +44,24 @@ jobs: - name: run the integration tests run: make test/integration - + + - name: Inject PR number into coverage.xml + if: matrix.python-version == '3.11' + run: sed -i '2i ' coverage.xml + + - name: upload coverage as artifact + if: matrix.python-version == '3.11' + uses: actions/upload-artifact@v4 + with: + name: coverage + path: coverage.xml + + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@master + if: github.event_name == 'push' && github.repository == 'ansible/galaxy-importer' && github.ref_name == 'master' + env: + SONAR_TOKEN: ${{ secrets.CICD_ORG_SONAR_TOKEN_CICD_BOT }} + publish: name: Build and publish to PyPI registry diff --git a/.github/workflows/sonar-pr.yaml b/.github/workflows/sonar-pr.yaml new file mode 100644 index 00000000..f9ad2eed --- /dev/null +++ b/.github/workflows/sonar-pr.yaml @@ -0,0 +1,63 @@ +# With much help from: +# https://community.sonarsource.com/t/how-to-use-sonarcloud-with-a-forked-repository-on-github/7363/30 +# https://community.sonarsource.com/t/how-to-use-sonarcloud-with-a-forked-repository-on-github/7363/32 +name: SonarCloud +on: + workflow_run: + workflows: + - CI + types: + - completed +jobs: + sonar: + name: Upload to SonarCloud + runs-on: ubuntu-latest + if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + show-progress: false + + - uses: actions/download-artifact@v4 + with: + name: coverage + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} + + - name: Extract PR number from coverage.xml + run: | + echo "PR_NUMBER=$(grep -m 1 '