Skip to content

Chapter 5 of 9

Events and Triggers

Trigger workflows precisely with repository events, filters, schedules, and manual inputs.

34 minutes 10 quick checksBy Subha Prasad
Lesson 5 of 9Course navigation

Lesson content

Read, practise, then check your understanding

Events and Triggers

The on configuration determines when a workflow is eligible to run. Precise triggers reduce noise and cost while ensuring important changes are validated. Event payloads are available through the github context and the file path stored in github.event_path.

Core ideas

  • push can filter branches, tags, and changed paths.
  • pull_request runs in the base repository context; activity types can narrow actions such as opened or synchronize.
  • workflow_dispatch provides a manual entry point with typed inputs.
  • schedule uses POSIX cron in UTC and runs from the default branch; scheduled runs can be delayed during high load.

How it works

Filters at the same level are combined according to GitHub's event rules. When both branch and path filters are present, both must match. A skipped required workflow can leave a required check pending, so design required checks and filters together.

Configuration example

on:
  push:
    branches: [main, "release/**"]
    paths:
      - "src/**"
      - "package-lock.json"
  pull_request:
    types: [opened, synchronize, reopened]
  schedule:
    - cron: "23 2 * * 1-5"
  workflow_dispatch:
    inputs:
      deploy:
        type: boolean
        default: false

Read the example from top to bottom: the trigger creates a run, the job requests a runner, and each step receives only the context configured for it. Adapt names, versions, permissions, and commands to the repository rather than copying production credentials or policies blindly.

Production guidance

  • Use a non-round cron minute to reduce contention at the top of the hour.
  • Inspect the event name and ref in logs while developing trigger logic.
  • Treat pull_request_target as privileged: never check out and execute untrusted pull-request code with its credentials.

The chapter quiz follows this lesson and checks both the vocabulary and the operational decisions behind the configuration.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement correctly describes push?
Which term matches this explanation: An event emitted when commits or tags are pushed.
Which statement correctly describes pull_request?
Which term matches this explanation: An event for pull request lifecycle activity in the base repository.
Which statement correctly describes workflow_dispatch?
Which term matches this explanation: A trigger that enables a workflow to be started manually with optional inputs.
Which statement correctly describes schedule?
Which term matches this explanation: A UTC cron-based trigger for recurring workflows.
Which statement correctly describes path filter?
Which term matches this explanation: An include or exclude rule limiting runs based on changed file paths.

0 of 10 checks passed

Your progress is saved on this device.

Events and Triggers | Actions Lesson | Subha Prasad