Skip to content

Latest commit

 

History

History
78 lines (57 loc) · 1.44 KB

File metadata and controls

78 lines (57 loc) · 1.44 KB

GitHub Actions: Workflow Triggers


In GitHub Actions, a trigger defines when and why a workflow runs. Triggers listen for specific events in your repository. Understanding triggers is essential to ensure your workflow runs at the right time and on the right branches.


1. push

  • Triggered when code is pushed to a branch or tag.
  • Commonly used for CI pipelines to automatically build and test new commits.
  • Example: trigger on main branch:
on:
  push:
    branches:
      - main
  • Trigger on tags (e.g., version release):
on:
  push:
    tags:
      - 'v*.*.*'

2. pull_request

  • Triggered on pull requests targeting specific branches.
  • Useful for running tests and validations before merging code.
  • Example:
on:
  pull_request:
    branches:
      - main

3. schedule

  • Trigger workflows automatically on a schedule using cron syntax.
  • Use case: nightly builds, periodic tests, or maintenance tasks.
  • Example: daily at midnight:
on:
  schedule:
    - cron: "0 0 * * *"

4. workflow_dispatch

  • Manual trigger from the GitHub UI.
  • Can accept inputs/parameters for flexible workflows.
  • Example:
on:
  workflow_dispatch:
    inputs:
      env:
        description: 'Deployment environment'
        required: true
        default: 'staging'