Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

Chapter 2Name in the course: Events that trigger workflows

Start workflows at the right time

The on: block decides when a workflow runs: on pushes to some branches, on pull requests, on a schedule, by hand, or when another workflow finishes. Filters keep pipelines fast and cheap.

  • 5 Lessons
  • 1 Commands

$ run as a normal user# run as root (or with sudo)

2.1

Run on push and pull request

The most used events. Filter by branch, tag and path.

.github/workflows/terraform.yml
on:
  push:
    branches: [main]
    tags: ["v*"]
    paths: ["envs/**", "modules/**"]
  pull_request:
    branches: [main]
    paths-ignore: ["docs/**", "**.md"]
FilterMeaning
branches / branches-ignoreOnly these / not these branches
tagsTag pushes, for releases
paths / paths-ignoreOnly when these files changed

Remember

pull_request runs the code of the PR in a safe context: secrets are not given to PRs from forks.

2.2

Run on a schedule

schedule uses cron syntax in UTC — for nightly scans, drift checks and reports.

.github/workflows/nightly.yml
on:
  schedule:
    - cron: "30 1 * * *"

Watch out

Scheduled runs can start late at busy times, and they stop after 60 days without activity in a public repository.

2.3

Run by hand with inputs

workflow_dispatch adds a Run workflow button, with inputs you choose.

.github/workflows/deploy.yml
on:
  workflow_dispatch:
    inputs:
      environment:
        type: choice
        options: [staging, prod]
        default: staging
      dry_run:
        type: boolean
        default: true
 
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Deploying to ${{ inputs.environment }} (dry run ${{ inputs.dry_run }})"
gh workflow run deploy.yml -f environment=staging -f dry_run=false

Commands in this lesson

2.4

Chain workflows

workflow_run starts a workflow when another one finishes; workflow_call makes a workflow reusable (see Reuse workflows).

.github/workflows/deploy-after-ci.yml
on:
  workflow_run:
    workflows: [CI]
    types: [completed]
    branches: [main]
jobs:
  deploy:
    if: github.event.workflow_run.conclusion == 'success'
    runs-on: ubuntu-latest
    steps:
      - run: echo "CI passed, deploying"

2.5

Know other useful events

Many GitHub events can start automation.

EventUse
release (types: [published])Build and upload release files
issues, issue_commentLabel or triage issues
merge_groupChecks for the merge queue
repository_dispatchStart from an outside system through the API
pull_request_targetRuns with secrets for PRs from forks — dangerous, see Secure your pipelines

All commands in this chapter