Github actions run only on feature branches

Viewed 4210

I am just experimenting with GitHub action and I have the following workflow.

  1. when a developer finishes a feature and creates a PR on (branch name can be in the format of feature/ticketno ), I would like to run some tests against the newly created PR branch.

one solution I found is to add an if condition in the action steps to avoid running tests against the desired branches on the PR up(ie master, staging).

But not sure this is the right approach I looking for a proper solution

1 Answers

Github actions supports triggering a build when a pull request is created pointing to a specified branch or on a push to a wildcard branch. Your scenario would require custom conditions. You might find a good compromise by using branches-ignore and types

here's an example of a wildcard feature branches, push vs pull_request trigger

on:
  push:
    branches:
      - master
      - "feature/*"
  pull_request:
    branches: 
      - master 
      - develop

Also check this Q&A GitHub actions to trigger build on new Pull Requests

For reference and all available options https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions

Related