Skip to content

Instantly share code, notes, and snippets.

@ciiqr
Created April 16, 2022 05:06
Show Gist options
  • Save ciiqr/6f32ea7b7d50f52163e2a871692ff2b4 to your computer and use it in GitHub Desktop.
Save ciiqr/6f32ea7b7d50f52163e2a871692ff2b4 to your computer and use it in GitHub Desktop.
Github actions matrix build for all packages in a monorepo

assumes a file structure something like:

├── package.json
└── packages
    ├── foo
    │   ├── package.json
    │   └── ...
    └── bar
        ├── package.json
        └── ...
name: build
on:
push:
branches:
- main
jobs:
matrix:
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.set_packages.outputs.packages }}
steps:
- uses: actions/checkout@v2
- id: set_packages
run: |
echo "::set-output name=packages::$(
find packages -mindepth 1 -maxdepth 1 -exec basename '{}' ';' \
| jq --compact-output --raw-input -n '[inputs]'
)"
build:
name: Build ${{ matrix.package }}
runs-on: ubuntu-latest
needs: matrix
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.matrix.outputs.packages) }}
defaults:
run:
working-directory: ./packages/${{ matrix.package }}
steps:
- uses: actions/checkout@v2
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: "16"
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment