on push and on pull_request difference in github actions?
On every pull request we are pushing our code then why do we need on push and on pull_request isn't just on push enough?
You can trigger only on pushes to master or pull requests to master. This will prevent builds from happening twice when somebody opens a pull request against master and then pushes updates to their branch.
For example:
on:
push:
branches:
- master
pull_request:
branches:
- master
on push and on pull_request difference in github actions?
In general, push
will trigger when you push code where pull_request
will trigger when there is a pull request.
They overlap when you create PRs from the same repo, but you need pull_request
if you want to run an action when you receive a PR from a fork for example. You need push
when you want to run an action when something is push. You can fine tune them depending on the behaviour you expect to avoid duplication of jobs.
Example that highlights the difference and shows that both can be important and needed:
Imagine you want to run CI tests every time code is pushed
, but only when in a PR (eg to save money in GHA)
If you only use on: push
then when the PR is first raised, you won't have any tests run (because raising a PR alone does not trigger the on: push
)
You also need on: pull_request