Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(ci): split selective Jest tests into two shards (#83282)

Paul D'Ambrae5c1dff6d9e1
diff --git a/.github/workflows/ci-frontend.yml b/.github/workflows/ci-frontend.yml
index dc4844003dbf..6ca2311a07b0 100644
--- a/.github/workflows/ci-frontend.yml
+++ b/.github/workflows/ci-frontend.yml
@@ -309,13 +309,14 @@ jobs:
exit 0
fi
- # Selective mode: single EE-tree job, no chunk sharding. The FOSS
+ # Selective mode uses two EE-tree shards because a widely imported
+ # source file can make --findRelatedTests approach a full suite. The FOSS
# structural check (ee/ removed) only matters when ee imports are
# touched; defer that to the ready-for-review full run. --findRelatedTests
# walks jest's import graph from these files and runs the matching
# *.test.* files.
echo "mode=selective" >> "$GITHUB_OUTPUT"
- echo 'matrix={"include":[{"segment":"EE","chunk":1}]}' >> "$GITHUB_OUTPUT"
+ echo 'matrix={"include":[{"segment":"EE","chunk":1,"shard_count":2},{"segment":"EE","chunk":2,"shard_count":2}]}' >> "$GITHUB_OUTPUT"
echo "should_run=true" >> "$GITHUB_OUTPUT"
echo "changed_files=$CHANGED_FILES" >> "$GITHUB_OUTPUT"
echo "Selective mode: $(echo "$CHANGED_FILES" | wc -w) frontend source files"
@@ -699,10 +700,8 @@ jobs:
jest:
runs-on: ubuntu-latest
- # Draft PRs run the selective mode as a single unsharded job over every
- # test reachable from the changed files. A PR touching a scene component
- # can pull in much of the suite, so the budget must fit a near-full
- # unsharded run; the ready-for-review fanout shards well below it.
+ # Draft PRs run two selective shards over tests reachable from changed files.
+ # The ready-for-review fanout uses four shards over the full suite.
timeout-minutes: 20
needs: [changes, select-jest-tests]
# A status function is required because select-jest-tests is skipped on ready
@@ -715,7 +714,7 @@ jobs:
strategy:
# If one test fails, still run the others
fail-fast: false
- # On draft PRs, select-jest-tests may narrow this to a single EE job
+ # On draft PRs, select-jest-tests may narrow this to two EE jobs
# running only the tests reachable from changed frontend source files,
# or skip jest entirely (should_run=false) when selection can't be
# trusted. On ready PRs and master pushes it's skipped, so
@@ -754,9 +753,7 @@ jobs:
env:
NODE_OPTIONS: --max-old-space-size=16384
SHARD_INDEX: ${{ matrix.chunk }}
- # Keep shard runtime well under timeout-minutes: at 2 shards the EE
- # suite regularly hit the job timeout and failed the whole run.
- SHARD_COUNT: 4
+ SHARD_COUNT: ${{ matrix.shard_count || 4 }}
MODE: ${{ needs.select-jest-tests.outputs.mode }}
CHANGED_FILES: ${{ needs.select-jest-tests.outputs.changed_files }}
JEST_JUNIT_OUTPUT_DIR: ${{ github.workspace }}/junit-results
@@ -768,8 +765,8 @@ jobs:
run: |
if [ "$MODE" = "selective" ]; then
# --findRelatedTests walks jest's import graph from the changed
- # source files and runs the matching tests. No --shard: single
- # job runs the entire selected set.
+ # source files and runs the matching tests. Sharding keeps broad
+ # import graphs within the job timeout.
#
# No --testPathPattern: it is mutually exclusive with
# --findRelatedTests (jest folds both into one path regex and
@@ -782,6 +779,7 @@ jobs:
pnpm --filter=@posthog/frontend exec jest \
--forceExit \
--passWithNoTests \
+ --shard=$SHARD_INDEX/$SHARD_COUNT \
--findRelatedTests $CHANGED_FILES
else
# 100% = one worker per available core. Public-repo ubuntu-latest