Workflow Triggers
- pushOn push to branch
- pull_requestPR events
- scheduleCron schedule
- workflow_dispatchManual trigger
- repository_dispatchAPI trigger
- releaseRelease events
Job Keywords
- runs-onRunner environment
- needsJob dependencies
- ifConditional run
- timeout-minutesJob timeout
- continue-on-errorAllow failure
- environmentDeploy environment
Step Keywords
- usesUse action
- runRun command
- withAction inputs
- envEnvironment vars
- idStep identifier
- working-directoryRun directory
Runners
- ubuntu-latestUbuntu LTS
- ubuntu-22.04Ubuntu 22.04
- windows-latestWindows Server
- macos-latestmacOS
- self-hostedCustom runner
Basic Workflow
name: CI Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- run: npm test
Matrix Strategy
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [18, 20]
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm test
Context Variables
- github.shaCommit SHA
- github.refBranch/tag ref
- github.actorUser who triggered
- github.repositoryRepo name
- github.event_nameTrigger event
- runner.osRunner OS
Secrets & Variables
- ${{ secrets.NAME }}Access secret
- ${{ vars.NAME }}Access variable
- GITHUB_TOKENAuto-generated
- ${{ env.NAME }}Env variable
Conditionals & Expressions
# Run only on main branch
if: github.ref == 'refs/heads/main'
# Run on success of previous job
if: success()
# Run even if previous failed
if: always()
# Run only on failure
if: failure()
# Complex condition
if: github.event_name == 'push' && contains(github.ref, 'release')
Popular Actions
- actions/checkoutClone repo
- actions/setup-nodeSetup Node.js
- actions/setup-pythonSetup Python
- actions/cacheCache deps
- actions/upload-artifactUpload files
Cron Schedule
on:
schedule:
# Every day at 2am UTC
- cron: '0 2 * * *'
# Every Monday at 9am
- cron: '0 9 * * 1'
# Format: min hour day month weekday