C.W.K.
Stream
Lesson 02 of 12 · published

Events (Triggers)

~12 min · events, triggers, on

Level 0Apprentice
0 XP0/101 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

The 'on' block is your scheduler

Every workflow declares its triggers under on:. The most common triggers, in roughly the order you'll use them:

  • push — fires on every push. Filterable by branches, tags, paths.
  • pull_request — fires on PR open, sync (new commit), reopen, etc. Filterable by branches, paths, types.
  • schedule — cron-like, in UTC. '0 6 * * *' = 06:00 UTC daily.
  • workflow_dispatch — manual trigger from UI / API / CLI. Inputs are first-class.
  • release — fires on release events (created, published, edited).
  • workflow_call — makes this workflow callable from another (reusable workflow).
  • repository_dispatch — external system POSTs to fire it.
  • merge_group — fires inside a merge queue.

Filters narrow the trigger

You almost never want bare on: push. You want push to main or push that changed source files. Filters live under each event:

  • branches / branches-ignore
  • tags / tags-ignore
  • paths / paths-ignore — glob patterns matched against changed files.
  • types — for events with sub-types (PR opened/synchronized/reopened).

Code

Mixed triggers with filters·yaml
name: ci
on:
  pull_request:
    types: [opened, synchronize, reopened, ready_for_review]
    paths:
      - 'src/**'
      - 'tests/**'
      - '.github/workflows/ci.yml'
  push:
    branches: [main]
    tags: ['v*.*.*']
  schedule:
    - cron: '0 6 * * *'   # 06:00 UTC daily
  workflow_dispatch:
    inputs:
      reason:
        description: 'Why are you running this?'
        required: true

External links

Exercise

In a sandbox repo, write one workflow that fires on three different events: push to main, pull_request, and workflow_dispatch with a single input. Make each one echo a different message so you can tell which trigger fired.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.