Execute only on certain branch names during PR #26531
-
I’d like for an action to run on any PR that’s opened and that has a head name like feature/**, fix/** or hotfix/**
However this doesn’t work, the action just sits in “Starting your workflow runs…” |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 2 replies
-
There’s nothing in the documentation to suggest that contains() performs regular expression or pattern matching, so that probably why this isn’t working. Given that all the patterns you’ve listed are prefix matches, have you considered using startsWith() instead? |
Beta Was this translation helpful? Give feedback.
-
I add some comments to your code, please kindly check:
The workflow will be triggered when PR is created from ‘feature**,fix**, hotfix**’ branch to ‘develop’ branch. However i doubt whether you want to check the source branch, if you’d like to limit the workflow to ‘target’ branch, on ‘pull_request.branches’ is enough. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the suggestions @weide-zhou; I’ve updated my code My use case is as follows: we use actions to run all our unit tests including functional tests, we use gitflow for branch naming and therefore I do not want to run unit tests on branches like “docs/**” or “chore/**”. We use these actions as required status checks (base_ref develop) before merging on all head_ref. Therefore, even if skipping the action, I need it to return some sort of success status. I’m doing that now like this:
I tried using
instead of copy&pasting that if line on each step, but that doesn’t work either. Ideally I’d like to do an early success termination on the condition below
|
Beta Was this translation helpful? Give feedback.
-
Glad to support! Since you’d like to return success even if skipping the action, as your code shown, probably you have to set ‘if’ expression on step level instead of job level to achieve this. BTW, if you’d like to skip the whole workflow for PR source branch ‘docs/**’ or ‘chore/**’, you can simply remove the yaml file in these branches. |
Beta Was this translation helpful? Give feedback.
-
Unfortunately that doesn’t actually work; if the whole action is skipped, success is never returned to the status.
This also doesn’t work as the PR will get merged into develop. |
Beta Was this translation helpful? Give feedback.
-
I create a repository for checking:
Status check is passed and steps are skiped for source branch docs/** and feature/**. Please let me know if my understanding is wrong. |
Beta Was this translation helpful? Give feedback.
Hi @constantinoschillebe ,
I create a repository for checking:
Pull request from ‘docs/B2’ to ‘develop’ branch: https://github.com/weide-zhou/ticket22/pull/1
Pull request from ‘feature/B1’ to ‘develop’ branch: https://github.com/weide-zhou/ticket22/pull/2
Pull request form ‘succeedBranch’ to develop, no step is skiped: https://github.com/weide-zhou/ticket22/pull/3
Status check is passed and steps are skiped for source branch docs/** and feature/**.
Please let me know if my understanding is wrong.