← Cheatsheets
CI/CD

GitHub Actions

Workflow syntax, triggers, contexts and common patterns for building CI/CD pipelines with GitHub Actions.

Workflow Structure

name:
on:
jobs:
runs-on: ubuntu-latest
steps:
uses: actions/checkout@v4
run: echo hello

Triggers (on:)

on: push
on: push: branches: [main]
on: pull_request
on: schedule: cron: '0 6 * * *'
on: workflow_dispatch
on: workflow_call

Contexts & Expressions

${{ github.sha }}
${{ github.ref_name }}
${{ github.actor }}
${{ github.event_name }}
${{ runner.os }}
${{ env.MY_VAR }}
${{ secrets.MY_SECRET }}
${{ vars.MY_VAR }}

Jobs & Control Flow

needs: build
if: github.ref == 'refs/heads/main'
continue-on-error: true
timeout-minutes: 10
strategy: matrix:
environment: production

Secrets & Variables

env: MY_VAR: ${{ secrets.TOKEN }}
secrets.GITHUB_TOKEN
with: token: ${{ secrets.GITHUB_TOKEN }}

Artifacts & Cache

uses: actions/upload-artifact@v4
uses: actions/download-artifact@v4
uses: actions/cache@v4
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}

Common Actions

actions/checkout@v4
actions/setup-node@v4
actions/setup-python@v4
docker/build-push-action@v5
aws-actions/configure-aws-credentials@v4