GitHub Actions

Continuous Integration with GitHub Actions

Project Status Meeting 1

Overview

In this lesson, we’ll design a GitHub Actions CI/CD pipeline for our Node.js application. We’ll begin by mapping out all nine tasks, then dive into the first four:

  1. Analyze the Node.js codebase
  2. Define DevOps requirements
  3. Identify dependencies and environment variables
  4. Draft the workflow YAML structure

Once the groundwork is set, we’ll implement jobs for:

  • Unit testing
  • Code coverage
  • Containerization

Let’s get started!

Roadmap: All Nine Tasks

TaskDescription
1Analyze the Node.js codebase
2Define DevOps requirements (environments, secrets)
3Inventory dependencies and environment variables
4Draft initial workflow YAML structure
5Add unit-test job using Jest
6Integrate code-coverage reporting
7Build and push Docker image
8Deploy to staging environment
9Configure notifications and post-build checks

Note

Before proceeding, ensure you have:

  • Node.js (v16+) installed
  • A GitHub repository with your Node.js project
  • Basic familiarity with YAML syntax

1. Analyze the Node.js Codebase

Start by exploring your application’s entry point (index.js or app.js) and folder structure:

.
├── src/
│   ├── index.js     # Application entry
│   ├── routes/      # Express routes
│   └── controllers/ # Route handlers
├── tests/
│   └── app.test.js  # Jest test file
├── package.json
└── Dockerfile
  • Verify test coverage tools (e.g., Jest).
  • Confirm environment variable usage (dotenv, process.env).

2. Define DevOps Requirements

Document your CI/CD goals:

  • Which Node.js versions to test?
  • Required environment variables (e.g., DATABASE_URL, API_KEY).
  • Build matrix (operating systems, Node versions).

Use a .github/workflows/ci.yml stub:

name: CI Pipeline

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

3. Inventory Dependencies & Environments

List all production and dev dependencies from package.json:

{
  "dependencies": {
    "express": "^4.17.1",
    "dotenv": "^10.0.0"
  },
  "devDependencies": {
    "jest": "^29.0.0",
    "supertest": "^6.1.3"
  }
}

Confirm:

  • Lockfile (package-lock.json or yarn.lock) is checked in.
  • Secrets are added to GitHub under Settings > Secrets and variables > Actions.

4. Draft Initial Workflow Structure

Define job placeholders:

jobs:
  analyze:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

  setup:
    runs-on: ubuntu-latest
    needs: analyze

  unit-test:
    runs-on: ubuntu-latest
    needs: setup

  build:
    runs-on: ubuntu-latest
    needs: unit-test

Next steps:

  1. Install Node.js and cache dependencies.
  2. Run tests with coverage.
  3. Build Docker image.

Warning

Always pin action versions (e.g., actions/checkout@v3) to avoid unexpected breaking changes.


Next Up

In the upcoming session, we’ll:

  1. Configure Node.js setup and caching
  2. Add the unit-test job using Jest
  3. Generate and upload code coverage reports

Watch Video

Watch video content

Previous
Cancelling and Skipping Workflows