Skip to content

ci : fix failing sonar pipeline by moving sonar publish step to workflow_run #7151

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rohanKanojia
Copy link
Member

@rohanKanojia rohanKanojia commented Jul 7, 2025

Description

Sonar analysis is no longer working on pull requests with sonar login token is not provided in pull requests workflows.

In order to perform analysis, split the github action into two actions:

  • Sonar PR Report Request : Will run on PR, but would only verify build is ok
  • Sonar PR Report Publish : Will run after completion of previous workflow, but on main repository that would have required secrets.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • Code contributed by me aligns with current project license: Apache 2.0
  • I Added CHANGELOG entry regarding this change
  • I have implemented unit tests to cover my changes
  • I have added/updated the javadocs and other documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report
  • I tested my code in Kubernetes
  • I tested my code in OpenShift

@rohanKanojia rohanKanojia changed the title ci : fix failing sonar pipeline by moving sonar publish step to workprflow_run ci : fix failing sonar pipeline by moving sonar publish step to workflow_run Jul 7, 2025
…flow_run`

Sonar analysis is no longer working on pull requests as sonar login token is not
propagated to pull requests.

In order to perform analysis, split the github action into two actions:
- `Sonar PR Report Request` : Will run on PR, but would only verify build is ok
- `Sonar PR Report Publish` : Will run after completion of previous workflow, but on main repository that would have required secrets.

Signed-off-by: Rohan Kumar <[email protected]>
@rohanKanojia rohanKanojia force-pushed the pr/split-sonar-workflow-run branch from 6924ca4 to b67e173 Compare July 7, 2025 08:33
@rohanKanojia rohanKanojia marked this pull request as ready for review July 7, 2025 18:57
Comment on lines +46 to +47
- name: Build Project before requesting for Sonar Analysis
run: mvn ${MAVEN_ARGS} install
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is building the project, but I'm not sure I follow why.
Is it to ensure that the project builds and the tests pass?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, before invoking workflow_run request on the main repository. We just make sure that build is not failing.

Comment on lines +56 to +63
run: |
PR_QUERY_RESULT=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$GITHUB_REPO/pulls?head=$PR_AUTHOR:$PR_BRANCH&state=open" | jq '.[0].number')
if [ "$PR_QUERY_RESULT" = "null" ] || [ -z "$PR_QUERY_RESULT" ]; then
echo "Could not find PR number for $PR_AUTHOR:$PR_BRANCH"
exit 1
fi
echo "PR_NUMBER=$PR_QUERY_RESULT" >> $GITHUB_ENV
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this part is checking that the PR exists and hasn't been merged before proceeding to publish the PR results.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is extracting pull request number using GitHub API. Actually, I couldn't find GitHub pull request number in github event payload. Therefore using GitHub REST API to fetch it. This pull request number is passed in sonar.pullrequest.key property

Comment on lines +64 to +65
- name: Sonar
run: make sonar-pr-report
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up to https://github.com/fabric8io/kubernetes-client/pull/7151/files#r2191435582

How are the results from the build in the PR branch evaluated here? there are no intermediate artifacts stored.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be merged to work. As of now there is no workflow_run workflow present in main repository.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But still I don't understand where are the (or where would the) intermediate artifacts or sonar scanner results be fetched from

Copy link
Member Author

@rohanKanojia rohanKanojia Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no intermediate artifacts, it would trigger a fresh sonar analysis in workflow_run

I had tested it on my fork by creating test PR (from another account of mine) rohanKanojia#198

It triggered this workflow https://github.com/rohanKanojia/kubernetes-client/actions/runs/16107925671

It posted sonar analysis on this pull request on fabric8io/kubernetes-client (due to projectId set in sonar properties) #198 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants