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
Minimal workflow file
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"

# Basic YAML structure for a workflow.

Name a workflow clearly
name: Node.js CI

# Use a descriptive workflow name.

Run on push to selected branches
on:
  push:
    branches:
      - main
      - develop

# Trigger on pushes to specific branches.

Run on pull requests
on:
  pull_request:
    branches: [main]

# Trigger on pull requests for review pipelines.

Add a manual run button
on:
  workflow_dispatch:

# Enable workflow_dispatch for manual execution.

Manual run with inputs
on:
  workflow_dispatch:
    inputs:
      environment:
        description: Deploy target
        required: true
        default: staging
        type: choice
        options:
          - staging
          - production

# Prompt for environment or other runtime parameters.

Run on a cron schedule
on:
  schedule:
    - cron: "0 6 * * 1-5"

# Schedule workflows using cron syntax in UTC.

## Filters and concurrency
Run only when selected paths change
on:
  push:
    paths:
      - "src/**"
      - "package.json"
      - ".github/workflows/ci.yml"

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

Ignore docs-only changes
on:
  pull_request:
    paths-ignore:
      - "docs/**"
      - "**/*.md"

# Exclude paths that should not trigger CI.

Cancel in-progress duplicate runs
concurrency:
  group: ci-${{ github.ref }}
  cancel-in-progress: true

# Use concurrency groups to keep only the latest run active.

Set a job timeout
jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 20

# Prevent jobs from hanging forever.

Chain jobs with needs
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - run: npm test

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

# Run a deploy only after tests succeed.

Recommended next

No recommendations yet.