Conditional Tasks for Files

Conditionally run tasks when certain files change

Your repository may be set up as a monorepo, as your team makes changes to packages within it specific tasks may not need to run as part of the pipeline. Leading to slower build times and more importantly wasted build resources.

The "when:" property supports a "paths:" property. It accepts an array of glob file patterns. Sail CI looks at the diff of files changed since the last successful build pushed, if any files match a declared glob pattern the task will be run. In the event of no match we do not run the task.

Example Project Structure

packages/package-1/index.js
packages/package-2/index.js
README.md

.sail.yml

tasks:
build-package-1:
image: sailci/demo
when:
paths:
- "packages/package-1/**/*"
build-package-2:
image: sailci/demo
when:
paths:
- "packages/package-2/**/*"
deploy:
image: sailci/demo
when: \/heads\/master$

In the example, any files that change within "package-1" will cause the "build-package-1" task to run. The same rules apply to package-2 in that only if team members edit any files within package-2 the "build-package-2" task runs.

As you can see from the example, it offers teams an incredibly effective way of working within a monorepo. No more waiting for unnecessary changes to build.

Note: You can also combine both the "paths:" and "ref:" property to allow conditionals for both running tasks on a specific branch and when particular files change.

tasks:
my-task:
image: sailci/demo
when:
ref: \/heads\/master$
paths:
- "packages/package-2/**/*"

Workflows

The "when:" property is also supported and can be declared on individual workflow task items.

tasks:
my-task:
image: sailci/demo
workflow:
- my-task:
when:
ref: \/heads\/master$
paths:
- "packages/package-2/**/*"