AI Hints
Home›CI/CD with GitHub Actions Tutorial›Events, Jobs and Steps
CI/CD with GitHub Actions · Lesson 19 of 138

Events with on

What starts a workflow.

⏱ 2 min read▶ Video at 21:41🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Every workflow starts because of an event. Someone pushed code, opened a pull request, created a release, or a timer went off. The on key lists the events your workflow listens for.

Events with on
From the video: Events with on
  • Every run has a cause
  • Push, pull request, release
  • The on key

Three ways to write on

The simplest form is a single event, like push. A list in square brackets listens for several events. And the longest form, a map, lets you add settings to each event, like which branches count. That's the form most real workflows use.

on.ymlyaml
# one event
on: push

# several events
on: [push, pull_request]

# events with settings
on:
  push:
    branches: [main]
  pull_request:

Common events

These are the events you'll use most. Push runs when commits arrive. Pull request runs when a pull request is opened or updated. Workflow dispatch adds a run button. Schedule runs on a timer. And release runs when you publish a release.

EventRuns when
pushcommits are pushed
pull_requesta PR is opened or updated
workflow_dispatchsomeone clicks Run
schedulea timer fires (cron)
releasea release is published

Summary

The on key lists the events that start a workflow. One event, a list, or a map with settings. Next, jobs and the runners they use.

Key takeaways
  • on: push
  • on: [push, pull_request]
  • on: with settings
Next up: Jobs and runs-on — machines for your work