Sub topic 13
Handling shared libraries and workflow edits
This chapter assumes you can write a change-detection job with dorny/paths-filter, expose its outputs, and gate jobs with if. If not, review those chapters first.
The problem: hidden dependencies
A path filter only knows about file locations. It does not know that services/api imports code from libs/shared. If you filter the backend job on services/api/** alone, a change to libs/shared/** skips the backend tests, and the breakage reaches main unnoticed.
The same applies to the workflow file. If you edit .github/workflows/ci.yml and no job runs, you have changed the pipeline without testing the change.
The rule: list every input
Treat each area's filter as the full list of files that can change its result. That list has three parts:
- The area's own directory.
- Every shared library or config it depends on.
- The workflow file that defines its job.
filters: |
backend:
- 'services/api/**'
- 'libs/shared/**'
- '.github/workflows/ci.yml'
frontend:
- 'apps/web/**'
- 'libs/shared/**'
- '.github/workflows/ci.yml'A change to libs/shared/** now sets both backend and frontend to 'true'. A change to ci.yml sets both too, so every job runs once to validate the edit.
Two kinds of workflow files
When the filter covers a single workflow, list that workflow's own path, as in the example above. When several workflows share one reusable workflow or composite action, list that file in every filter that uses it.
backend:
- 'services/api/**'
- 'libs/shared/**'
- '.github/workflows/ci.yml'
- '.github/workflows/reusable-test.yml'
- '.github/actions/setup/**'Diagram of the flow
Keeping the list honest
Shared dependencies drift. A new library gets imported and nobody updates the filters. Two habits help:
- Keep shared code in a small number of known directories, such as
libs/, so one pattern covers it. - Add a comment above each filter naming the dependencies it covers, and update it in the same pull request that adds an import.
If the dependency graph is complex, you can choose to over-trigger. Add a catch-all area, such as root-config for package.json, lock files, or Makefile, that sets every output to true. Extra runs cost minutes. A missed run costs a broken main.
filters: |
global: &global
- '.github/workflows/**'
- 'package-lock.json'
backend:
- *global
- 'services/api/**'
- 'libs/shared/**'
frontend:
- *global
- 'apps/web/**'
- 'libs/shared/**'The YAML anchor &global and alias *global are resolved by the action's YAML parser, so each area includes the global patterns without repeating them.
Exercise
Your frontend filter lists only apps/web/**. A pull request edits libs/shared/utils.ts, which the web app imports. What happens, and what two entries should you add to fix the filter?
Show answer
The frontend output is 'false', so frontend-test is skipped and the shared change is not tested against the web app. Add libs/shared/** and the workflow file path, such as .github/workflows/ci.yml, to the frontend filter.