#How to run exec, but only if files have changed?

1 messages · Page 1 of 1 (latest)

vocal cloud
#

Let's say I have a monorepo workspace with multiple packages.

I want to build each package independently, and then traverse the dependency tree and build the children of the package.

However, I want to target the exec in such a way that it only runs if the package files have changed.

E.g. run pnpm build inside packages/foo but only if files in packages/foo/* have changed and then cache that layer.

Then I would use this layer and run build in the package bar that uses foo and again, only if the files in bar have changed, otherwise reuse cache.

Effectively, what I am trying to say is how to compute a layer cache key based on some pattern of globs, similar to how turborepo does it.

Thanks!

timid parcel
vocal cloud
#

Hi @timid parcel thanks again for jumping in. I read the posts you have linked, but didn't find the answer I was looking for. 😀

timid parcel
#

Ah

#

Sorry if I misunderstood

#

Re-reading, looks like you should be able to achieve what you want by filtering the contents of the directory before passing them to withExec

#

But, if you follow best practices (ie. keep your inputs miminal, only give a function what it needs to build, filter out unnecessary files to avoid cache misses), then I think Dagger already gives you what you want

vocal cloud
#

OK, thanks, i'll try.

As for 'best practices', I still haven't figured those out, just tinkering 🙂

#

The idea was like this:

Step 1: build a base container, which has the npm deps installed
Step 2: resolve the pnpm dep graph
Step 3: build the graph one package at a time, from root to leafs, caching each package unless files in it have changed (and root lock)