Day 1 of 5

GitHub Actions Basics

GitHub Actions runs automated workflows on push, pull request, or schedule. Each workflow is a YAML file in .github/workflows/. Today you will write your first workflow and understand jobs, steps, and runners.

yaml
# .github/workflows/hello.yml
name: Hello World

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

jobs:
  greet:
    runs-on: ubuntu-latest

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

      - name: Print greeting
        run: echo "Hello from GitHub Actions!"

      - name: Show runner info
        run: |
          echo "OS: $RUNNER_OS"
          echo "Workspace: $GITHUB_WORKSPACE"
          node --version
          python3 --version
yaml
# Matrix build — test on multiple Node versions
jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18, 20, 22]

    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
      - run: npm ci
      - run: npm test
Tip: The on key controls triggers. Use workflow_dispatch to add a manual run button in the GitHub UI.

Exercise: Write Your First Workflow

  1. Create a Node.js repo with a package.json
  2. Add .github/workflows/ci.yml
  3. Configure triggers: push to main and all PRs
  4. Add steps: checkout, setup-node, npm ci, npm test
  5. Push and watch the workflow run in the Actions tab

Day 1 Summary

Finished this lesson?