-
Notifications
You must be signed in to change notification settings - Fork 6
CI: Add SonarCloud integration for abbenay #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+152
−1
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c8c0fd1
ci: add SonarCloud static analysis with coverage reporting
Hrithik-Gavankar 61c01b4
Merge branch 'main' into feat/sonar-cloud-integration
Hrithik-Gavankar e152564
Merge branch 'main' into feat/sonar-cloud-integration
sudhirverma 0758e2a
ci(sonar): fix source/test overlap, harden PR metadata resolution, an…
Hrithik-Gavankar ebf0f24
ci(sonar): pin sonar.host.url to prevent PR override of endpoint
Hrithik-Gavankar 13f4d3b
ci(sonar): update SonarCloud scan token key
Hrithik-Gavankar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| --- | ||
| name: finalize | ||
| on: | ||
| workflow_run: | ||
| workflows: | ||
| - CI | ||
| types: | ||
| - completed | ||
|
|
||
| permissions: read-all | ||
|
|
||
| jobs: | ||
| finalize: | ||
| name: finalize | ||
| if: | | ||
| github.event.workflow_run.conclusion == 'success' && | ||
| (github.event.workflow_run.event == 'pull_request' || | ||
| (github.event.workflow_run.event == 'push' && github.event.workflow_run.head_branch == 'main')) | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 | ||
| with: | ||
| ref: ${{ github.event.workflow_run.head_sha }} | ||
| fetch-depth: 0 | ||
| show-progress: false | ||
| persist-credentials: false | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| - name: Download coverage artifact | ||
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 | ||
| with: | ||
| name: sonar-coverage | ||
| path: packages/daemon/coverage | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| run-id: ${{ github.event.workflow_run.id }} | ||
|
|
||
| - name: Resolve PR metadata | ||
| if: github.event.workflow_run.event == 'pull_request' | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| HEAD_SHA: ${{ github.event.workflow_run.head_sha }} | ||
| REPO: ${{ github.repository }} | ||
| # Trusted GitHub payload — not PR-controlled artifact content | ||
| PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| if [[ -z "${PR_NUMBER}" ]]; then | ||
| PR_NUMBER=$(gh api \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| "repos/${REPO}/commits/${HEAD_SHA}/pulls" \ | ||
| --jq '.[0].number // empty') | ||
| fi | ||
|
|
||
| if [[ ! "${PR_NUMBER}" =~ ^[0-9]+$ ]]; then | ||
| echo "::error::Unable to resolve a trusted PR number for head SHA ${HEAD_SHA}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| PR_DATA=$(gh api "repos/${REPO}/pulls/${PR_NUMBER}") | ||
| PR_BASE=$(jq -r '.base.ref' <<< "${PR_DATA}") | ||
| PR_HEAD=$(jq -r '.head.ref' <<< "${PR_DATA}") | ||
|
|
||
| if [[ -z "${PR_BASE}" || "${PR_BASE}" == "null" || -z "${PR_HEAD}" || "${PR_HEAD}" == "null" ]]; then | ||
| echo "::error::Unable to resolve PR branch metadata for PR ${PR_NUMBER}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| { | ||
| echo "PR_NUMBER=${PR_NUMBER}" | ||
| echo "PR_BASE=${PR_BASE}" | ||
| echo "PR_HEAD=${PR_HEAD}" | ||
| } >> "${GITHUB_ENV}" | ||
|
|
||
| echo "Resolved PR #${PR_NUMBER} (${PR_HEAD} -> ${PR_BASE})" | ||
|
|
||
| - name: Prepare SonarCloud args | ||
| if: hashFiles('packages/daemon/coverage/lcov.info') != '' | ||
| shell: bash | ||
| env: | ||
| WORKFLOW_EVENT: ${{ github.event.workflow_run.event }} | ||
| COMMIT_SHA: ${{ github.event.workflow_run.head_sha }} | ||
| REPO_NAME: ${{ github.repository }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| IFS="/" read -r REPO_OWNER REPO_NAME_ONLY <<< "${REPO_NAME}" | ||
|
|
||
| # Pin endpoint; PRs must not override via sonar-project.properties | ||
| SONAR_ARGS="-Dsonar.host.url=https://sonarcloud.io" | ||
| SONAR_ARGS="${SONAR_ARGS} -Dsonar.projectKey=${REPO_OWNER}_${REPO_NAME_ONLY} -Dsonar.organization=${REPO_OWNER}" | ||
| SONAR_ARGS="${SONAR_ARGS} -Dsonar.scm.revision=${COMMIT_SHA}" | ||
|
|
||
| if [[ "${WORKFLOW_EVENT}" == "pull_request" ]]; then | ||
| if [[ ! "${PR_NUMBER:-}" =~ ^[0-9]+$ ]]; then | ||
| echo "::error::PR_NUMBER is missing or invalid" | ||
| exit 1 | ||
| fi | ||
| SONAR_ARGS="${SONAR_ARGS} -Dsonar.pullrequest.key=${PR_NUMBER}" | ||
| SONAR_ARGS="${SONAR_ARGS} -Dsonar.pullrequest.branch=${PR_HEAD}" | ||
| SONAR_ARGS="${SONAR_ARGS} -Dsonar.pullrequest.base=${PR_BASE}" | ||
| fi | ||
|
|
||
| echo "SONAR_ARGS=${SONAR_ARGS}" >> "${GITHUB_ENV}" | ||
|
|
||
| - name: Check for coverage files | ||
| run: | | ||
| if [ -f packages/daemon/coverage/lcov.info ]; then | ||
| echo "Coverage Data: Available" | ||
| ls -la packages/daemon/coverage/lcov.info | ||
| else | ||
| echo "Coverage Data: Not available - exiting" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Running SonarCloud analysis..." | ||
|
|
||
| - name: SonarCloud Scan | ||
| uses: SonarSource/sonarqube-scan-action@22918119ff8e1ca75a623e15c8296b6ea4fbe28f # v8 | ||
| env: | ||
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| with: | ||
| args: ${{ env.SONAR_ARGS }} | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # cspell: ignore multicriteria | ||
| # sonar does not support cobertura coverage xml format, only lcov.info | ||
| # | ||
| # Branch analysis: SonarCloud treats the default branch automatically. | ||
| # Do not hardcode sonar.branch.name or sonar.branch.target here — a static | ||
| # target would break other branch scans. For additional long-lived branches, | ||
| # set the pattern (Project > Branches) to: ^(next|(branch|release)-.*)$ | ||
| sonar.debug=false | ||
| sonar.log.level.app=INFO | ||
| sonar.javascript.lcov.reportPaths=packages/daemon/coverage/lcov.info | ||
| sonar.typescript.lcov.reportPaths=packages/daemon/coverage/lcov.info | ||
| sonar.organization=redhat-developer | ||
| sonar.projectKey=redhat-developer_abbenay | ||
| sonar.sources=packages/daemon/src/,packages/vscode/src/ | ||
| sonar.tests=packages/daemon/src/,packages/daemon/tests/,packages/vscode/src/test/ | ||
| # Keep source/test sets disjoint: co-located *.test.ts live under source roots | ||
| # but must be classified only as tests (not main sources). | ||
| sonar.exclusions=**/node_modules/**,**/dist/**,**/coverage/**,packages/proto-ts/**,packages/python/**,**/*.test.ts | ||
| sonar.test.inclusions=**/*.test.ts | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| sonar.verbose=false | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.