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): set up Trunk Dynamic CI in learning mode (#101929)

Georges-Antoine Assi32c63251ce07
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.yml
index ef424f8439d5..1309d94cb085 100644
--- a/.depot/workflows/ci-backend.yml
+++ b/.depot/workflows/ci-backend.yml
@@ -46,6 +46,10 @@
# 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)
+# - 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.
# - 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
diff --git a/.github/scripts/test_report_test_timings.py b/.github/scripts/test_report_test_timings.py
index 887b9af26794..0834ea8a5987 100644
--- a/.github/scripts/test_report_test_timings.py
+++ b/.github/scripts/test_report_test_timings.py
@@ -1,5 +1,6 @@
from __future__ import annotations
+import os
import re
import sys
import json
@@ -44,13 +45,20 @@ def test_full_jest_fixture_renders_single_browser_report(tmp_path: Path) -> None
fixture = SCRIPT_PATH.parent / "fixtures/jest-timings-real-run"
output = tmp_path / "jest-test-speed-report.html"
- subprocess.run(
+ # The fixture holds the artifacts of a single attempt. Above attempt 1 the reporter keeps
+ # only `-attempt<N>` artifacts, finds none, and writes no timings file, so the run attempt
+ # of the job that runs this test must not reach it. Fork pull requests always run as
+ # attempt 2, because their attempt 1 concludes action_required while it waits for approval.
+ result = subprocess.run(
[REPO_ROOT / "bin/report-jest-timings", "--artifacts", fixture, "--html", output],
- check=True,
+ check=False,
capture_output=True,
text=True,
+ env={**os.environ, "GITHUB_RUN_ATTEMPT": "1"},
)
+ assert result.returncode == 0, result.stderr
+
html = output.read_text()
match = re.search(r"const tests=(.*), summary=", html)
assert match is not None
diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.yml
index 2b855f1f3594..be76f50d58a9 100644
--- a/.github/workflows/ci-backend.yml
+++ b/.github/workflows/ci-backend.yml
@@ -98,6 +98,29 @@ permissions:
pull-requests: write
jobs:
+ # Learning mode: nothing reads these outputs, so a recommendation cannot change what runs.
+ # Fork and Dependabot runs get no secret; the queue always runs everything anyway.
+ # The step fails open, because this telemetry must not turn a passing workflow red.
+ dynamic-ci-filter:
+ name: Trunk Dynamic CI (Learning Mode)
+ if: >-
+ github.event_name == 'pull_request' &&
+ github.repository == 'PostHog/posthog' &&
+ github.event.pull_request.head.repo.full_name == github.repository &&
+ github.actor != 'dependabot[bot]' &&
+ !startsWith(github.head_ref, 'trunk-merge/') &&
+ (github.event.pull_request.draft != true ||
+ !contains(github.event.pull_request.labels.*.name, 'no-ci'))
+ runs-on: ubuntu-24.04
+ timeout-minutes: 5
+ permissions: {}
+ steps:
+ - name: Ask Trunk which jobs this diff needs
+ continue-on-error: true
+ uses: trunk-io/dynamic-ci@7e3af9331e8ebdfe0c71ba7d0ff6b7424dde8c57 # v1
+ with:
+ token: ${{ secrets.TRUNK_API_TOKEN }}
+
# Job to decide if we should run backend ci
# See .github/actions/paths-filter/README.md for filter semantics
changes:
diff --git a/.github/workflows/ci-dagster.yml b/.github/workflows/ci-dagster.yml
index 124a945612a8..947f4683fbe6 100644
--- a/.github/workflows/ci-dagster.yml
+++ b/.github/workflows/ci-dagster.yml
@@ -49,6 +49,27 @@ env:
OIDC_RSA_PRIVATE_KEY: ${{ vars.OIDC_RSA_FAKE_PRIVATE_KEY }}
jobs:
+ # Learning mode: nothing reads these outputs, so a recommendation cannot change what runs.
+ # Fork and Dependabot runs get no secret; the queue always runs everything anyway.
+ # The step fails open, because this telemetry must not turn a passing workflow red.
+ dynamic-ci-filter:
+ name: Trunk Dynamic CI (Learning Mode)
+ if: >-
+ github.event_name == 'pull_request' &&
+ github.repository == 'PostHog/posthog' &&
+ github.event.pull_request.head.repo.full_name == github.repository &&
+ github.actor != 'dependabot[bot]' &&
+ !startsWith(github.head_ref, 'trunk-merge/')
+ runs-on: ubuntu-24.04
+ timeout-minutes: 5
+ permissions: {}
+ steps:
+ - name: Ask Trunk which jobs this diff needs
+ continue-on-error: true
+ uses: trunk-io/dynamic-ci@7e3af9331e8ebdfe0c71ba7d0ff6b7424dde8c57 # v1
+ with:
+ token: ${{ secrets.TRUNK_API_TOKEN }}
+
# Verify the path filter below stays in sync with what dagster files
# actually import — prevents silent drift where a new import slips in
# without a matching filter entry.
diff --git a/.github/workflows/ci-e2e-playwright.yml b/.github/workflows/ci-e2e-playwright.yml
index 5a6c42e41d3a..45f97c674090 100644
--- a/.github/workflows/ci-e2e-playwright.yml
+++ b/.github/workflows/ci-e2e-playwright.yml
@@ -74,6 +74,29 @@ concurrency:
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
+ # Learning mode: nothing reads these outputs, so a recommendation cannot change what runs.
+ # Fork and Dependabot runs get no secret; the queue always runs everything anyway.
+ # The step fails open, because this telemetry must not turn a passing workflow red.
+ # Drafts skip E2E entirely, so a verdict recorded on one would have no run to check against.
+ dynamic-ci-filter:
+ name: Trunk Dynamic CI (Learning Mode)
+ if: >-
+ github.event_name == 'pull_request' &&
+ github.repository == 'PostHog/posthog' &&
+ github.event.pull_request.head.repo.full_name == github.repository &&
+ github.actor != 'dependabot[bot]' &&
+ !startsWith(github.head_ref, 'trunk-merge/') &&
+ github.event.pull_request.draft != true
+ runs-on: ubuntu-24.04
+ timeout-minutes: 5
+ permissions: {}
+ steps:
+ - name: Ask Trunk which jobs this diff needs
+ continue-on-error: true
+ uses: trunk-io/dynamic-ci@7e3af9331e8ebdfe0c71ba7d0ff6b7424dde8c57 # v1
+ with:
+ token: ${{ secrets.TRUNK_API_TOKEN }}
+
changes:
runs-on: ubuntu-latest
# 7 not 5: the debounce step below sleeps up to 60s, so widen the budget to
diff --git a/.github/workflows/ci-frontend.yml b/.github/workflows/ci-frontend.yml
index 703dc3673043..20c278b4686c 100644
--- a/.github/workflows/ci-frontend.yml
+++ b/.github/workflows/ci-frontend.yml
@@ -45,6 +45,29 @@ env:
NPM_CONFIG_FUND: 'false'
jobs:
+ # Learning mode: nothing reads these outputs, so a recommendation cannot change what runs.
+ # Fork and Dependabot runs get no secret; the queue always runs everything anyway.
+ # The step fails open, because this telemetry must not turn a passing workflow red.
+ dynamic-ci-filter:
+ name: Trunk Dynamic CI (Learning Mode)
+ if: >-
+ github.event_name == 'pull_request' &&
+ github.repository == 'PostHog/posthog' &&
+ github.event.pull_request.head.repo.full_name == github.repository &&
+ github.actor != 'dependabot[bot]' &&
+ !startsWith(github.head_ref, 'trunk-merge/') &&
+ (github.event.pull_request.draft != true ||
+ !contains(github.event.pull_request.labels.*.name, 'no-ci'))
+ runs-on: ubuntu-24.04
+ timeout-minutes: 5
+ permissions: {}
+ steps:
+ - name: Ask Trunk which jobs this diff needs
+ continue-on-error: true
+ uses: trunk-io/dynamic-ci@7e3af9331e8ebdfe0c71ba7d0ff6b7424dde8c57 # v1
+ with:
+ token: ${{ secrets.TRUNK_API_TOKEN }}
+
# Job to decide if we should run frontend ci
# See .github/actions/paths-filter/README.md for filter semantics
# we skip each step individually, so they are still reported as success
diff --git a/.github/workflows/ci-hog.yml b/.github/workflows/ci-hog.yml
index 18ba4cd3eb3b..ebcf7c6d041f 100644
--- a/.github/workflows/ci-hog.yml
+++ b/.github/workflows/ci-hog.yml
@@ -22,6 +22,27 @@ env:
NPM_CONFIG_FUND: 'false'
jobs:
+ # Learning mode: nothing reads these outputs, so a recommendation cannot change what runs.
+ # Fork and Dependabot runs get no secret; the queue always runs everything anyway.
+ # The step fails open, because this telemetry must not turn a passing workflow red.
+ dynamic-ci-filter:
+ name: Trunk Dynamic CI (Learning Mode)
+ if: >-
+ github.event_name == 'pull_request' &&
+ github.repository == 'PostHog/posthog' &&
+ github.event.pull_request.head.repo.full_name == github.repository &&
+ github.actor != 'dependabot[bot]' &&
+ !startsWith(github.head_ref, 'trunk-merge/')
+ runs-on: ubuntu-24.04
+ timeout-minutes: 5
+ permissions: {}
+ steps:
+ - name: Ask Trunk which jobs this diff needs
+ continue-on-error: true
+ uses: trunk-io/dynamic-ci@7e3af9331e8ebdfe0c71ba7d0ff6b7424dde8c57 # v1
+ with:
+ token: ${{ secrets.TRUNK_API_TOKEN }}
+
# Job to decide if we should run backend ci
# See .github/actions/paths-filter/README.md for filter semantics
changes:
diff --git a/.github/workflows/ci-nodejs.yml b/.github/workflows/ci-nodejs.yml
index 031377347514..04fdd6a4457f 100644
--- a/.github/workflows/ci-nodejs.yml
+++ b/.github/workflows/ci-nodejs.yml
@@ -32,6 +32,27 @@ concurrency:
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
+ # Learning mode: nothing reads these outputs, so a recommendation cannot change what runs.
+ # Fork and Dependabot runs get no secret; the queue always runs everything anyway.
+ # The step fails open, because this telemetry must not turn a passing workflow red.
+ dynamic-ci-filter:
+ name: Trunk Dynamic CI (Learning Mode)
+ if: >-
+ github.event_name == 'pull_request' &&
+ github.repository == 'PostHog/posthog' &&
+ github.event.pull_request.head.repo.full_name == github.repository &&
+ github.actor != 'dependabot[bot]' &&
+ !startsWith(github.head_ref, 'trunk-merge/')
+ runs-on: ubuntu-24.04
+ timeout-minutes: 5
+ permissions: {}
+ steps:
+ - name: Ask Trunk which jobs this diff needs
+ continue-on-error: true
+ uses: trunk-io/dynamic-ci@7e3af9331e8ebdfe0c71ba7d0ff6b7424dde8c57 # v1
+ with:
+ token: ${{ secrets.TRUNK_API_TOKEN }}
+
# Job to decide if we should run nodejs services ci
# See .github/actions/paths-filter/README.md for filter semantics
changes:
diff --git a/.github/workflows/ci-python.yml b/.github/workflows/ci-python.yml
index f71555e178dd..cc40a1eaf99d 100644
--- a/.github/workflows/ci-python.yml
+++ b/.github/workflows/ci-python.yml
@@ -26,6 +26,27 @@ concurrency:
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
+ # Learning mode: nothing reads these outputs, so a recommendation cannot change what runs.
+ # Fork and Dependabot runs get no secret; the queue always runs everything anyway.
+ # The step fails open, because this telemetry must not turn a passing workflow red.
+ dynamic-ci-filter:
+ name: Trunk Dynamic CI (Learning Mode)
+ if: >-
+ github.event_name == 'pull_request' &&
+ github.repository == 'PostHog/posthog' &&
+ github.event.pull_request.head.repo.full_name == github.repository &&
+ github.actor != 'dependabot[bot]' &&
+ !startsWith(github.head_ref, 'trunk-merge/')
+ runs-on: ubuntu-24.04
+ timeout-minutes: 5
+ permissions: {}
+ steps:
+ - name: Ask Trunk which jobs this diff needs
+ continue-on-error: true
+ uses: trunk-io/dynamic-ci@7e3af9331e8ebdfe0c71ba7d0ff6b7424dde8c57 # v1
+ with:
+ token: ${{ secrets.TRUNK_API_TOKEN }}
+
# Job to decide if we should run python ci
# See .github/actions/paths-filter/README.md for filter semantics
changes:
diff --git a/.github/workflows/ci-rust.yml b/.github/workflows/ci-rust.yml
index ac2f5a678cb7..8a9b985209e0 100644
--- a/.github/workflows/ci-rust.yml
+++ b/.github/workflows/ci-rust.yml
@@ -15,6 +15,27 @@ env:
RUNS_ON_INTERNAL_PR: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false }}
jobs:
+ # Learning mode: nothing reads these outputs, so a recommendation cannot change what runs.
+ # Fork and Dependabot runs get no secret; the queue always runs everything anyway.
+ # The step fails open, because this telemetry must not turn a passing workflow red.
+ dynamic-ci-filter:
+ name: Trunk Dynamic CI (Learning Mode)
+ if: >-
+ github.event_name == 'pull_request' &&
+ github.repository == 'PostHog/posthog' &&
+ github.event.pull_request.head.repo.full_name == github.repository &&
+ github.actor != 'dependabot[bot]' &&
+ !startsWith(github.head_ref, 'trunk-merge/')
+ runs-on: ubuntu-24.04
+ timeout-minutes: 5
+ permissions: {}
+ steps:
+ - name: Ask Trunk which jobs this diff needs
+ continue-on-error: true
+ uses: trunk-io/dynamic-ci@7e3af9331e8ebdfe0c71ba7d0ff6b7424dde8c57 # v1
+ with:
+ token: ${{ secrets.TRUNK_API_TOKEN }}
+
# Job to decide if we should run rust ci
# See .github/actions/paths-filter/README.md for filter semantics
changes:
diff --git a/.github/workflows/ci-storybook.yml b/.github/workflows/ci-storybook.yml
index cb8203b5f18a..fe74af1a0c92 100644
--- a/.github/workflows/ci-storybook.yml
+++ b/.github/workflows/ci-storybook.yml
@@ -32,6 +32,29 @@ env:
NPM_CONFIG_FUND: 'false'
jobs:
+ # Learning mode: nothing reads these outputs, so a recommendation cannot change what runs.
+ # Fork and Dependabot runs get no secret; the queue always runs everything anyway.
+ # The step fails open, because this telemetry must not turn a passing workflow red.
+ dynamic-ci-filter:
+ name: Trunk Dynamic CI (Learning Mode)
+ if: >-
+ github.event_name == 'pull_request' &&
+ github.repository == 'PostHog/posthog' &&
+ github.event.pull_request.head.repo.full_name == github.repository &&
+ github.actor != 'dependabot[bot]' &&
+ !startsWith(github.head_ref, 'trunk-merge/') &&
+ (github.event.pull_request.draft != true ||
+ !contains(github.event.pull_request.labels.*.name, 'no-ci'))
+ runs-on: ubuntu-24.04
+ timeout-minutes: 5
+ permissions: {}
+ steps:
+ - name: Ask Trunk which jobs this diff needs
+ continue-on-error: true
+ uses: trunk-io/dynamic-ci@7e3af9331e8ebdfe0c71ba7d0ff6b7424dde8c57 # v1
+ with:
+ token: ${{ secrets.TRUNK_API_TOKEN }}
+
# Job to decide if we should run storybook ci
# See .github/actions/paths-filter/README.md for filter semantics
changes:
diff --git a/tools/workflow-plan/tests/workflows.test.ts b/tools/workflow-plan/tests/workflows.test.ts
index 9cad16960a0c..5750b77b3393 100644
--- a/tools/workflow-plan/tests/workflows.test.ts
+++ b/tools/workflow-plan/tests/workflows.test.ts
@@ -122,6 +122,7 @@ const EXPECTATIONS: Expectation[] = [
{ name: 'ready PR' },
{
runs: [
+ 'dynamic-ci-filter',
'turbo-tests',
'django',
'backend-coverage-report',
@@ -139,14 +140,14 @@ const EXPECTATIONS: Expectation[] = [
{ name: 'merge queue', github: mergeQueue() },
{
runs: ['turbo-tests', 'django', 'django_tests'],
- skipped: ['backend-coverage-report'],
+ skipped: ['backend-coverage-report', 'dynamic-ci-filter'],
}
),
backend(
{ name: 'draft PR labeled no-ci', github: pullRequest({ draft: true, labels: ['no-ci'] }) },
{
runs: ['django_tests'],
- skipped: ['changes', 'django', 'turbo-tests', 'repo-checks', 'check-migrations'],
+ skipped: ['changes', 'django', 'turbo-tests', 'repo-checks', 'check-migrations', 'dynamic-ci-filter'],
}
),
backend(
@@ -154,6 +155,7 @@ const EXPECTATIONS: Expectation[] = [
{
runs: ['changes', 'django', 'django_tests'],
skipped: [
+ 'dynamic-ci-filter',
'validate-product-yamls',
'calculate-running-time',
'report-test-timings',
@@ -180,6 +182,7 @@ const EXPECTATIONS: Expectation[] = [
{
runs: ['changes', 'repo-checks', 'check-migrations', 'mirror-schema-cache', 'django_tests'],
skipped: [
+ 'dynamic-ci-filter',
'detect-snapshot-mode',
'turbo-tests',
'django',
@@ -237,14 +240,21 @@ const EXPECTATIONS: Expectation[] = [
frontend(
{ name: 'draft PR', github: pullRequest({ draft: true }) },
{
- runs: ['changes', 'select-jest-tests', 'jest', 'frontend-typescript-checks', 'frontend_tests'],
+ runs: [
+ 'changes',
+ 'dynamic-ci-filter',
+ 'select-jest-tests',
+ 'jest',
+ 'frontend-typescript-checks',
+ 'frontend_tests',
+ ],
}
),
frontend(
{ name: 'merge queue', github: mergeQueue() },
{
runs: ['jest', 'frontend_tests'],
- skipped: ['select-jest-tests'],
+ skipped: ['select-jest-tests', 'dynamic-ci-filter'],
}
),
frontend(
@@ -258,21 +268,21 @@ const EXPECTATIONS: Expectation[] = [
{ name: 'draft PR labeled no-ci', github: pullRequest({ draft: true, labels: ['no-ci'] }) },
{
runs: ['frontend_tests'],
- skipped: ['changes', 'jest', 'frontend-format', 'frontend-typescript-checks'],
+ skipped: ['changes', 'jest', 'frontend-format', 'frontend-typescript-checks', 'dynamic-ci-filter'],
}
),
frontend(
{ name: 'fork PR', github: pullRequest({ fork: true }) },
{
runs: ['jest', 'frontend_tests'],
- skipped: ['capture-jest-selection', 'report-test-signals', 'calculate-running-time'],
+ skipped: ['dynamic-ci-filter', 'capture-jest-selection', 'report-test-signals', 'calculate-running-time'],
}
),
frontend(
{ name: 'master push', github: push() },
{
runs: ['frontend-format', 'frontend-typescript-checks', 'frontend_tests'],
- skipped: ['jest', 'select-jest-tests'],
+ skipped: ['jest', 'select-jest-tests', 'dynamic-ci-filter'],
}
),
frontend(