AI Hints
Home›CI/CD with GitHub Actions Tutorial›Privilege, Runners, and Monorepos
CI/CD with GitHub Actions · Lesson 111 of 138

Monorepos

Many projects, one repo.

⏱ 2 min read▶ Video at 2:09:26🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

A monorepo holds many projects in one repository. An API, a website, shared libraries. Running every pipeline on every change would be slow and wasteful. Path filters let each project run only when its own files change.

Monorepos
From the video: Monorepos
  • Many projects, one repo
  • Don't run everything
  • Filter by path

One workflow per project

The API workflow runs only when something under services slash API changes. The web workflow has the same shape, for services slash web. Each team gets fast, focused feedback.

.github/workflows/api.ymlyaml
name: API
on:
  push:
    paths: ["services/api/**"]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Testing the API"

Only what changed

The last commit only changed the website. Our helper checks both workflows against that commit. The API workflow isn't triggered, because no API files changed. The web workflow runs.

Terminal
git show --stat --format=%s HEAD | grep -v "^$" | head -2
Update the website
 services/web/index.html | 1 +
run-steps .github/workflows/api.yml
Workflow: API  (event: push, branch: main)
  Not triggered: no changed file matches paths
    changed: services/web/index.html
run-steps .github/workflows/web.yml | grep -E "✓|Testing"
  ✓ Run echo "Testing the website"
      Testing the website

Shared code in a monorepo

Projects often share code, like a common library. If the library changes, every project that uses it should be tested. So add the library's folder to each project's paths. For bigger monorepos, tools like the paths filter action, or build tools like Nx and Bazel, work out exactly what's affected.

keyvalue
Shared libraryadd its path to each
paths-filterdecide inside a job
Nx, Bazel, Turborepoaffected projects only
Root filesmay trigger everything

Summary

Path filters keep monorepo pipelines fast, by running only what changed. Shared code may need to trigger several workflows. Next, debugging workflows.

Key takeaways
  • paths: per project
  • Fast, focused feedback
  • Shared code triggers more
Next up: Debugging Workflows — when CI is confusing