Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monorepo, Travis and Matrix builds: How do I build a specific path only when it changes?

Tags:

I have a single repo with several (java/gradle) projects:

project-a/
project-b/
project-c/

I would like to create a matrix build configuration, with one build per project. And I only want to build that project if there have been changes to it.

Is this possible?

I can easily create a script that checks if a folder has been affected by using $TRAVIS_COMMIT_RANGE. But how would I use this in .travis.yml?

EDIT

There's an issue in Travis for adding support for include/exclude paths for when to trigger builds. With matrix support, this would solve my issue.

like image 547
neu242 Avatar asked Sep 20 '16 14:09

neu242


People also ask

How to conditionally run certain stages of a monorepo pipeline?

You can use the " when " block combined with the built in "changeset" condition to conditionally run only certain stages of your monorepo's pipeline. From the when.changeset documentation: changeset- Executes the stage if the build’s SCM changeset contains one or more files matching the given string or glob.

Does a monorepo bring more benefits than drawbacks to a project?

Whether a monorepo brings more benefits than drawbacks to a project depends strongly on the project’s structure and organization. Simple rule-of-thumbs are One repo per team or Release it together, keep it together.

Should I migrate my multirepo to a monorepo?

If you migrate your multirepo to a monorepo, or if your project is getting big enough to consider running only part of continuous integration (CI) - then it can make sense to run only those parts of CI that could have been affected by the change.

What are the best practices of monorepo development?

Based on the collection of monorepo stories, we can define a set of best practices: Define a unified directory organization for easy discovery. Maintain branch hygiene. Keep branches small, consider adopting trunk-based development. Use pinned dependencies for every project.


1 Answers

You essentially ask about a conditional build in one form or another. Unfortunately the documentation about conditional builds states that

Jobs created via matrix expansion currently cannot have conditions.

... and even if it supported that, I don't see any easy way to check for a commit path in the list of supported conditions.

Nonetheless it is possible to achieve that process with their API. You can create a build configuration which aims to just run your script, and check which subproject needs to be built now. This meta build script can trigger a travis build via the API. On that doc page you can find an example of how to trigger a particular job from your matrix.

like image 103
battlmonstr Avatar answered Oct 12 '22 00:10

battlmonstr