Most CI workflows listen for two events. Push, for commits landing on main. And pull request, for changes that want to be merged. Each tells the workflow something different, and you can act on that.
This workflow runs on pushes to main, and on pull requests. The first step prints which event started it, and the branch, using expressions in double curly braces. The second step has an if condition, so it only runs for pull requests.
.github/workflows/events.ymlyaml
name: Eventson: push: branches: [main] pull_request:jobs: info: runs-on: ubuntu-latest steps: - run: echo "Started by ${{ github.event_name }} on ${{ github.ref_name }}" - name: Only for pull requests if: github.event_name == 'pull_request' run: echo "Checking a pull request"
First, as a push to main. The event is push, and the pull request step is skipped. Then, with dash dash event, we pretend a pull request opened from a feature branch. Now the event is pull request, and the extra step runs. One workflow, two behaviours.
Terminal
run-steps .github/workflows/events.ymlWorkflow: Events (event: push, branch: main)Job: info ✓ Run echo "Started by push on main" Started by push on main - Only for pull requests (skipped) Job succeededrun-steps .github/workflows/events.yml --event pull_request --ref add-free-shippingWorkflow: Events (event: pull_request, branch: add-free-shipping)Job: info ✓ Run echo "Started by pull_request on add-free-shipping" Started by pull_request on add-free-shipping ✓ Only for pull requests Checking a pull request Job succeeded
Push and pull request are the core CI events. The github dot event name expression tells you which one started the run. Next, filtering by branch and by changed files.