It's not a Monorepo
If you only have apps, then I'm sorry... but all you have is a repo of many apps.
A monorepo is a collection of packages that you can map a graph of dependencies between.
Aha, I have a monorepo
But if you have a collection of packges which depend on each other, then read on.
apps/
one/
depends:
pkg/foo
two/
depends:
pkg/bar
pkg/foo
pkg/
foo/
bar/
baz/
The answer is that you switch to a tool that can describe which packages have changed between the current git ref and some other git ref.
The following two examples runs the release
npm script on each package that changed under apps/*
and all the packges they would depend on.
I'm unsure if the pnpm method silently skips packages that don't have a release
target/command/script.
Use NX Dev
Using NX.dev, it will work it out for you with its nx affected
command.
- you need a
nx.json
in the root of your monorepo
- it assumes you're using the package.json approach with nx.dev, if you have
project.json
in each package, then the target
would reside there.
- your CI would then look like:
pnpx nx affected --target=release
Pnpm Filtering
Your other option is to switch to pnpm and use its filtering syntax:
pnpm --filter "...{apps/**}[origin/master]" release
Naive Path Filtering
If you just try and rely on "which paths" changed in this git commit, then you miss out on transient changes that affect the packages you actually want to deploy.
If you have a github action like:
on:
push:
paths:
- 'app/**'
Then you won't ever get any builds for when you only push commits that change anything in pkg/**
.
Other interesting github actions