Skip to content

CI/CD Pipeline with GitHub Actions

Beginner ~25 min

What you'll build

A GitHub Actions workflow that runs on every push, installs dependencies, runs tests, and builds the project automatically.

Goals

  • Understand GitHub Actions workflow syntax
  • Create a workflow that triggers on push events
  • Add build and test stages to the pipeline
  • View pipeline results in the GitHub UI

Prerequisites

  • A GitHub account and a repository with a Node.js project
  • Basic understanding of YAML syntax
  • A project with `npm test` and `npm run build` scripts

Steps

  1. 1

    Create the workflow directory

    GitHub Actions workflows live in the .github/workflows/ directory. Create this directory structure in your repository.

    Code
    mkdir -p .github/workflows

    Expected result

    The .github/workflows directory exists in your project.

  2. 2

    Write the workflow file

    Create a file named ci.yml in the workflows directory. Define a workflow that triggers on push and pull request, runs on Ubuntu, checks out the code, installs dependencies, runs tests, and builds.

    Code
    name: CI
    on: [push, pull_request]
    jobs:
      build-and-test:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v3
          - uses: actions/setup-node@v3
            with:
              node-version: 18
          - run: npm ci
          - run: npm test
          - run: npm run build

    Expected result

    A workflow file exists that defines the CI pipeline.

  3. 3

    Commit and push

    Commit the workflow file and push to GitHub. GitHub will automatically detect the workflow and start running it.

    Code
    git add .github/workflows/ci.yml
    git commit -m "Add CI pipeline"
    git push

    Expected result

    The push triggers the workflow. Go to the 'Actions' tab in GitHub to see it running.

  4. 4

    Review the results

    Go to the 'Actions' tab in your GitHub repository. You should see your workflow running. Click on it to view the logs for each step.

    Expected result

    The workflow shows green checkmarks for each step, meaning build and test passed.

  5. 5

    Add a health check endpoint

    Add a /health endpoint returning 200 OK for orchestration systems (Kubernetes, load balancers) to probe liveness. Health checks are foundational for production deployment.

    Code
    # app.py (Flask example)
    from flask import Flask, jsonify
    app = Flask(__name__)
    
    @app.route("/health")
    def health():
        return jsonify({"status": "ok"}), 200
    
    @app.route("/ready")
    def ready():
        # Check DB connection etc.
        return jsonify({"ready": True}), 200

    Expected result

    curl localhost:5000/health returns {"status":"ok"} with a 200 status code.

Try it yourself

What you learned

You built a CI pipeline with GitHub Actions that automatically tests and builds your code on every push. This catches bugs early and ensures your code is always in a buildable state.

Related Resources

Related Glossary

Related Glossary

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to topic