Triggers: push, pull_request, schedule, manual

GitHub Actions · Essentials · 10 min

Running the right workflow at the right time saves minutes and keeps deploys from firing on the wrong branch.

The on key lists events, optionally with filters.

  • push and pull_request accept branches, tags and paths filters (and -ignore variants). For pull_request the branch filter matches the target branch, so branches: [main] means "PRs into main".
  • pull_request has activity types; the default is opened, synchronize (new commits) and reopened.
  • schedule takes cron expressions in UTC, minimum every 5 minutes, and runs on the default branch only. Scheduled runs can start late under load.
  • workflow_dispatch adds a Run workflow button (and API/CLI trigger) with optional typed inputs, read as inputs.name.
  • Others include release, workflow_run (after another workflow finishes), issues and repository_dispatch for external webhooks.

Glob patterns in filters use * (no slash) and ** (any depth). When both branches and paths are given, both must match.

A pull_request run checks out a temporary merge commit of the PR into the base branch, so tests see what main would look like after merging. Workflows triggered by pull requests from forks get a read-only token and no secrets, which is a deliberate safety measure.

Example

on:
  push:
    branches: [main, "release/**"]
    paths: ["src/**", "package.json"]
  pull_request:
    branches: [main]          # PRs targeting main
  schedule:
    - cron: "30 2 * * 1"      # Mondays 02:30 UTC
  workflow_dispatch:
    inputs:
      environment:
        type: choice
        options: [staging, production]
        default: staging
jobs:
  show:
    runs-on: ubuntu-latest
    steps:
      - run: echo "event=${{ github.event_name }} env=${{ inputs.environment }}" 

Remember

  • push/pull_request filter on branches, tags and paths
  • Cron schedules are UTC and run on the default branch
  • workflow_dispatch adds a manual button with typed inputs

Watch out for

  • Expecting a schedule in a feature branch's workflow file to run: only the default branch's copy is used.

Check yourself

  1. With on: pull_request: branches: [main], which PRs trigger the workflow?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows

Triggers: push, pull_request, schedule, manual · GitHub Actions · Topolearn