This is an alpha, sneak peek of Monorepo Maestros. For this iteration, I'm getting all of my thoughts down. In the future, we'll have better information architecture, graphics, and other awesomeness. Your feedback is welcome!

GitHub Actions

Creating checks in GitHub Actions ensures that our repository maintains its health through constant development. All of the developers in the repository will need to follow the guardrails that we have codified into our checks, making our entire monorepo predictable, safe, and a joy to work in at any scale.

Rather than rewrite the excellent instructions from the Turborepo documentation, we encourage you to visit their guide to learn how to set up turbo to run checks in your repository.

Below, we will talk about a few techniques of GitHub Actions that we use in the Maestros repository that you can leverage.

Running a GitHub action for trunk-based deployments

As mentioned on our CI/CD introduction page, our goal is to always be merging our pull requests to the main branch. To make sure the checks that we've written run when we put up a pull request under these conditions, we need to write this rule into the top of our GitHub Action:

.github/workflows.quality.yml
name: Quality

on:
push:
branches: ['main']
pull_request:
types: [opened, synchronize]

jobs:
.github/workflows.quality.yml
name: Quality

on:
push:
branches: ['main']
pull_request:
types: [opened, synchronize]

jobs:

The on block informs GitHub to run the Action whenever a pull_request is opened or updated (synchronize) to the branches in the provided array (in our case, main). Our developers will now be informed about any code that doesn't follow the conventions established in our codebase.

Creating a uniform installation action

The jobs in the GitHub Actions of a monorepo often need to go through similar setup steps. We can create a common setup step to reduce boilerplate and keep things more simple. Let's learn about this by taking a look at the setup steps for the Actions in this repo:

./tooling/github-actions/setup/action.yml
name: 'Setup and install'
description: 'Common setup steps for Actions'

runs:
using: composite
steps:
- uses: actions/setup-node@v3
with:
node-version: 18

- uses: actions/checkout@v3

- shell: bash
run: npm i -g pnpm turbo

- shell: bash
run: pnpm install
./tooling/github-actions/setup/action.yml
name: 'Setup and install'
description: 'Common setup steps for Actions'

runs:
using: composite
steps:
- uses: actions/setup-node@v3
with:
node-version: 18

- uses: actions/checkout@v3

- shell: bash
run: npm i -g pnpm turbo

- shell: bash
run: pnpm install

A few key details to keep in mind when reading this file are:

Canceling stale jobs

If you're pushing updates to your branch faster than your checks are completing, you'll end up kicking off many Actions than you need. It would be great if Actions that are running on stale code could be cancelled...

Well, we can do exactly that!

./.github/workflows/quality.yml
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
./.github/workflows/quality.yml
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

This block of code tells a GitHub Action to cancel any workflows that are:

  1. Named the same as the current workflow
  2. Have the same branch name as the current workflow

We will not only ever have one active Action that is checking, for example, our formatting, no matter how many times we push new code to your pull request.