πŸ† CI/CD Learning Roadmap (GitHub Actions)

βš™οΈ Core Concepts Before Starting


πŸ”Ή Stage 1: Hello World (Basics)

πŸ‘‰ Goal: Understand how workflows run.

πŸ“Œ Workflow: .github/workflows/01-hello.yml

name: Hello World CI   # Workflow name (shown in Actions tab)

on:
  push:                # Trigger event
    branches: [ "main" ]

jobs:
  hello:               # Job ID
    runs-on: ubuntu-latest   # Runner machine
    steps:
      - name: Checkout repo
        uses: actions/checkout@v3   # Action to fetch code

      - name: Print message
        run: echo "πŸš€ Hello CI/CD World!"   # Run shell command

βœ… Push β†’ check Actions tab β†’ see logs.


πŸ”Ή Stage 2: Run Jobs (Node.js or Python)

πŸ‘‰ Goal: Run scripts/tests.

πŸ“Œ Workflow: .github/workflows/02-tests.yml

name: Run Tests

on: [push]    # Short syntax (same as "on: push")

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18    # Specify Node.js version

      - run: npm install
      - run: npm run test

βœ… Add a simple npm run test script in package.json.


πŸ”Ή Stage 3: Matrix Builds

πŸ‘‰ Goal: Test across multiple versions.

πŸ“Œ .github/workflows/03-matrix.yml

name: Matrix Build

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:              # Define test matrix
      matrix:
        node: [18, 20] # Node.js versions
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node }}
      - run: npm install
      - run: npm run test

βœ… Runs tests on Node.js 16, 18, 20 simultaneously.


πŸ”Ή Stage 4: Lint + Test + Build (Pipeline Stages)

πŸ‘‰ Goal: Create real CI pipeline.

πŸ“Œ .github/workflows/04-pipeline.yml

name: CI Pipeline

on: [push]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: npm install
      - run: npm run lint

  test:
    runs-on: ubuntu-latest
    needs: lint     # Run only after lint succeeds
    steps:
      - uses: actions/checkout@v3
      - run: npm install
      - run: npm run test

  build:
    runs-on: ubuntu-latest
    needs: test     # Run only after test succeeds
    steps:
      - uses: actions/checkout@v3
      - run: npm install
      - run: npm run build

βœ… Enforces Lint β†’ Test β†’ Build order.


πŸ”Ή Stage 5: Cache Dependencies

πŸ‘‰ Goal: Optimize workflow speed.

πŸ“Œ .github/workflows/05-cache.yml

name: CI with Cache

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Cache node_modules
        uses: actions/cache@v3
        with:
          path: node_modules
          key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-

      - run: npm install
      - run: npm run test

βœ… Dependencies won’t reinstall every time.


πŸ”Ή Stage 6: Deploy (GitHub Pages Example)

πŸ‘‰ Goal: Continuous Deployment.

πŸ“Œ .github/workflows/06-deploy.yml

name: Deploy to GitHub Pages

on:
  push:
    branches: [ "main" ]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18
      - run: npm install
      - run: npm run build
      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./dist

βœ… Every push β†’ deploys site to GitHub Pages.


🎯 Your Mastery Checklist


⚑ Once you complete all 6 stages, you’ll fully master GitHub Actions CI/CD basics + deployment.