Events in GitHub Actions (Triggers)
Definition In GitHub Actions, an event is something that happens inside GitHub which causes a workflow to start. Events tell the workflow when it should run.
Every workflow starts with:
on:
Whatever you write under this section decides the trigger.
Types of Events There are many events. Below are the most commonly used events in DevOps and CI/CD teaching.
- push
- pull_request
- workflow_dispatch
- schedule
- release
- issues
- create and delete
- workflow_run
- path based triggers
- tag based triggers
- multiple events combined
Now each one explained in detail.
- push Event
Runs when someone pushes code to a branch.
Example:
on: push
Runs on all branches.
If you want only main branch:
on:
push:
branches: [ main ]
If you want multiple branches:
on:
push:
branches:
- main
- dev
Push event runs whenever a commit is pushed.
- pull_request Event
Runs when a pull request is created, reopened, or updated.
Example:
on: pull_request
Runs for all PR branches targeting any branch.
To run only when PR targets main:
on:
pull_request:
branches: [ main ]
Usage: Testing, linting, security scanning before merging.
- workflow_dispatch Event
Used for manual running. Adds a "Run workflow" button in Actions tab.
on:
workflow_dispatch:
Without this, manual run is not possible.
You can also add inputs:
on:
workflow_dispatch:
inputs:
username:
description: "Enter name"
required: true
- schedule Event
Used to run workflows on a time schedule (cron jobs).
Example: run every day at midnight.
on:
schedule:
- cron: "0 0 * * *"
Example: run every hour
cron: "0 * * * *"
Usage: Nightly builds Daily reports Automatic backups Regular health checks
- release Event
Runs when a release is created.
on:
release:
types: [created]
Usage: Packaging Publishing software Deploying final artifacts
- issues Event
Runs when an issue is opened, edited, or closed.
Example:
on:
issues:
types: [opened]
Usage: Auto reply bot Auto label bot
- create and delete Events
Runs when a branch or tag is created or deleted.
Example:
on:
create
or
on:
delete
Usage: Notify team when new branch is created Handle tag creation
- workflow_run Event
Triggered after another workflow finishes.
Example:
on:
workflow_run:
workflows: ["Build"]
types:
- completed
This runs after the workflow named Build completes.
Usage: Chaining workflows Post-deployment tasks
- Path based events
Trigger workflow only when specific files are changed.
Example:
on:
push:
paths:
- "src/**"
Runs only if files inside src folder changed.
Exclude paths:
on:
push:
paths-ignore:
- "docs/**"
Usage: Run tests only when code changes Skip workflow when docs change
- Tag based events
Trigger on tag creation.
Example:
on:
push:
tags:
- "v*"
Runs when tag starts with v (v1.0, v2.3 etc)
Usage: Release builds Version packaging
- Multiple Events Combined
You can combine events using list.
Example:
on:
push:
pull_request:
workflow_dispatch:
Or:
on: [push, pull_request]
name: Multi Event Workflow
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
schedule:
- cron: "0 5 * * *"
release:
types: [created]
jobs:
demo:
runs-on: ubuntu-latest
steps:
- run: echo "Triggered workflow"
Explanation: Runs on push to main Runs on PR to main Runs manually Runs every day at 5AM Runs when a release is created
Events decide when a workflow will run. Different events are used for different automation needs. push and pull_request are the most used. workflow_dispatch is for manual run. schedule is for cron jobs.