-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # | ||
| # Copyright (C) 2015 Red Hat, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| name: Sonar PR Report Publish | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: [Sonar PR Report Request] | ||
| types: | ||
| - completed | ||
|
|
||
| concurrency: | ||
| # Only run once for latest commit per ref and cancel other (previous) runs. | ||
| group: ci-sonar-kubernetes-client-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| sonar: | ||
| name: Sonar | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| BASE_BRANCH: main | ||
| PR_BRANCH: ${{ github.event.workflow_run.head_branch }} | ||
| PR_AUTHOR: ${{ github.event.sender.login }} | ||
| GITHUB_REPO: ${{ github.repository }} | ||
| SONAR_LOGIN_TOKEN: ${{ secrets.SONAR_LOGIN_TOKEN }} | ||
| steps: | ||
| - name: Setup Java 17 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: '17' | ||
| distribution: 'temurin' | ||
| - name: Get PR number | ||
| 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 | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: refs/pull/${{ env.PR_NUMBER }}/head | ||
| # Shallow clones should be disabled for a better relevancy of analysis | ||
| fetch-depth: 0 | ||
| - name: Sonar | ||
| run: make sonar-pr-report | ||
|
Comment on lines
+65
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, but this is actually running the sonar analysis on main (unless I'm mistaken), so it's not checking the code in the PR (see the link to your workflow run): There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're right, thanks for noticing. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # | ||
| # Copyright (C) 2015 Red Hat, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| name: Sonar PR Report Request | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths-ignore: | ||
| - 'doc/**' | ||
| - 'ide-config/**' | ||
| - '**.md' | ||
|
|
||
| concurrency: | ||
| # Only run once for latest commit per ref and cancel other (previous) runs. | ||
| group: ci-sonar-kubernetes-client-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| sonar: | ||
| name: Sonar | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Setup Java 17 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: '17' | ||
| distribution: 'temurin' | ||
| - name: Build Project before requesting for Sonar Analysis | ||
| run: mvn ${MAVEN_ARGS} install | ||
|
Comment on lines
+46
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, before invoking |
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.keyproperty