Hi @zaro0508 ,
Thank you for the question!
I believe that when pull requests are opened, the text
pull/ is contained in the branch name.
We can use this to filter the branches for which jobs are executed upon.
First, we can set the job filtering to the following conditions:
- For the
pre-merge workflow, filter the jobs to only run if
pull/ is included in the branchname
- For the
merge workflow, filter the jobs to only run if
pull/ is not included in the branchname
Since this syntax can get kind of long when specifying it for multiple jobs, I will use yaml aliases to simplify it (I am using negative lookaheads here, but if there are issues with this, then using the
ignore key could replace them):
If we use this in the workflows, it would look something like this:
By having the filter condition for every job, if no jobs are to be run for a workflow, the workflow will not execute.
Another method would be to check for the value of environment variables such as
CIRCLE_PULL_REQUEST. Then you could cancel a workflow based on if it is defined or not (as this variable is only present in jobs triggered by a PR ).
One caveat with this approach is that a workflow will actually be triggered on CircleCI, but it will be immediately canceled. The filter approach I mentioned earlier will not trigger a workflow on CircleCI.
Let me know if this points you in the right direction, and if I seem to have misunderstood your question, please let me know and I am happy to take another look!