Monorepo or yarnWorkspaces support? #260
-
Is it possible to use this Github action with a monorepo or yarn workspaces setup? For example if I have two following folders in a monorepo
Both of this using Jest, but in apps folder there could be Nextjs/express etc applications, and in packages folder there could be shared helpers/utilities and shared React components, so each app or packages can have separate Jest config/setup. Wondering if there is a way to use this github action to get coverage posted to a PR. Guessing if I manually add one entry per app/package it might be possible, but wondering if there could be a way to pull in |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hello @marexandre 👋, Yes, it is possible to run this action on yarn workspaces setup. You can simply run action for each package separately: name: CI
on:
pull_request:
branches: [main]
jobs:
coverage:
name: Coverage report
runs-on: ubuntu-latest
strategy:
matrix:
path:
- ./packages/first
- ./packages/second
- ./apps/main
- ./apps/other
steps:
- uses: actions/checkout@v1
- name: Use Node 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Install npm 17.x
run: npm i -g npm@latest
- name: Installing dependencies
run: npm install
- uses: artiomtr/jest-coverage-report-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
skip-step: install
working-directory: ${{ matrix.path }}
test-script: yarn jest But, this will require adding dependencies manually. So I recommend checking out get-changed-workspaces action. This action will help you to run actions only for changed packages. For instance, this is the configuration for one of my projects: name: CI
on:
pull_request:
branches: [main]
workflow_dispatch:
jobs:
generate_matrix:
name: Get changed packages
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
outputs:
names: ${{ steps.changed_packages.outputs.names }}
paths: ${{ steps.changed_packages.outputs.paths }}
empty: ${{ steps.changed_packages.outputs.empty }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Find changed packages
id: changed_packages
uses: alexshukel/[email protected]
coverage:
name: Coverage report
if: ${{ !fromJson(needs.generate_matrix.outputs.empty) }}
needs: [generate_matrix]
runs-on: ubuntu-latest
strategy:
matrix:
path: ${{ fromJson(needs.generate_matrix.outputs.paths) }}
steps:
- uses: actions/checkout@v1
- name: Use Node 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Install npm 17.x
run: npm i -g npm@latest
- name: Installing dependencies
run: npm install
- uses: artiomtr/jest-coverage-report-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
skip-step: install
working-directory: ${{ matrix.path }}
test-script: npm run test:coverage # change to your test script |
Beta Was this translation helpful? Give feedback.
-
@ArtiomTr thank you for the reply and example code! In this couple of days I've prototyped with a custom script/setup to get only workspaces that have changes, and got it working with a test monorepo for the most part, but the whole setup felt a bit too much and complex, didn't have time to fully refactor/cleanup 🙈 |
Beta Was this translation helpful? Give feedback.
Hello @marexandre 👋,
Yes, it is possible to run this action on yarn workspaces setup. You can simply run action for each package separately: