DevOpsil
GitHub Actions33 commands

GitHub Actions Cheat Sheet

Essential GitHub Actions syntax for workflows, jobs, steps, secrets, matrices, caching, and reusable actions.

Workflow Triggers

CommandDescription
on: push
Trigger on any push
on: push: branches: [main]
Trigger on push to main
on: pull_request
Trigger on PR events
on: schedule: - cron: '0 9 * * 1'
Run every Monday at 9 AM UTC
on: workflow_dispatch
Manual trigger with button
on: release: types: [published]
Trigger on new release

Job Syntax

CommandDescription
runs-on: ubuntu-latest
Run on latest Ubuntu
needs: [build, test]
Job depends on other jobs
if: github.ref == 'refs/heads/main'
Conditional job execution
strategy: matrix: node: [18, 20, 22]
Matrix build across versions
timeout-minutes: 15
Set job timeout
concurrency: group: ${{ github.ref }}
Prevent concurrent runs

Common Steps

CommandDescription
uses: actions/checkout@v4
Check out repository code
uses: actions/setup-node@v4 with: node-version: 20
Set up Node.js
uses: actions/cache@v4 with: path: ~/.npm key: ...
Cache dependencies
uses: actions/upload-artifact@v4
Upload build artifact
uses: actions/download-artifact@v4
Download artifact in later job
run: npm ci && npm test
Run shell commands

Secrets & Variables

CommandDescription
${{ secrets.MY_SECRET }}
Access repository secret
${{ vars.MY_VARIABLE }}
Access repository variable
${{ github.sha }}
Current commit SHA
${{ github.actor }}
User who triggered workflow
${{ github.event.pull_request.number }}
PR number
${{ env.MY_VAR }}
Access environment variable

Deployment Patterns

CommandDescription
environment: production
Use deployment environment
environment: url: https://my-app.com
Set environment URL
permissions: contents: read id-token: write
Set OIDC permissions
uses: aws-actions/configure-aws-credentials@v4
AWS OIDC auth
if: success() && github.ref == 'refs/heads/main'
Deploy only on success + main

gh CLI in Actions

CommandDescription
gh pr comment $PR --body "Deployed!"
Comment on PR
gh release create v1.0 --generate-notes
Create release with notes
gh api repos/$REPO/deployments
List deployments via API
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Auto-provided token for gh