Regular expression pattern matching is possible in github actions? #26771
-
Is regular expression pattern matching is possible in Github actions? I have few release branches with name release/v1.1, release/v1.2 etc… Let’s say my current branch is release/v1.1. How do i pass it as a regular expression with the pattern that matches my branch ? if: contains(github.ref, ‘release/*’) or if [[ ${{ env.BRANCH }} =~ release/.* ]] |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
yogesh-kumitisomu-by:
yogesh-kumitisomu-by:
That is Bash syntax, you can use it within a |
Beta Was this translation helpful? Give feedback.
-
Somehow the below condition doesn’t work for me if i use it in run step. if [[ ${{ env.BRANCH }} =~ release/.* ]] Is it the right way to declare ? |
Beta Was this translation helpful? Give feedback.
-
You’ll have to provide more context to answer that, ideally the full workflow and a description of how it doesn’t work, like in a bug report: What do you expect, what actually happens? And of course that only works if you actually have |
Beta Was this translation helpful? Give feedback.
-
Thanks. I tried with the below one and it worked. if: startsWith(github.ref, ‘refs/heads/release/’) Considering base branch as release, how can i check for the pull request level ? |
Beta Was this translation helpful? Give feedback.
-
yogesh-kumitisomu-by:
I’m not sure what you mean, could you explain? Something related to merging into a release branch? |
Beta Was this translation helpful? Give feedback.
-
Ok. Let’s say i have multiple release branches with the name release/v1.1, release/v1.2 (This is at the branch level the below condition works if: startsWith(github.ref, ‘refs/heads/release/’) Similarly if developer raises a Pull request for any of these release branches release/v1.1 or release/v1.2. I know something like below will work for exact matching branch…How can i have the if condition to check for multiple pull request release branches ? if: github.event.pull_request.base.ref == ‘release/v1.1’ Because based on the above PR for the respective release branches, i need to set an environment variable. But for all the release branches i am going to use the same environment variable as test. |
Beta Was this translation helpful? Give feedback.
-
One option would be to use If you need more complex logic the best thing might be to feed the base ref to a custom command/script, and decide what to write to |
Beta Was this translation helpful? Give feedback.
-
Thanks. This helps!!! |
Beta Was this translation helpful? Give feedback.
One option would be to use
startWith()
ongithub.event.pull_request.base.ref
.If you need more complex logic the best thing might be to feed the base ref to a custom command/script, and decide what to write to
GITHUB_ENV
in there. That way you have a lot more options to write the logic you need.