CodeBlanks Logo Icon CodeBlanks

Trigger

Learn push and pull request triggers.

What is a trigger?

A trigger determines which event starts a workflow. In GitHub Actions, the push event can start a workflow when new commits are pushed to a repository, while the pull_request event can start one when a pull request is opened or updated. These events are defined under the on field.

on:
  push:
  pull_request:

Push and pull request events

The push trigger runs when commits are pushed to the specified repository. The pull_request trigger can be used for activities such as opening and updating pull requests. By defining both events in the same workflow, you can automatically check code pushes and the review process.

on:
  push:
  pull_request:

Practice Define two triggers

Enable both push and pull_request events in the workflow file. Both events must be defined under the on field.

Starter code

terminal
name: Event Checks

on:
  # Push olayını ekle
  # Pull request olayını ekle

jobs:
  test:
    runs-on: ubuntu-latest

Sample solution

terminal
name: Event Checks

on:
  push:
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest

Expected output

Event Checks
push
pull_request
test
ubuntu-latest

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which event starts a workflow when a pull request is opened?

  • merge
  • push
  • pull_request Correct answer
  • commit

Explanation: The pull_request event allows a workflow to run when pull request activities occur.

2 Add the push event

Question
on:
  ____:
  pull_request:
Answer
on:
  push:
  pull_request:

Explanation: push is the event that starts a workflow when commits are pushed to the repository.

3 Trigger types

Term Meaning
on Defines events
push Runs on a code push
pull_request Runs on a PR activity
Trigger Workflow starting event

All lessons in Intermediate

20 Intermediate final

  1. Branch management
  2. Rebase
  3. Conflict
  4. PR flow