GitHub Actions Cheatsheet

Basics

Use this GitHub Actions reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.

What is GitHub Actions

GitHub Actions is a CI/CD platform built into GitHub. Workflows run in response to events (push, PR, schedule, etc.) on GitHub-hosted or self-hosted runners.

Use this cheatsheet after a snippet works in an online code editor, Python online compiler, JavaScript playground, or C++ online compiler. Actions turns that browser experiment into repeatable CI so every push can install dependencies, run tests, and catch regressions.

Key concepts:

TermDescription
WorkflowYAML file in .github/workflows/ — the top-level unit
EventWhat triggers the workflow (push, pull_request, schedule, …)
JobA group of steps that run on the same runner
StepA single shell command or reusable Action
ActionA reusable unit — from Marketplace or your own repo
RunnerThe VM/container that executes the job

File Location

Workflows live in .github/workflows/ at the root of your repo.

.github/
  workflows/
    ci.yml
    deploy.yml
    nightly.yml

Any .yml or .yaml file in that directory is picked up automatically.

From Online Compiler to CI

A browser compiler is great for the first proof. Use Hack University's Python online compiler, JavaScript playground, or C++ online compiler to run code online, then move the same solution into a repo and let GitHub Actions repeat the check on every push.

Starting pointGitHub Actions follow-up
One-file algorithmAdd a unit test job that runs the same cases on push
Small web demoAdd install, lint, and build steps before deploy
Portfolio projectUpload artifacts and keep failing logs easy to inspect

Minimal Workflow

name: Hello World

on: push

jobs:
  greet:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Hello, GitHub Actions!"

Full Skeleton

name: CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Set up Node
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Install dependencies
        run: npm ci

      - name: Run tests
        run: npm test

Workflow Anatomy

name          →  display name in the Actions UI
on            →  event(s) that trigger the workflow
env           →  workflow-level env vars (optional)
defaults      →  default shell/working-directory (optional)
jobs          →  map of job IDs → job definitions
  <job-id>:
    runs-on   →  runner label
    steps     →  ordered list of steps
      - uses  →  reference an Action
      - run   →  run shell commands

Context Objects (Quick Reference)

ContextCommon properties
github.event_name, .ref, .sha, .actor, .repository
envworkflow/job/step environment variables
varsrepo/org configuration variables
secretsencrypted secrets
runner.os, .arch, .temp
job.status
steps.<id>.outputs.<name>, .conclusion
matrixcurrent matrix values

Access via ${{ github.sha }}, ${{ secrets.MY_SECRET }}, etc.

CLI — GitHub CLI for Actions

# List workflow runs
gh run list

# Watch a run in real time
gh run watch <run-id>

# View logs
gh run view <run-id> --log

# Re-run failed jobs only
gh run rerun <run-id> --failed-only

# Manually trigger a workflow (workflow_dispatch)
gh workflow run ci.yml --ref main

# List workflows
gh workflow list

# Enable / disable a workflow
gh workflow enable ci.yml
gh workflow disable ci.yml

Permissions

Default token permissions are set at the repo or org level. Override per workflow or job:

permissions:
  contents: read
  pull-requests: write
  issues: write

Minimum-privilege: set permissions: read-all at workflow level, then grant write only where needed per job.