Disable Github Action workflow, only run when desired

12.4k Views Asked by At

I have some very expensive benchmarks/tests which I'd only like to run on some PRs, not all. Is there a way to do this with github actions?

1

There are 1 best solutions below

0
On BEST ANSWER

Yes, there are several ways. Most of the workflow triggers can be further specified through "Activity Types". For Pull Requests, they are:

  • assigned
  • unassigned
  • labeled
  • unlabeled
  • opened
  • edited
  • closed
  • reopened
  • synchronize
  • ready_for_review
  • locked
  • unlocked
  • review_requested
  • review_request_removed

(Docs as Source)

Now, you could run the workflow only for PRs matching a certain pattern:

on:
  pull_request:
    branches:
      - 'benchmark/**'

You could also do it with labels:

on:
  pull_request: labeled
...
jobs:
  check-label:
    if: ${{ github.event.label.name == 'benchmark' }}
...

And of course you can also always use manual triggers only:

on: workflow_dispatch