Reputation: 575
I'm trying to create an action whose workflow runs when Pull Requests from specific branches are opened against master. What I currently have runs the workflow on all Pull requests opened against master from all branches.
name: Auto Approve Pull Request
on:
pull_request:
branches:
- 'master'
- 'skip-*'
jobs:
build:
name: Approve PR
runs-on: ubuntu-latest
steps:
- name: Fetch out code
uses: username/my-github-repo@master
with:
token: ******
env:
BRANCH_PREFIX: "skip-*"
PULL_REQUEST_BRANCH: "master"
I wanted to have the workflow to run on just branches named skip-*
.
Upvotes: 4
Views: 2166
Reputation: 575
The solution I found was to use an if statement to check that the head-ref branch name matches (starts with) skip-
.
Here's my solution:
name: Auto Approve Pull Request
on:
pull_request:
branches:
- 'master'
jobs:
build:
name: Approve PR
runs-on: ubuntu-latest
if: startsWith(github.head_ref, 'skip-') == true
steps:
- name: Fetch out code
uses: username/my-github-repo@master
with:
token: ******
env:
BRANCH_PREFIX: "skip-*"
PULL_REQUEST_BRANCH: "master"
Notes:
- Use the github context to find the branch name that's opening the Pull Request (https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context)
- Github functions: https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#startswith
Upvotes: 6