Trigger GitHub Action when push from specific branch

Viewed 994

We have a branch model with feature branches, develop, staging (for testing) and master for release. Now we have an action for the Release notes, which creates a Pull Request with the actual release notes when pushing to staging or master.

But the action should only run when we push a Pull Request from develop into staging and from staging into master, but not when pushing from the release notes branch into staging or master. Is this possible? Thank you!

1 Answers

Since your release notes are likely being generated in a specific path (inferred from the fact that you're making a new PR containing the new release notes), you can ignore that path in your "on push"-triggered action. This means that the action will not be triggered on pushes to master or staging unless at least 1 changed file is outside the ignored path:

on:
  push:
    paths-ignore:
    - 'release_notes/**'
    branches:
      - master
      - staging
# ...

Source: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#onpushpull_requestpaths

Related