Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Coverage

on:
pull_request:
branches:
- main
Comment on lines +4 to +6
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand this correctly, it will only run on pull requests that target main?
Does it need to be run on all pull requests instead?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is correct, you don't need to run it for a PR into something other than main... at some point you'll want that in main and then it will trigger (as in for this PR itself)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How long does it take to run? If not long, can just add to all PRs.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But 1) why? you can do whatever you want in your branch, I'm only interested at the point of merging to main; and 2) we could do it for all PRs, but we'd need to change the script to make it meaningful, which currently runs coverage on your change and then checks out main specifically to get a baseline coverage.


jobs:
coverage:
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for turbo diff

- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 10

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
cache: "pnpm"
cache-dependency-path: "**/pnpm-lock.yaml"

- name: Install dependencies
run: pnpm install --frozen-lockfile

# --- PR coverage (affected only) ---
- name: Run PR coverage
# the filter means 'projects changed since origin/main, inc dependents'
run: pnpm turbo coverage --filter=...[origin/main] --force --no-daemon

- name: Save PR coverage
run: |
mkdir pr-coverage
find . -name coverage-summary.json | while read file; do
project=$(dirname "$(dirname "$file")")
project=$(basename "$project")
cp "$file" "pr-coverage/$project.json"
done

- name: Capture PR ref
run: echo "PR_REF=${{ github.head_ref }}" >> $GITHUB_ENV

# --- baseline coverage ---
- name: Checkout main
run: git checkout origin/main

- name: Install dependencies (main)
run: pnpm install --frozen-lockfile

- name: Run coverage (main affected)
# notice both times we --force turbo to ignore cache and execute tasks fresh
run: pnpm turbo coverage --filter=...[origin/$PR_REF] --force --no-daemon

- name: Save coverage (main affected)
run: |
mkdir base-coverage
find . -name coverage-summary.json | while read file; do
project=$(dirname "$(dirname "$file")")
project=$(basename "$project")
cp "$file" "base-coverage/$project.json"
done

# --- compare ---
- name: Compare coverage
# the script errors (exit code 1), causing this action to fail,
# if regression for any app or package is detected
run: node scripts/compare-coverage.mjs pr-coverage base-coverage
Loading