Debian Codegraph @

ansible_collections/amazon/aws/.github/workflows/sonarcloud.yml

raw
1 ## SonarCloud Analysis Workflow for amazon.aws
2
3 # This workflow runs SonarCloud analysis triggered by all_green workflow completion.
4 #
5 # FLOW: all_green completes (linters, sanity, units, coverage) → workflow_run triggers this workflow → finalize job runs
6 #
7 # - Triggered by: workflow_run (all_green on pull_request or push to main/stable-*)
8 # - Steps: Checkout → Download coverage from all_green run → Get PR info (if PR) → Run SonarCloud scan
9 # - Coverage: Unit test coverage is produced by the coverage job (via tox) in all_green and passed to SonarCloud here.
10 #
11 # This ensures coverage data is always available from the all_green run before analysis runs.
12 #
13 # What files are scanned:
14 # - All files in the repository that SonarCloud can analyze
15 # - Excludes: tests, scripts, dev environments, external collections (see sonar-project.properties)
16
17
18 ---
19 name: SonarCloud
20
21 on:
22 workflow_run:
23 workflows:
24 - all_green
25 types:
26 - completed
27
28 permissions:
29 contents: read
30 pull-requests: read
31 actions: read
32
33 jobs:
34 finalize:
35 name: finalize
36 runs-on: ubuntu-latest
37 if: github.event.workflow_run.conclusion == 'success'
38 steps:
39 - name: Checkout repository
40 uses: actions/checkout@v4
41 with:
42 ref: ${{ github.event.workflow_run.head_sha }}
43 fetch-depth: 0
44 show-progress: false
45
46 - name: Download coverage artifacts
47 uses: dawidd6/action-download-artifact@2536c51d3d126276eb39f74d6bc9c72ac6ef30d3 # v16
48 with:
49 github_token: ${{ secrets.GITHUB_TOKEN }}
50 workflow: all_green
51 run_id: ${{ github.event.workflow_run.id }}
52 pattern: coverage*
53
54 - name: Set coverage report paths
55 run: |
56 coverage_files=$(find . -name "coverage*.xml" -type f 2>/dev/null | tr '\n' ',' | sed 's/,$//')
57 echo "Found coverage files: ${coverage_files:-none}"
58 echo "COVERAGE_PATHS=${coverage_files}" >> $GITHUB_ENV
59
60 - name: Get PR number and info
61 if: github.event.workflow_run.event == 'pull_request'
62 env:
63 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64 HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
65 REPO: ${{ github.repository }}
66 run: |
67 PR_NUMBER=$(gh pr list --head "$HEAD_BRANCH" --repo "$REPO" --json number -q '.[0].number')
68 echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
69 if [ -n "$PR_NUMBER" ]; then
70 PR_DATA=$(gh api "repos/$REPO/pulls/$PR_NUMBER")
71 echo "PR_BASE=$(echo "$PR_DATA" | jq -r '.base.ref')" >> $GITHUB_ENV
72 echo "PR_HEAD=$(echo "$PR_DATA" | jq -r '.head.ref')" >> $GITHUB_ENV
73 fi
74
75 - name: Prepare SonarCloud args
76 env:
77 COMMIT_SHA: ${{ github.event.workflow_run.head_sha }}
78 EVENT_TYPE: ${{ github.event.workflow_run.event }}
79 run: |
80 SONAR_ARGS="-Dsonar.scm.revision=\"${COMMIT_SHA}\""
81 if [[ "$EVENT_TYPE" == "pull_request" && -n "${PR_NUMBER:-}" ]]; then
82 SONAR_ARGS="${SONAR_ARGS} -Dsonar.pullrequest.key=${PR_NUMBER}"
83 SONAR_ARGS="${SONAR_ARGS} -Dsonar.pullrequest.branch=${PR_HEAD}"
84 SONAR_ARGS="${SONAR_ARGS} -Dsonar.pullrequest.base=${PR_BASE}"
85 fi
86 if [[ -n "${COVERAGE_PATHS:-}" ]]; then
87 SONAR_ARGS="${SONAR_ARGS} -Dsonar.python.coverage.reportPaths=${COVERAGE_PATHS}"
88 fi
89 echo "SONAR_ARGS=${SONAR_ARGS}" >> $GITHUB_ENV
90
91 - name: SonarCloud Scan
92 # a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 (v7)
93 uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9
94 env:
95 SONAR_TOKEN: ${{ secrets.ANSIBLE_COLLECTIONS_ORG_SONAR_TOKEN_CICD_BOT }}
96 with:
97 args: ${{ env.SONAR_ARGS }}