How to prevent running actions on push
when pull_request
is also specified?
#25654
-
I’m using the classical configuration:
When a PR is made, this always run both strategies (obvious), but I don’t want that. What I want is:
Maybe… do I even need Basically on every push or force-push, no matter where to (a branch with or without PR) I want the build to run. This matters for cases where no dedicated PR is needed in branch but I still want to “see” that the tests for this branches are green before merging manually. Or I just want to trigger a test suit run with an idea of a modification. Maybe I’m overthinking things, not sure. Or I don’t get the proper distinction between them. I looked at https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#on but can’t derive a clear answer. It sounds similar to https://github.community/t5/GitHub-Actions/How-to-trigger-an-action-on-push-or-pull-request-but-not-both/m-p/35805 which doesn’t have a satisfiying answer. Thanks,
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Hey! I am trying to understand exactly what you are looking for here. Is it fair to say that your desired workflow is: “Basically on every push or force-push, no matter where to (a branch with or without PR) I want the build to run.” or am I misunderstanding something? |
Beta Was this translation helpful? Give feedback.
-
Let me sort out your requirement, for example there is a pull request from dev to master, when changes push to dev.
>> What I have to say is that your requirement could not be reached. If you want to run a build when push to every branch , you need to specify on:push in the workflow yml file on all branches . This will lead to that on push will work no matter there is a pull request or not. The workflow on pull request is building a pre merged code from dev to master (refs/pull/id/merge) , the workflow on push is building just code on dev branch. These two workflow runs are running with different codes. You could not prevent the workflow run on push event. |
Beta Was this translation helpful? Give feedback.
-
> Hey! I am trying to understand exactly what you are looking for here. Is it fair to say that your desired workflow is: “Basically on every push or force-push, no matter where to (a branch with or without PR) I want the build to run.” or am I misunderstanding something? Yes, that’s th gist and correct! > These two workflow runs are running with different codes. You could not prevent the workflow run on push event. Oh, I think this is the news for me! So:
> The workflow on pull request is building a pre merged code from dev to master (refs/pull/id/merge) Did I got this right? Drive-by question: If so, what happens on merge conflicts with master/target branch? It totally makes sense but it’s also totally not obvious to me 😅 I’m not able to find this in the documentation or I’m looking in the wong place. Places I read: That seems to be the first place to start Very detailed on it’s parameters, but doens’t tell you about the git/tree state? thanks |
Beta Was this translation helpful? Give feedback.
-
Yes, you got it right. The git/tree you mentioned is the GITHUB_REF. You could see the environment variable description here. Note: I think the ‘pull’ you mentioned above is push.
When PR reports merge conflicts, the workflow on: pull_request will not be triggered. |
Beta Was this translation helpful? Give feedback.
-
Thank you so much, this totally clears things up 🙇♀️ |
Beta Was this translation helpful? Give feedback.
-
Have you figure out the answer? It’s happing to me as well. I don’t want multiple builds(for push and PR) when PR is already created |
Beta Was this translation helpful? Give feedback.
Yes, you got it right. The git/tree you mentioned is the GITHUB_REF. You could see the environment variable description here.
Note: I think the ‘pull’ you mentioned above is push.
When …