-
Notifications
You must be signed in to change notification settings - Fork 213
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
Remove condition on pull_request events #6
Conversation
README.md
Outdated
@@ -46,6 +46,10 @@ jobs: | |||
|
|||
- `SONAR_TOKEN` – **Required** this is the token used to authenticate access to SonarCloud. You can generate a token on your [Security page in SonarCloud](https://sonarcloud.io/account/security/). You can set the `SONAR_TOKEN` environment variable in the "Secrets" settings page of your repository. | |||
|
|||
### Environment variables | |||
|
|||
- `SCAN_PULL_REQUEST` – **Optional** Flag to run analysis on `pull_request` events. Scans on pull requests are disabled by default as the action expects to be triggered by push events. |
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.
Where is this variable used?
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 messed up the master
branch on our side accidentally. Sorry!
I've reverted it to the relevant commit; The variable is used used in entrypoint.sh
.
Is the goal to trigger an analysis on the creation of a pull request, so that there's no need to push a new commit? |
entrypoint.sh
Outdated
@@ -17,7 +17,7 @@ if [[ -f "build.gradle" ]]; then | |||
exit 1 | |||
fi | |||
|
|||
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then | |||
if [[ -z "${SCAN_PULL_REQUEST}" || "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then | |||
EVENT_ACTION=$(jq -r ".action" "${GITHUB_EVENT_PATH}") | |||
if [[ "${EVENT_ACTION}" != "opened" ]]; then | |||
echo "No need to run analysis. It is already triggered by the push event." |
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.
@sawy @simonbrandhof Why is this block needed?
You can let the users decide to run the analysis whenever they want by using the if
conditional.
You can use the
if
conditional to prevent a step from running unless a condition is met. You can use any supported context and expression to create a conditional.
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.
@sawy @simonbrandhof Why is this block needed?
I don't know that. The scripts seems to assume that there is a workflow in place that runs on push. We have workflows that only listen to pull_request events and therefore never run the analysis. Hence the new flag to overwrite the behavior.
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.
That is a safeguard to prevent analysis of branch when a pull request exists. To be honest that was put in place by fear of having users misunderstanding how branches and pull requests work in SonarCloud. Indeed a branch can be analysed in isolation of its associated pull request.
Removing this condition, and the suggested SCAN_PULL_REQUEST
variable, is an option that could make things simpler. It would be up to users to correctly configure their workflow.
Does that make sense?
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.
@simonbrandhof could you elaborate a bit more? I think I'm part of the misunderstanding users 😟, sorry.
If we open a PR, the checkout action will AFAIK (per default) checkout a merge commit that may differ from the branch HEAD. In such case why analysis should be bypassed?
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.
@loicalbertin it doesn't actually make much sense at all, but it seems @simonbrandhof doesn't want to change anything either. If you want to have your pull requests scanned properly, try pr-fix
branch on my fork. We've been using it for quite some time now and haven't noticed any issues neither on SonarCloud side, nor on GitHub itself. Everything's working fine.
You can include it in your github workflow the following way:
- name: SonarCloud Scan
uses: hakimio/sonarcloud-github-action@pr-fix
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
The goal is to run the action on |
@simonbrandhof Any reason this can not be merged? We need this functionality as well. |
See #6 (comment). Could that help? |
@simonbrandhof I understand the reasoning behind this check but I also think it should be completely optional. |
entrypoint.sh
Outdated
@@ -17,7 +17,7 @@ if [[ -f "build.gradle" ]]; then | |||
exit 1 | |||
fi | |||
|
|||
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then | |||
if [[ -z "${SCAN_PULL_REQUEST}" || "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then |
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'm pretty sure it should be &&
instead of ||
condition. Otherwise any additional commits to the PR are not analyzed.
SonarCloud Github Action currently does not support PullRequest runs: SonarSource/sonarcloud-github-action#6
* Create sonar_cloud_scan.yml * Update sonar-project.properties SonarCloud Github Action currently does not support PullRequest runs: SonarSource/sonarcloud-github-action#6 * Update .travis.yml Disable SonarCloud in Travis
If I only have a scan on pull_requests, when a someone pushes a new commit to a PR you would need to trigger on pushes and NOT have a PR trigger alone. Since sonarcloud will decide for itself whether it needs to scan or not. Which comes a little opinionated |
any news about it? |
@lechen26 no, but you can use my fork to have PRs scanned properly: #6 (comment) |
Removes restriction on EVENT_ACTION and GITHUB_EVENT_NAME, to allow analysis on any pull request event. It's up to the users to correctly configure their workflow.
@simonbrandhof and @ZeevKatz, I've updated this PR to simply remove the condition as suggested and implemented by @hakimio. |
@sawy 😜Approved! Now seriously, why we're waiting with this merge? |
It would be so nice to have this merged ... |
@simonbrandhof There are quite a few people who want this merged. What's your final decision? Merge or just close? |
@simonbrandhof Please update what's your decision. |
We also need this feature. Interested to hear what your thoughts are. Due to limited resources we are scanning locally when a commit is made and then we are requiring analysis to pass before a PR can be merged |
@FahdW This is a really good point, and was worth checking out. I am currently using @sawy 's fork and analysis is being ran when I make a push to the branch containing the PR. So there is no need for an extra step to run on push. In fact, something similar to this works exactly as I am expecting
|
Hi guys, would require this too :). My scan on push to PR gets ignored, which is a bit annoying as it makes my PR checks invalid. |
Guys This may look like a nice to have feature. But it will very much be required for us. Kindly push it through 😄 |
Hi guys, it would be very nice if this would finally be merged into master. We have been waiting for a half year now. Thank you in advance. |
This pull request significantly changed since the initial contribution. Dropping the filter on events |
Merged into |
can we have a new tag release for this change? |
@kenhuang Sure. It will be done in the next few hours. |
Introduces a way to run the scanner action on
pull_request
events by setting the
SCAN_PULL_REQUEST
environment flag.