: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(ci): upload storybook and frontend jest junit to trunk (#68076)
Paul D'Ambraf3268a1614e8
diff --git a/.github/workflows/ci-frontend.yml b/.github/workflows/ci-frontend.ymlindex a29fa4a0c7c8..b16015c78099 100644--- a/.github/workflows/ci-frontend.yml+++ b/.github/workflows/ci-frontend.yml@@ -649,6 +649,12 @@ jobs:SHARD_COUNT: 4MODE: ${{ needs.select-jest-tests.outputs.mode }}CHANGED_FILES: ${{ needs.select-jest-tests.outputs.changed_files }}+ JEST_JUNIT_OUTPUT_DIR: ${{ github.workspace }}/junit-results+ JEST_JUNIT_OUTPUT_NAME: junit-${{ matrix.segment }}-${{ matrix.chunk }}.xml+ # Trunk attributes flakes by test file; jest-junit's default suite name is the+ # top-level describe, which collides across files. Anchor identity to the file.+ JEST_JUNIT_SUITE_NAME: '{filepath}'+ JEST_JUNIT_ADD_FILE_ATTRIBUTE: 'true'run: |if [ "$MODE" = "selective" ]; then# --findRelatedTests walks jest's import graph from the changed@@ -673,6 +679,15 @@ jobs:bin/turbo run test --filter=@posthog/frontend -- --maxWorkers=100%fi+ - name: Upload test results+ if: always()+ uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0+ with:+ name: junit-results-frontend-${{ matrix.segment }}-${{ matrix.chunk }}+ path: junit-results/junit-*.xml+ if-no-files-found: ignore+ retention-days: 1+calculate-running-time:name: Calculate running timeneeds: [jest, frontend-typescript-checks, frontend-format, frontend-bundle-size, frontend_tests, changes]@@ -746,3 +761,45 @@ jobs:exit 1fiecho "Frontend TypeScript checks passed."++ trunk-upload:+ name: Upload test results to Trunk+ # jest shards emit and upload junit-results-frontend-* artifacts; this feeds them to+ # Trunk (flaky-test detection) once. Trusted non-pull_request events only (master push),+ # so the secret token never runs in a PR-controlled context; the uploader is a pinned+ # external action, not a local one.+ needs: [jest]+ runs-on: ubuntu-latest+ continue-on-error: true+ timeout-minutes: 10+ # != 'skipped' (not == 'success'): a failed shard still emits junit, and failing+ # results are exactly the flake signal Trunk needs. Only bail when jest never ran.+ if: always() && github.repository == 'PostHog/posthog' && github.event_name != 'pull_request' && needs.jest.result != 'skipped'+ steps:+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ with:+ fetch-depth: 1+ persist-credentials: false+ - name: Download JUnit artifacts+ uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v6.0.0+ continue-on-error: true+ with:+ path: ./junit-artifacts+ pattern: junit-results-frontend-*+ # FOSS and EE run the same test files, so a single upload would give one test id+ # both segments' outcomes and a segment-specific failure would look like a flake.+ # Upload each segment under its own Trunk variant to keep their histories distinct.+ - name: Upload FOSS results to Trunk+ uses: trunk-io/analytics-uploader@385f1ccdf345b4532dc4b6c665dd432b702b8e28 # v2.1.2+ with:+ junit-paths: junit-artifacts/**/junit-FOSS-*.xml+ org-slug: posthog-inc+ variant: FOSS+ token: ${{ secrets.TRUNK_API_TOKEN }}+ - name: Upload EE results to Trunk+ uses: trunk-io/analytics-uploader@385f1ccdf345b4532dc4b6c665dd432b702b8e28 # v2.1.2+ with:+ junit-paths: junit-artifacts/**/junit-EE-*.xml+ org-slug: posthog-inc+ variant: EE+ token: ${{ secrets.TRUNK_API_TOKEN }}diff --git a/.github/workflows/ci-storybook.yml b/.github/workflows/ci-storybook.ymlindex eb4b9b08d009..cf2c2468fa5c 100644--- a/.github/workflows/ci-storybook.yml+++ b/.github/workflows/ci-storybook.yml@@ -508,6 +508,7 @@ jobs:name: junit-results-storybook-${{ matrix.browser }}-${{ matrix.shard }}path: common/storybook/junit.xmlif-no-files-found: ignore+ retention-days: 1# Verify changed story files are stable by re-running them multiple times.# Catches flaky snapshots before they land on master.@@ -883,3 +884,46 @@ jobs:EOFecho "SELECTION_METRICS: $(echo "$RESULT" | jq -c '{mode, reason, total: .total_story_count}')"fi++ trunk-upload:+ name: Upload test results to Trunk+ # visual-regression shards already emit and upload junit-results-storybook-* artifacts;+ # this feeds them to Trunk (flaky-test detection) once. Trusted non-pull_request events+ # only (master push), so the secret token never runs in a PR-controlled context; the+ # uploader is a pinned external action, not a local one.+ needs: [visual-regression]+ runs-on: ubuntu-latest+ continue-on-error: true+ timeout-minutes: 10+ # Storybook CI is skipped on merge_group, so visual-regression won't run there;+ # != 'skipped' keeps this from spinning a runner that downloads nothing, while still+ # uploading failed-test results (the flake signal Trunk needs) on master push.+ if: always() && github.repository == 'PostHog/posthog' && github.event_name != 'pull_request' && needs.visual-regression.result != 'skipped'+ steps:+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ with:+ fetch-depth: 1+ persist-credentials: false+ - name: Download JUnit artifacts+ uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v6.0.0+ continue-on-error: true+ with:+ path: ./junit-artifacts+ pattern: junit-results-storybook-*+ # chromium and webkit run the same stories, so a single upload would give one test id+ # both browsers' outcomes and a browser-specific failure would look like a flake.+ # Upload each browser under its own Trunk variant to keep their histories distinct.+ - name: Upload chromium results to Trunk+ uses: trunk-io/analytics-uploader@385f1ccdf345b4532dc4b6c665dd432b702b8e28 # v2.1.2+ with:+ junit-paths: junit-artifacts/junit-results-storybook-chromium-*/*.xml+ org-slug: posthog-inc+ variant: chromium+ token: ${{ secrets.TRUNK_API_TOKEN }}+ - name: Upload webkit results to Trunk+ uses: trunk-io/analytics-uploader@385f1ccdf345b4532dc4b6c665dd432b702b8e28 # v2.1.2+ with:+ junit-paths: junit-artifacts/junit-results-storybook-webkit-*/*.xml+ org-slug: posthog-inc+ variant: webkit+ token: ${{ secrets.TRUNK_API_TOKEN }}diff --git a/frontend/jest.config.ts b/frontend/jest.config.tsindex bb9efe8b87bc..86824a7c4d92 100644--- a/frontend/jest.config.ts+++ b/frontend/jest.config.ts@@ -237,8 +237,8 @@ const config: Config = {// Run tests from one or more projects// projects: undefined,- // Use this configuration option to add custom reporters to Jest- // reporters: undefined,+ // Emit JUnit XML for Trunk flaky-test detection only when JEST_JUNIT_OUTPUT_DIR is set.+ reporters: process.env.JEST_JUNIT_OUTPUT_DIR ? ['default', 'jest-junit'] : ['default'],// Automatically reset mock state between every test// resetMocks: false,diff --git a/frontend/package.json b/frontend/package.jsonindex 7390b831408b..b6330b69c00f 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -324,6 +324,7 @@"jest-canvas-mock": "^2.4.0","jest-environment-jsdom": "^29.3.1","jest-image-snapshot": "^6.1.0",+ "jest-junit": "^16.0.0","kea-typegen": "3.7.1","less": "^3.12.2","lint-staged": "catalog:",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 61ba0e4766b5..02874c0f86fe 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -1309,6 +1309,9 @@ importers:jest-image-snapshot:specifier: ^6.1.0version: 6.4.0([email protected](@types/[email protected])([email protected](@swc/[email protected])(@types/[email protected])([email protected])))+ jest-junit:+ specifier: ^16.0.0+ version: 16.0.0kea-typegen:specifier: 3.7.1version: 3.7.1([email protected])diff --git a/turbo.json b/turbo.jsonindex 6b060c8d7099..6f124135f815 100644--- a/turbo.json+++ b/turbo.json@@ -64,7 +64,11 @@"REDIS_URL","NODE_OPTIONS","PERSONS_DATABASE_URL",- "PERSONS_READONLY_DATABASE_URL"+ "PERSONS_READONLY_DATABASE_URL",+ "JEST_JUNIT_OUTPUT_DIR",+ "JEST_JUNIT_OUTPUT_NAME",+ "JEST_JUNIT_SUITE_NAME",+ "JEST_JUNIT_ADD_FILE_ATTRIBUTE"]},"start": {