GitHub Actions: Workflow Syntax and Triggers

Workflow YAML structure, common triggers, path filters, schedule, workflow_dispatch, concurrency, and job basics for GitHub Actions.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Workflow skeleton

Start with the core keys every workflow uses.

Minimal workflow file

Basic YAML structure for a workflow.

yamlANYworkflowyamlbasic
yaml
name: CI

on:
  push:
    branches: [main]
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: echo "Hello from GitHub Actions"
Notes

Workflows live under `.github/workflows/*.yml` and define triggers, jobs, and steps.

Name a workflow clearly

Use a descriptive workflow name.

yamlANYnameworkflow
yaml
name: Node.js CI
Notes

A clear name helps people quickly identify runs in the Actions tab and status checks.

Run on push to selected branches

Trigger on pushes to specific branches.

yamlANYpushbranches
yaml
on:
  push:
    branches:
      - main
      - develop
Notes

Use branch filters to avoid running expensive workflows everywhere.

Run on pull requests

Trigger on pull requests for review pipelines.

yamlANYpull_requestpr
yaml
on:
  pull_request:
    branches: [main]
Notes

This is common for lint, test, and build validation before merging.

Add a manual run button

Enable workflow_dispatch for manual execution.

yamlANYworkflow_dispatchmanual
yaml
on:
  workflow_dispatch:
Notes

This adds a Run workflow button in GitHub Actions.

Manual run with inputs

Prompt for environment or other runtime parameters.

yamlANYworkflow_dispatchinputs
yaml
on:
  workflow_dispatch:
    inputs:
      environment:
        description: Deploy target
        required: true
        default: staging
        type: choice
        options:
          - staging
          - production
Notes

Inputs are useful for ad hoc deploys, scripts, and maintenance workflows.

Run on a cron schedule

Schedule workflows using cron syntax in UTC.

yamlANYschedulecron
yaml
on:
  schedule:
    - cron: "0 6 * * 1-5"
Notes

Scheduled workflows are good for cleanup, dependency updates, sync jobs, and audits.

Filters and concurrency

Use filters to limit runs and concurrency to cancel duplicates.

Run only when selected paths change

Use `paths` to scope the workflow to files or directories.

yamlANYpathsfilters
yaml
on:
  push:
    paths:
      - "src/**"
      - "package.json"
      - ".github/workflows/ci.yml"
Notes

Path filters save minutes and cost by skipping unrelated changes.

Ignore docs-only changes

Exclude paths that should not trigger CI.

yamlANYpaths-ignorefilters
yaml
on:
  pull_request:
    paths-ignore:
      - "docs/**"
      - "**/*.md"
Notes

Useful when docs edits do not need a full build pipeline.

Cancel in-progress duplicate runs

Use concurrency groups to keep only the latest run active.

yamlANYconcurrencycancel-in-progress
yaml
concurrency:
  group: ci-${{ github.ref }}
  cancel-in-progress: true
Notes

This is especially valuable on busy branches where every new push supersedes the prior run.

Set a job timeout

Prevent jobs from hanging forever.

yamlANYtimeoutjob
yaml
jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 20
Notes

Timeouts keep queues healthy and cap costs when a process hangs.

Chain jobs with needs

Run a deploy only after tests succeed.

yamlANYneedsdependencies
yaml
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - run: npm test

  deploy:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - run: echo "Deploying..."
Notes

`needs` defines job dependencies and helps structure staged pipelines.

Recommended next

No recommendations yet.