Workflow Triggers and Events
Explore various events that can trigger your GitHub Actions workflows, such as pushes, pull requests, and scheduled events.
Workflow Triggers and Events is a free DevOps Bootcamp lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Starts a Workflow?
Workflows in GitHub Actions don't just run by themselves. They need a signal to start! This signal is called a trigger.
Triggers are specific events that tell GitHub Actions, "Hey, something happened! Time to run this workflow." Understanding triggers is key to automating your development process effectively.
The 'on' Keyword
In your workflow file (a .yml file in the .github/workflows directory), you define triggers using the on keyword.
This section tells GitHub Actions when to execute the workflow. You can specify one or many events.
name: My First Triggered Workflow
on:
push: # This workflow will run on every push event
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run a simple command
run: echo "Workflow triggered!"
Reacting to Code Pushes
The push event is one of the most common triggers. It fires whenever code is pushed to your repository, whether it's a new commit or a merge.
By default, a push trigger will run for all branches.
on: push
jobs:
greeting:
runs-on: ubuntu-latest
steps:
- name: Say Hello
run: echo "Code was pushed!"
Targeted Pushes
You can refine the push trigger to run only for specific branches or when changes occur in particular file paths. This helps optimize your workflows.
branches: Run only when pushes occur on specific branch names.paths: Run only when changes are made to files within specified directories.
on:
push:
branches:
- main
- 'feature/*' # Glob pattern for feature branches
paths:
- 'src/**' # Only if changes in src/ directory
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: echo "Push to relevant branch/path detected!"
Automating Pull Request Checks
The pull_request event triggers when a pull request is opened, synchronized (new commits pushed to the PR branch), or reopened.
It's ideal for running automated checks like tests, linting, or code reviews before changes are merged into your main codebase.
on: pull_request
jobs:
pr_check:
runs-on: ubuntu-latest
steps:
- name: PR opened/updated
run: echo "A pull request was opened or updated!"
Specific PR Actions
You can further refine the pull_request trigger by specifying types. This allows your workflow to react only to specific actions related to a pull request.
opened: When a new pull request is created.synchronize: When new commits are pushed to the PR's branch.reopened: When a closed pull request is reopened.
on:
pull_request:
types: [opened, synchronize, reopened] # Run only on these PR actions
jobs:
pr_review:
runs-on: ubuntu-latest
steps:
- run: echo "PR action: ${{ github.event.action }}"
Time-Based Triggers
The schedule event allows you to run workflows at specific times using cron syntax. This is perfect for daily reports, cleanup tasks, or periodic checks.
Cron syntax uses five asterisks representing: minute hour day-of-month month day-of-week.
on:
schedule:
- cron: '0 0 * * *' # Run daily at midnight UTC
- cron: '0 12 * * 1-5' # Run at 12 PM UTC, Mon-Fri
jobs:
scheduled_task:
runs-on: ubuntu-latest
steps:
- run: echo "Scheduled workflow running!"
Manual Workflow Runs
Sometimes you need to run a workflow manually, perhaps for a deployment or a specific maintenance task. The workflow_dispatch event enables this.
When this trigger is present, a "Run workflow" button appears in the GitHub UI for that workflow, allowing you to trigger it on demand.
on: workflow_dispatch
jobs:
manual_task:
runs-on: ubuntu-latest
steps:
- run: echo "This workflow was triggered manually!"
Beyond the Basics
While push, pull_request, schedule, and workflow_dispatch are the most common, GitHub Actions offers many other event triggers.
workflow_call: For creating reusable workflows.repository_dispatch: For triggering workflows from external systems via an API call.- Many more for specific GitHub events (e.g.,
issues,release,fork).
Trigger Challenge
You need to set up a workflow that automatically generates a weekly report every Friday at 5 PM UTC, regardless of any code changes. Which trigger event is the most appropriate for this task?
Triggers in Review
Great job exploring GitHub Actions triggers! You've learned how workflows are started by various events:
push: For changes pushed to your repository.pull_request: For actions related to pull requests.schedule: For time-based, recurring tasks using cron.workflow_dispatch: For manual execution from the UI or API.
Choosing the right trigger is the first step to building effective and efficient CI/CD pipelines!
Frequently asked questions
Is the “Workflow Triggers and Events” lesson free?
Yes — the full text of “Workflow Triggers and Events” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.
What will I learn in “Workflow Triggers and Events”?
Explore various events that can trigger your GitHub Actions workflows, such as pushes, pull requests, and scheduled events. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start DevOps Bootcamp?
No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Workflow Triggers and Events” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this DevOps Bootcamp lesson?
Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Workflow Triggers and Events
- Running Tests with GitHub Actions
- Linting and Code Quality Checks
- Caching Dependencies for Faster Builds