: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): add Trunk verdicts to Depot backend CI (#96921)
Raúl Negrón-Otero0f8a18c21d94
diff --git a/.depot/actions/trunk-quarantine-gate/action.yml b/.depot/actions/trunk-quarantine-gate/action.ymlnew file mode 100644index 000000000000..23f3efa63e2e--- /dev/null+++ b/.depot/actions/trunk-quarantine-gate/action.yml@@ -0,0 +1,79 @@+name: 'Trunk quarantine gate'+description: 'Upload a shard JUnit report to Trunk, masking known flakes, retrying once on a transient upload failure'++inputs:+ junit-paths:+ description: 'Comma-separated glob paths to the JUnit files this shard wrote'+ required: true+ previous-step-outcome:+ description: 'steps.<test step>.outcome, so Trunk can tell a failed shard from a passing one'+ required: true+ token:+ description: 'Trunk API token'+ required: true+ variant:+ description: 'Trunk variant, for suites whose shards upload under one name'+ required: false+ default: ''++runs:+ using: 'composite'+ steps:+ # Exports TRUNK_CODEOWNERS_PATH for the uploader steps below, so Trunk attributes each test+ # to the team that owns its file. Exports nothing when it cannot, which leaves the uploader+ # on .github/CODEOWNERS as before, and the script reads the reports to skip the work for a+ # suite whose reporter writes no file attribute. The existence guard covers a checkout that+ # predates the script, the way an unrebased branch does.+ - name: Build the Trunk ownership map+ shell: bash+ env:+ JUNIT_PATHS: ${{ inputs.junit-paths }}+ run: |+ script="$GITHUB_WORKSPACE/.github/scripts/trunk-codeowners.sh"+ if [ -x "$script" ]; then "$script" "$RUNNER_TEMP/trunk-codeowners" "$JUNIT_PATHS"; fi++ - name: Upload to Trunk+ id: upload+ continue-on-error: true+ uses: trunk-io/analytics-uploader@385f1ccdf345b4532dc4b6c665dd432b702b8e28 # v2.1.2+ with:+ junit-paths: ${{ inputs.junit-paths }}+ org-slug: posthog-inc+ variant: ${{ inputs.variant }}+ # Pinned rather than 'latest', which costs an extra github.com request to follow the release redirect.+ cli-version: '0.15.4'+ quarantine: true+ previous-step-outcome: ${{ inputs.previous-step-outcome }}+ token: ${{ inputs.token }}++ # Randomized because a github.com release-asset rate limit or a Trunk outage fails every+ # shard at once, and a fixed delay would retry them all in the same instant too.+ - name: Back off before retrying+ if: ${{ steps.upload.outcome == 'failure' && inputs.previous-step-outcome == 'success' }}+ shell: bash+ run: sleep $((15 + RANDOM % 46))++ # Only a shard whose tests passed: the uploader exits non-zero by design when the report has+ # failures it could not quarantine, and re-uploading those would double-count them in the+ # flake statistics that decide what gets quarantined.+ - name: Upload to Trunk (retry)+ id: upload-retry+ if: ${{ steps.upload.outcome == 'failure' && inputs.previous-step-outcome == 'success' }}+ continue-on-error: true+ uses: trunk-io/analytics-uploader@385f1ccdf345b4532dc4b6c665dd432b702b8e28 # v2.1.2+ with:+ junit-paths: ${{ inputs.junit-paths }}+ org-slug: posthog-inc+ variant: ${{ inputs.variant }}+ cli-version: '0.15.4'+ quarantine: true+ previous-step-outcome: ${{ inputs.previous-step-outcome }}+ token: ${{ inputs.token }}++ # Re-raise, so this action's own outcome still means what a bare uploader step meant and+ # callers can keep gating their verdict on `steps.<gate>.outcome == 'success'`. Without it+ # the swallowed attempts above would report success and mask every real failure.+ - name: Fail if no attempt cleared the shard+ if: ${{ steps.upload.outcome != 'success' && steps.upload-retry.outcome != 'success' }}+ shell: bash+ run: exit 1diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.ymlindex 1153c26f741f..ffdcbd029b91 100644--- a/.depot/workflows/ci-backend.yml+++ b/.depot/workflows/ci-backend.yml@@ -25,33 +25,14 @@# capture-test-selection job — turbo-discover still emits its telemetry outputs to# stay apples-to-apples, they just have no consumer here; canonical mints the# telemetry token from the GH_APP_TELEMETRY_APP_ID org variable rather than the-# secret, which the shadow has no token step to mirror. Canonical also makes that-# mint fail open, falls its consumers back to github.token, and narrows-# calculate-running-time to contents/actions read. The shadow has neither the step-# nor the job, so all three are depot-exempt),-# --store-durations write, test-selection verdict (so the guard skipping it when both-# test matrices were skipped has nothing to mirror), Trunk flaky-test quarantine-# gate (canonical runs per-shard analytics-uploader steps that post to the-# external Trunk service; the upload is best-effort and a local "Fail on test-# failure" step owns the pass/fail verdict. Canonical stages JUnit under per-product-# filenames before this upload, and can hold a product back from quarantine by naming-# its report as an exclusion. The shadow strips all of it because a non-blocking timing-# trial must not post to Trunk, and so it also omits the test-# steps' continue-on-error and that verdict step, letting each shard's test-# exit code be the verdict directly. Canonical gates each quarantine gate on the-# TRUNK_UPLOAD_ENABLED repo variable as an upload kill-switch, and its verdict step-# on TRUNK_QUARANTINE_ENABLED to decide whether known flakes are masked; since the-# shadow strips both the gate and the verdict step entirely, both variables are-# no-ops here and there is nothing to mirror. Canonical's turbo-tests gate now calls-# ./.github/actions/trunk-quarantine-gate to retry once. The shadow has no gate, so it-# does not need a mirrored action. Canonical pins Trunk CLI 0.15.4 for JUnit retry-# elements; the shadow has no uploader CLI to pin. Canonical also builds a CODEOWNERS-# projection of the owners.yaml map before each upload, so Trunk can attribute a test to-# a team; with no upload here, that step has nothing to mirror either)+# secret, which the shadow has no token step to mirror),+# --store-durations write, and test-selection verdict.+# - Trunk uploads and quarantine verdicts match canonical only when side effects+# are enabled. Disabled test steps retain their direct failure verdict.# - dynamic-ci-filter: canonical asks Trunk which jobs a diff needs and records the verdict-# in that job's log. Nothing there reads its outputs, and the shadow posts to Trunk from-# nowhere (above), so the job and its action pin are depot-exempt. Its fail-open step and-# its `no-ci` draft guard belong to that job, so they need no depot bump either.+# in that job's log. Nothing reads its outputs, so the job and its action pin are+# depot-exempt. Its fail-open step and its `no-ci` draft guard belong to that job, so+# they need no depot bump either.# - Per-test failure rollup: canonical's django_tests gate uploads product JUnit and, when a# test job fails, downloads that shard's JUnit to list the actual failing tests. The shadow# strips artifact uploads (above), so it has nothing to download and keeps the plain@@ -1008,6 +989,7 @@ jobs:turbo-tests:needs:[+ sample,changes,turbo-discover,prime-schema-cache,@@ -1186,6 +1168,8 @@ jobs:gh run download "$run_id" --repo "$GITHUB_REPOSITORY" --name test-durations --dir . \|| echo "::warning::Timing artifact of run $run_id unavailable, sharding without durations"- name: Run product tests+ continue-on-error: ${{ needs.sample.outputs.side_effects == 'true' }}+ id: run-product-tests# --force: discover already decided this product needs testing, skip turbo cache# --log-order=stream: stream pytest output live instead of buffering until completion# legs: one turbo invocation per entry, each with its own pytest-split flags@@ -1221,6 +1205,7 @@ jobs:PYTEST_ADDOPTS: >---reuse-db--durations-path ../../.test_durations+ ${{ needs.sample.outputs.side_effects == 'true' && '--junitxml=junit-product.xml' || '' }}${{ needs.detect-snapshot-mode.outputs.mode == 'update' && '--snapshot-update --snapshot-warn-unused' || '' }}${{ github.event_name == 'pull_request' && '--cov=backend --cov-report=xml:coverage.xml' || '' }}# turbo runs each product's backend:test with the product dir as CWD, so --cov=backend@@ -1278,6 +1263,33 @@ jobs:doneset -eexit $overall++ - name: Prepare product JUnit for Trunk+ id: prepare_product_junit+ if: ${{ needs.sample.outputs.side_effects == 'true' && (always()) }}+ shell: bash+ env:+ PRODUCT_FILTERS: ${{ matrix.filters }}+ run: |+ bash .github/scripts/prepare-product-junit-for-trunk.sh \+ trunk-junit \+ "$PRODUCT_FILTERS"++ - name: Quarantine gate+ id: quarantine_gate+ continue-on-error: true+ if: ${{ needs.sample.outputs.side_effects == 'true' && (!cancelled() && env.RUNS_ON_INTERNAL_PR == 'true' && github.repository == 'PostHog/posthog' && github.actor != 'dependabot[bot]' && vars.TRUNK_UPLOAD_ENABLED == 'true') }}+ uses: ./.github/actions/trunk-quarantine-gate+ with:+ junit-paths: trunk-junit/junit-product-*.xml+ previous-step-outcome: ${{ steps.run-product-tests.outcome }}+ token: ${{ secrets.TRUNK_API_TOKEN }}++ - name: Fail on test failure+ if: ${{ needs.sample.outputs.side_effects == 'true' && (!cancelled() && (steps.prepare_product_junit.outcome == 'failure' || (steps.run-product-tests.outcome == 'failure' && (vars.TRUNK_QUARANTINE_ENABLED != 'true' || steps.quarantine_gate.outcome != 'success')))) }}+ shell: bash+ run: exit 1+# Lightweight repo-wide checks that only need Python + uv (no Docker/DB).# Consolidates checks that previously each spun up their own runner.repo-checks:@@ -2094,7 +2106,7 @@ jobs:echo "include=$include" >> "$GITHUB_OUTPUT"echo "Django matrix size: $(jq -r 'length' <<< "$include") (mode=$MODE)"django:- needs: [changes, turbo-discover, detect-snapshot-mode, get_clickhouse_versions, build_django_matrix]+ needs: [sample, changes, turbo-discover, detect-snapshot-mode, get_clickhouse_versions, build_django_matrix]# Run legacy pytest if:# 1. Legacy code directly changed (ee/, posthog/)# 2. OR product changes affect legacy code (turbo-discover outputs run_legacy=true)@@ -2472,6 +2484,7 @@ jobs:docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" || trueecho "==================================="- name: Run Core tests+ continue-on-error: ${{ needs.sample.outputs.side_effects == 'true' }}id: run-core-testsif: ${{ needs.changes.outputs.backend == 'true' && matrix.segment == 'Core' }}env:@@ -2618,6 +2631,7 @@ jobs:docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" || trueecho "==================================="- name: Run Temporal tests+ continue-on-error: ${{ needs.sample.outputs.side_effects == 'true' }}id: run-temporal-testsif: ${{ needs.changes.outputs.backend == 'true' && matrix.segment == 'Temporal' }}shell: 'signal-fanout bash --noprofile --norc -eo pipefail {0}'@@ -2717,6 +2731,49 @@ jobs:if: failure() && (needs.changes.outputs.backend == 'true' && steps.run-core-tests.outcome != 'failure' && steps.run-temporal-tests.outcome != 'failure')shell: bashrun: docker compose -f docker-compose.dev.yml logs++ # Exports TRUNK_CODEOWNERS_PATH for the uploads below, so Trunk attributes each test to+ # the team that owns its file. The guard is for an unrebased branch: this job checks out+ # the PR head ref, which may predate the script. Without it the uploader keeps reading+ # .github/CODEOWNERS, as it did before.+ - name: Build the Trunk ownership map+ if: ${{ needs.sample.outputs.side_effects == 'true' && (!cancelled() && needs.changes.outputs.backend == 'true' && env.RUNS_ON_INTERNAL_PR == 'true' && github.repository == 'PostHog/posthog' && github.actor != 'dependabot[bot]' && vars.TRUNK_UPLOAD_ENABLED == 'true') }}+ shell: bash+ run: |+ script=.github/scripts/trunk-codeowners.sh+ if [ -x "$script" ]; then "$script" "$RUNNER_TEMP/trunk-codeowners" "junit-*.xml"; fi++ - name: Quarantine gate (Core)+ id: quarantine_gate_core+ continue-on-error: true+ if: ${{ needs.sample.outputs.side_effects == 'true' && (!cancelled() && matrix.segment == 'Core' && needs.changes.outputs.backend == 'true' && env.RUNS_ON_INTERNAL_PR == 'true' && github.repository == 'PostHog/posthog' && github.actor != 'dependabot[bot]' && vars.TRUNK_UPLOAD_ENABLED == 'true') }}+ uses: trunk-io/analytics-uploader@385f1ccdf345b4532dc4b6c665dd432b702b8e28 # v2.1.2+ with:+ junit-paths: junit-core.xml,junit-core-retry-failures.xml+ org-slug: posthog-inc+ cli-version: '0.15.4'+ quarantine: true+ previous-step-outcome: ${{ steps.run-core-tests.outcome }}+ token: ${{ secrets.TRUNK_API_TOKEN }}++ - name: Quarantine gate (Temporal)+ id: quarantine_gate_temporal+ continue-on-error: true+ if: ${{ needs.sample.outputs.side_effects == 'true' && (!cancelled() && matrix.segment == 'Temporal' && needs.changes.outputs.backend == 'true' && env.RUNS_ON_INTERNAL_PR == 'true' && github.repository == 'PostHog/posthog' && github.actor != 'dependabot[bot]' && vars.TRUNK_UPLOAD_ENABLED == 'true') }}+ uses: trunk-io/analytics-uploader@385f1ccdf345b4532dc4b6c665dd432b702b8e28 # v2.1.2+ with:+ junit-paths: junit-temporal.xml,junit-temporal-retry-failures.xml+ org-slug: posthog-inc+ cli-version: '0.15.4'+ quarantine: true+ previous-step-outcome: ${{ steps.run-temporal-tests.outcome }}+ token: ${{ secrets.TRUNK_API_TOKEN }}++ - name: Fail on test failure+ if: ${{ needs.sample.outputs.side_effects == 'true' && (!cancelled() && ((steps.run-core-tests.outcome == 'failure' && (vars.TRUNK_QUARANTINE_ENABLED != 'true' || steps.quarantine_gate_core.outcome != 'success')) || (steps.run-temporal-tests.outcome == 'failure' && (vars.TRUNK_QUARANTINE_ENABLED != 'true' || steps.quarantine_gate_temporal.outcome != 'success')))) }}+ shell: bash+ run: exit 1+# Read ClickHouse versions for the compat test matrix.get_clickhouse_versions:name: Get ClickHouse versionsdiff --git a/.github/actions/trunk-quarantine-gate/action.yml b/.github/actions/trunk-quarantine-gate/action.ymlindex 2afa2219c449..23f3efa63e2e 100644--- a/.github/actions/trunk-quarantine-gate/action.yml+++ b/.github/actions/trunk-quarantine-gate/action.yml@@ -29,7 +29,7 @@ runs:env:JUNIT_PATHS: ${{ inputs.junit-paths }}run: |- script="${{ github.action_path }}/../../scripts/trunk-codeowners.sh"+ script="$GITHUB_WORKSPACE/.github/scripts/trunk-codeowners.sh"if [ -x "$script" ]; then "$script" "$RUNNER_TEMP/trunk-codeowners" "$JUNIT_PATHS"; fi- name: Upload to Trunk