From c2dc2c2f85aa20cc98470eec06f3a199b1c6fb2e Mon Sep 17 00:00:00 2001 From: jessicamack Date: Wed, 15 Jul 2026 10:36:06 -0400 Subject: [PATCH 1/7] feat: add workflow for SonarCloud reporting --- .github/workflows/sonarcloud_pr.yml | 245 ++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100644 .github/workflows/sonarcloud_pr.yml diff --git a/.github/workflows/sonarcloud_pr.yml b/.github/workflows/sonarcloud_pr.yml new file mode 100644 index 00000000..91cfe87a --- /dev/null +++ b/.github/workflows/sonarcloud_pr.yml @@ -0,0 +1,245 @@ +# SonarCloud Analysis Workflow for awx_plugins.interfaces +# +# This workflow runs SonarCloud analysis triggered by CI workflow completion. +# It is split into two separate jobs for clarity and maintainability: +# +# FLOW: CI completes → workflow_run triggers this workflow → appropriate job runs +# +# JOB 1: sonar-pr-analysis (for PRs) +# - Triggered by: workflow_run (CI on pull_request) +# - Steps: Download coverage → Get PR info → Get changed files → Run SonarCloud PR analysis +# - Scans: All changed files in the PR (Python, YAML, JSON, etc.) +# - Quality gate: Focuses on new/changed code in PR only +# +# JOB 2: sonar-branch-analysis (for long-lived branches) +# - Triggered by: workflow_run (CI on push to devel) +# - Steps: Download coverage → Run SonarCloud branch analysis +# - Scans: Full codebase +# - Quality gate: Focuses on overall project health +# +# This ensures coverage data is always available from CI before analysis runs. +# +# What files are scanned: +# - All files in the repository that SonarCloud can analyze +# - Excludes: tests, scripts, dev environments, external collections (see sonar-project.properties) + + +# 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: # This is triggered by CI being completed. + workflows: + - CI + types: + - completed +permissions: + contents: read + actions: read + pull_requests: read +jobs: + sonar-pr-analysis: + name: SonarCloud PR Analysis + runs-on: ubuntu-latest + if: | + github.event.workflow_run.conclusion == 'success' && + github.event.workflow_run.event == 'pull_request' && + github.repository == 'ansible/awx_plugins.interfaces' + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + + # Download all individual coverage artifacts from CI workflow + - name: Download coverage artifacts + uses: dawidd6/action-download-artifact@246dbf436b23d7c49e21a7ab8204ca9ecd1fe615 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + workflow: CI + run_id: ${{ github.event.workflow_run.id }} + pattern: api-test-artifacts + + # Extract PR metadata from workflow_run event + - name: Set PR metadata and prepare files for analysis + env: + COMMIT_SHA: ${{ github.event.workflow_run.head_sha }} + REPO_NAME: ${{ github.event.repository.full_name }} + HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Find all downloaded coverage XML files + coverage_files=$(find . -name "coverage.xml" -type f | tr '\n' ',' | sed 's/,$//') + echo "Found coverage files: $coverage_files" + echo "COVERAGE_PATHS=$coverage_files" >> $GITHUB_ENV + + # Extract PR number from first coverage.xml file found + first_coverage=$(find . -name "coverage.xml" -type f | head -1) + if [ -f "$first_coverage" ]; then + PR_NUMBER=$(grep -m 1 '