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): reactivate optional depot backend ci (#66808)

Raúl Negrón-Otero6a2597507920
diff --git a/.depot/actions/pnpm-install/action.yml b/.depot/actions/pnpm-install/action.yml
new file mode 100644
index 000000000000..13bd3da720d9
--- /dev/null
+++ b/.depot/actions/pnpm-install/action.yml
@@ -0,0 +1,85 @@
+# Depot mirror of .github/actions/pnpm-install (same pattern as .depot/actions/setup-sqlx-cli).
+# Kept byte-for-byte equivalent to canonical except the node-gyp chmod below, which is hardened
+# for Depot Cache restores. actions/cache routes to Depot Cache, so the shared key does not collide.
+name: Install pnpm dependencies
+description: |
+ Sets up pnpm + Node, restores the shared pnpm store cache, installs, and
+ saves the cache only on the default branch.
+
+ Single source of truth for the pnpm cache key. Every node workflow shares
+ one namespace (`pnpm-<os>-<lockfile-hash>`), so the store is cached once
+ instead of fragmenting across runner-arch casings or per-workflow keys.
+
+ Deliberately does NOT use setup-node's `cache: pnpm`: that auto-saves on
+ every run (PRs included, and the post-save can't be gated) and keys on
+ `os.arch()` (lowercase `x64`), which never matches a hand-written
+ `runner.arch` key (uppercase `X64`). We restore/save explicitly instead.
+
+inputs:
+ install-command:
+ description: 'Command used to install dependencies. Override for filtered installs.'
+ required: false
+ default: 'pnpm install --frozen-lockfile'
+ node-version-file:
+ description: 'File specifying the Node version.'
+ required: false
+ default: .nvmrc
+ working-directory:
+ description: 'Directory to run the install command in.'
+ required: false
+ default: '.'
+
+runs:
+ using: composite
+ steps:
+ - name: Install pnpm
+ uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8
+
+ - name: Fix node-gyp permissions
+ shell: bash
+ # Depot CI's restored pnpm store can land node-gyp's gyp_main.py without +x.
+ # Locate it across pnpm/action-setup layouts and never fail if it is absent.
+ run: find ~/setup-pnpm -name gyp_main.py -path '*/node-gyp/*' -exec chmod +x {} + 2>/dev/null || true
+
+ - name: Set up Node.js
+ uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
+ with:
+ node-version-file: ${{ inputs.node-version-file }}
+ token: ${{ github.token }}
+
+ - name: Get pnpm store path
+ id: pnpm-store
+ shell: bash
+ run: echo "path=$(pnpm store path --silent)" >> "$GITHUB_OUTPUT"
+
+ - name: Restore pnpm store
+ id: restore
+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ${{ steps.pnpm-store.outputs.path }}
+ key: pnpm-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
+ restore-keys: pnpm-${{ runner.os }}-
+
+ - name: Install dependencies
+ shell: bash
+ working-directory: ${{ inputs.working-directory }}
+ # Pass the command through env and eval it rather than interpolating
+ # ${{ }} straight into run: — that trips semgrep's run-shell-injection
+ # rule. eval keeps shell parsing so quoted --filter globs survive.
+ # pnpm reads npm_config_* — keep cache-miss fetches resilient to blips.
+ env:
+ INSTALL_COMMAND: ${{ inputs.install-command }}
+ npm_config_fetch_retries: 3
+ npm_config_fetch_retry_mintimeout: 10000
+ npm_config_fetch_retry_maxtimeout: 60000
+ run: eval "$INSTALL_COMMAND"
+
+ # Save only on the default branch. Caches written on a PR/branch ref are
+ # scoped to that ref alone — no other branch can read them, they evict
+ # the shared master cache, and they only ever help that one PR's re-runs.
+ - name: Save pnpm store
+ if: github.ref == 'refs/heads/master' && steps.restore.outputs.cache-hit != 'true'
+ uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: ${{ steps.pnpm-store.outputs.path }}
+ key: pnpm-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.yml
index 35685949c791..e49d1f6f43e3 100644
--- a/.depot/workflows/ci-backend.yml
+++ b/.depot/workflows/ci-backend.yml
@@ -7,31 +7,52 @@
# job in .github/workflows/ci-backend-shadow-drift.yml fails when canonical
# changes without a matching depot bump.
#
-# Intentional deltas vs canonical:
+# Intentional deltas vs canonical (everything else is kept apples-to-apples):
# - runs-on: depot-* labels instead of ubuntu-latest
-# - action paths: ./.depot/actions/... instead of ./.github/actions/...
+# - action paths: ./.depot/actions/... instead of ./.github/actions/... (pnpm-install
+# and setup-sqlx-cli are byte-equivalent mirrors of the canonical composites)
# - permissions: pull-requests:read (no comment/auto-commit side effects)
# - Stripped side effects: artifact uploads, PR comment posters, snapshot
-# auto-commit (handle-snapshots), OpenAPI auto-commit, app-token issuance,
-# posthog-github-action telemetry, --store-durations, test-selection verdict
+# auto-commit (handle-snapshots), posthog-github-action telemetry,
+# --store-durations write, test-selection verdict
+# - OpenAPI types: the check-openapi-types job is folded into check-migrations as a
+# check-only step (drift still fails the run); only its auto-commit side effect is dropped
# - actions/cache reads/writes route to Depot Cache, not GitHub Actions Cache,
-# so shared keys with canonical (schema, rust-cache, uv, pnpm) do not collide
+# so shared keys with canonical (schema, uv, pnpm) do not collide
# - Three data-modeling tests deselected (Depot-only MinIO 403 quarantine)
# - GITHUB_TOKEN / OTEL_SERVICE_NAME neutralized (ambient on Depot, not on GHA)
-# - Path-filter persons-SQL folded into migrations; product_yamls dropped
+# - Docker Hub login reads Depot's secret store (secrets.DOCKERHUB_*) rather than
+# canonical's env.DOCKERHUB_USERNAME / vars.DOCKERHUB_USER
+# - Service launch via `nohup ... --down` (survives Depot's step-shell teardown) and
+# waits on a superset (objectstorage, Temporal) with an explicit 900s timeout
+# - Path-filter persons-SQL folded into migrations. check-migrations.if also gates
+# on openapi_types so an OpenAPI-only PR still runs the folded check
+# - Snapshot mode matches canonical, but snapshot patch upload/commit is stripped
+# - Test-duration cache restore omitted: there is no Depot timing-update writer, so
+# the shadow shards from the committed .test_durations (canonical refreshes from a
+# daily cache) and the file-granularity split-plan probe stays dormant
+# - master (push) runs only check-migrations to prime the shared schema cache; the
+# test matrices are skipped on master (canonical runs them). PRs/merge_group/dispatch
+# run the full graph — that is where the apples-to-apples comparison happens
+# - check-migrations timeout widened to 60m because it also runs the folded OpenAPI generation
# This workflow runs all of our backend django tests.
#
-# If these tests get too slow, look at increasing concurrency and re-timing the tests by manually dispatching
-# .depot/workflows/ci-backend-update-test-timing.yml action
-name: Backend CI
-# Every job is gated on the CI_ENABLE_DEPOT_SHADOW Depot CI variable (see the `changes`
-# job): `true` runs the shadow, anything else (incl. unset) skips it. This is a Depot
-# variable, NOT a GitHub one — Depot CI reads its own `vars` store. Toggle with:
-# depot ci vars add CI_ENABLE_DEPOT_SHADOW=true --repo PostHog/posthog (enable)
-# depot ci vars remove CI_ENABLE_DEPOT_SHADOW --repo PostHog/posthog (disable)
-# The companion drift check (.github/workflows/ci-backend-shadow-drift.yml) runs on
-# GitHub Actions and reads a same-named GitHub repository variable — set both.
+# Shards derive from the committed .test_durations; to re-time, refresh that file
+# (canonical's .github/workflows/ci-backend-update-test-timing.yml is the source of truth).
+name: '[optional, does not block merge] Backend CI'
+# OPTIONAL, non-blocking shadow of canonical Backend CI — its statuses must never gate
+# merging (hence the "[optional, does not block merge]" name prefix). The
+# CI_DEPOT_SHADOW_PERCENT Depot CI variable (0-100; 0 or unset = fully off) is both the
+# master switch and the pull_request sample rate: when >0, pull_request runs are sampled at
+# that percent; master (push) runs only check-migrations to prime the schema cache (test
+# matrices are skipped there); workflow_dispatch and merge_group always run. The `sample` job rolls a deterministic
+# per-run dice; `changes` (root of the needs graph) only runs when sampled in, so the
+# whole workflow cascades off on a miss. This is a Depot variable, NOT a GitHub one —
+# Depot CI reads its own `vars` store. Set it with:
+# depot ci vars add CI_DEPOT_SHADOW_PERCENT=<n> --repo PostHog/posthog (n=0 disables)
+# The drift check (.github/workflows/ci-backend-shadow-drift.yml) keeps this file in sync
+# with canonical; it runs whenever either file changes, independent of this variable.
on:
push:
branches:
@@ -50,9 +71,15 @@ on:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]
merge_group:
concurrency:
- group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
+ # PRs: one active run per branch, cancel stale. Push: per-SHA so master
+ # pushes never cancel each other (check-migrations always completes).
+ group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.sha || github.head_ref || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
+ # Schema cache epoch. Bump to abandon every shared schema cache entry at once
+ # (key is posthog-schema-mig-<epoch>-<hash>). Single-sourced so the merge-base (PR)
+ # and HEAD (push) key computations below can't drift.
+ SCHEMA_CACHE_EPOCH: v1
SECRET_KEY: '6b01eee4f945ca25045b5aab440b953461faf08693a9abbf1166dc7c6b9772da' # unsafe - for testing only
DATABASE_URL: 'postgres://posthog:posthog@localhost:5432/posthog'
REDIS_URL: 'redis://localhost'
@@ -94,14 +121,50 @@ permissions:
contents: read
pull-requests: read
jobs:
+ # Sampling gate (full design in the file header). The `if` keeps the whole workflow
+ # off when the percent is 0/unset; when >0 this job computes `sampled`, and `changes`
+ # — hence the rest of the graph — only runs when it is true.
+ sample:
+ if: vars.CI_DEPOT_SHADOW_PERCENT != '' && vars.CI_DEPOT_SHADOW_PERCENT != '0'
+ runs-on: depot-ubuntu-latest
+ timeout-minutes: 5
+ name: '[optional, does not block merge] Sample run'
+ outputs:
+ sampled: ${{ steps.roll.outputs.sampled }}
+ steps:
+ - name: Roll sampling dice
+ id: roll
+ env:
+ PERCENT: ${{ vars.CI_DEPOT_SHADOW_PERCENT }}
+ RUN_ID: ${{ github.run_id }}
+ EVENT: ${{ github.event_name }}
+ run: |
+ set -euo pipefail
+ # Only pull_request is sampled; push/workflow_dispatch/merge_group always run
+ # when enabled (sampling them would skip cache priming or no-op a dispatch).
+ if [ "$EVENT" != "pull_request" ]; then
+ echo "sampled=true" >> "$GITHUB_OUTPUT"
+ echo "::notice::Optional Backend CI: $EVENT always runs when enabled."
+ exit 0
+ fi
+ # Deterministic per-run dice. Non-integer percent → 0 (off).
+ case "$PERCENT" in ''|*[!0-9]*) PERCENT=0 ;; esac
+ bucket=$(( RUN_ID % 100 ))
+ if [ "$bucket" -lt "$PERCENT" ]; then
+ echo "sampled=true" >> "$GITHUB_OUTPUT"
+ echo "::notice::Optional Backend CI: PR sampled IN (bucket $bucket < ${PERCENT}%)."
+ else
+ echo "sampled=false" >> "$GITHUB_OUTPUT"
+ echo "::notice::Optional Backend CI: PR sampled OUT (bucket $bucket >= ${PERCENT}%) — skipped."
+ fi
# Job to decide if we should run backend ci
# See https://github.com/dorny/paths-filter#conditional-execution for more details
changes:
- # Shadow on/off switch. `changes` is the root of the `needs` graph, so gating
- # it skips every downstream job. `django_tests` repeats the gate because its
- # `always()` would otherwise survive the skip cascade.
- if: vars.CI_ENABLE_DEPOT_SHADOW == 'true'
- runs-on: depot-ubuntu-latest # was: ubuntu-latest. Mapped standard GitHub runner to Depot equivalent.
+ # Root of the `needs` graph: skipped when `sample` says skip (or is itself skipped
+ # at percent 0/unset), which cascades the whole workflow off.
+ needs: sample
+ if: needs.sample.outputs.sampled == 'true'
+ runs-on: depot-ubuntu-latest
timeout-minutes: 5
name: Determine need to run backend and migration checks
# Set job outputs to values from filter step
@@ -113,6 +176,13 @@ jobs:
tasks_temporal: ${{ steps.filter.outputs.tasks_temporal || 'true' }}
openapi_types: ${{ steps.filter.outputs.openapi_types || 'true' }}
legacy: ${{ steps.filter.outputs.legacy || 'true' }}
+ schema: ${{ steps.filter.outputs.schema || 'true' }}
+ product_yamls: ${{ steps.filter.outputs.product_yamls || 'false' }}
+ product_yamls_files: ${{ steps.filter.outputs.product_yamls_files }}
+ # True only when every backend-relevant changed file is a data
+ # warehouse import source — lets build_django_matrix drop the
+ # Core/CorePOE/compat segments. Defaults false (full matrix).
+ data_import_sources_only: ${{ steps.sources.outputs.data_import_sources_only || 'false' }}
steps:
# For pull requests it's not necessary to checkout the code, but we
# also want this to run on master so we need to checkout
@@ -170,17 +240,29 @@ jobs:
- requirements-dev.txt
- mypy.ini
- pytest.ini
+ - conftest.py # Root conftest loads for every pytest run
- .test_durations # Used for pytest-split sharding
+ - .test_quarantine.json # Un-quarantining must re-run the affected tests
# generates posthog/schema.py
- frontend/src/queries/schema.json
# Operator parity check
- rust/feature-flags/src/properties/property_models.rs
- frontend/src/products.json # Loaded at runtime by posthog/products.py
- 'products/*/manifest.tsx' # Generates products.json
- # hogli db commands used for test database setup
- - 'tools/hogli-commands/hogli_commands/**'
+ # hogli setup commands this workflow runs: db:restore-test-db
+ # and product:bootstrap/lint. Scoped to the modules those
+ # commands actually import — framework, manifest, boot
+ # modules, db_schema, product — so unrelated hogli commands
+ # (doctor, devbox, ...) don't trigger this suite.
- 'tools/hogli/**'
- hogli.yaml
+ - 'tools/hogli-commands/hogli_commands/db_schema.py'
+ - 'tools/hogli-commands/hogli_commands/prechecks.py'
+ - 'tools/hogli-commands/hogli_commands/telemetry_props.py'
+ - 'tools/hogli-commands/hogli_commands/hint_hook.py'
+ - 'tools/hogli-commands/hogli_commands/hints.py'
+ - 'tools/hogli-commands/hogli_commands/product/**'
+ - 'tools/hogli-commands/hogli_commands/product_structure.yaml'
# Make sure we run if someone is explicitly changing the workflow
- .depot/workflows/ci-backend.yml
- .github/clickhouse-versions.json
@@ -218,8 +300,9 @@ jobs:
- requirements-dev.txt
- mypy.ini
- pytest.ini
+ - conftest.py
- .test_durations
- - frontend/src/queries/schema.json
+ - .test_quarantine.json
- frontend/src/products.json
- 'products/*/manifest.tsx'
- rust/feature-flags/src/properties/property_models.rs
@@ -232,6 +315,11 @@ jobs:
- bin/ci-wait-for-docker
- frontend/public/email/*
- 'docker/clickhouse/**'
+ schema:
+ # Tracked separately from `legacy` so turbo-discover can
+ # diff schema.json and narrow the product matrix to
+ # products that import the changed types.
+ - frontend/src/queries/schema.json
migrations:
- 'docker/clickhouse/**'
- 'posthog/migrations/*.py'
@@ -243,9 +331,12 @@ jobs:
- 'rust/bin/migrate-persons'
tasks_temporal:
- 'products/tasks/backend/temporal/**/*'
+ product_yamls:
+ - 'products/*/product.yaml'
openapi_types:
# Generated OpenAPI types - validate they match schema
- 'frontend/src/generated/**/*'
+ - 'frontend/src/lib/agentScopes.generated.ts'
- 'products/*/frontend/generated/**/*'
- 'services/mcp/src/generated/**/*'
- 'services/mcp/src/api/generated.ts'
@@ -265,12 +356,93 @@ jobs:
- 'services/mcp/src/tools/generated/**/*'
- 'services/mcp/schema/generated-tool-definitions.json'
- 'services/mcp/schema/tool-definitions-all.json'
+
+ # Detect PRs whose backend changes are confined to data warehouse
+ # import sources that NO Django Core/CorePOE-collected code imports.
+ # Such a PR is exercised only by the Temporal segment (Core/CorePOE
+ # --ignore=posthog/temporal), so those segments add no coverage.
+ # The `coupled` sources are reverse-imported at runtime by Core tests
+ # (e.g. posthog/hogql/test/test_direct_postgres_query.py imports
+ # postgres) — a PR touching them must run the full matrix or it would
+ # silently skip those tests. `coupled` is kept complete by the guard
+ # test products/warehouse_sources/backend/temporal/data_imports/sources/tests/test_ci_core_coupled_sources.py.
+ # Fails OPEN: empty/non-source/coupled file list → false → full matrix.
+ # PR events only; push and merge_group always run everything.
+ # continue-on-error keeps the fail-open promise even when the runner can't
+ # start the step at all: a very large PR (e.g. a big rename) makes
+ # BACKEND_FILES exceed the process env limit ("Argument list too long"),
+ # which would otherwise hard-fail this job and skip every dependent test job.
+ # On that failure the job output below defaults to false → full matrix.
+ - name: Determine if only data warehouse sources changed
+ id: sources
+ continue-on-error: true
+ if: github.event_name == 'pull_request'
+ env:
+ BACKEND_FILES: ${{ steps.filter.outputs.backend_files }}
+ run: |
+ prefix="products/warehouse_sources/backend/temporal/data_imports/sources/"
+ # Space-separated, double-quoted, single line — parsed by the guard test.
+ coupled="common google_search_console mysql postgres salesforce stripe"
+ only_sources=false
+ if [ -n "$BACKEND_FILES" ]; then
+ only_sources=true
+ for f in $BACKEND_FILES; do
+ case "$f" in
+ "$prefix"*) ;;
+ *) only_sources=false; break ;;
+ esac
+ rest=${f#"$prefix"} # path within sources/
+ top=${rest%%/*} # vendor dir (or top-level filename)
+ case " $coupled " in
+ *" $top "*) only_sources=false; break ;;
+ esac
+ done
+ fi
+ echo "data_import_sources_only=$only_sources" >> "$GITHUB_OUTPUT"
+ echo "Only data warehouse import sources changed: $only_sources"
+
+ detect-snapshot-mode:
+ name: Detect snapshot mode
+ runs-on: depot-ubuntu-latest
+ timeout-minutes: 5
+ needs: [changes]
+ if: needs.changes.outputs.backend == 'true'
+ outputs:
+ mode: ${{ steps.detect.outputs.mode }}
+ steps:
+ - name: Detect mode
+ id: detect
+ env:
+ PR_REPO: ${{ github.event.pull_request.head.repo.full_name }}
+ REPO: ${{ github.repository }}
+ HAS_NO_SNAPSHOT_LABEL: ${{ contains(github.event.pull_request.labels.*.name, 'no-snapshot-update') }}
+ AUTHOR: ${{ github.actor }}
+ run: |
+ if [ "$PR_REPO" != "$REPO" ] && [ -n "$PR_REPO" ]; then
+ echo "mode=check" >> "$GITHUB_OUTPUT"
+ echo "Fork detected - running in check mode"
+ elif [ "$HAS_NO_SNAPSHOT_LABEL" == "true" ]; then
+ echo "mode=check" >> "$GITHUB_OUTPUT"
+ echo "No-snapshot label detected - running in check mode"
+ else
+ echo "Workflow triggered by: $AUTHOR"
+ if [[ "$AUTHOR" != "dependabot[bot]" ]] && \
+ { [[ "$AUTHOR" == *"github-actions"* ]] || [[ "$AUTHOR" == *"[bot]"* ]] || [[ "$AUTHOR" == "posthog-bot" ]]; }; then
+ echo "mode=check" >> "$GITHUB_OUTPUT"
+ echo "Bot actor detected - running in check mode"
+ else
+ echo "mode=update" >> "$GITHUB_OUTPUT"
+ echo "Running in update mode"
+ fi
+ fi
+
# Fast pre-job: determines which products need testing and if Django should run
# Only needs pnpm + node — no Python, Docker, or services
# Runs on depot for turbo remote cache access (cache status drives Django gating)
turbo-discover:
needs: changes
- if: needs.changes.outputs.backend == 'true'
+ # Not on master push: master only primes the schema cache; this cascades the matrices off.
+ if: needs.changes.outputs.backend == 'true' && github.event_name != 'push'
runs-on: depot-ubuntu-latest
timeout-minutes: 20
name: Discover product tests
@@ -278,6 +450,7 @@ jobs:
run_legacy: ${{ steps.discover.outputs.run_legacy }}
matrix: ${{ steps.discover.outputs.matrix }}
schema_cache_key: ${{ steps.schema-key.outputs.key }}
+ schema_migrations_key: ${{ steps.schema-key.outputs.migrations_key }}
django_shards: ${{ steps.discover.outputs.django_shards }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -299,32 +472,47 @@ jobs:
# The fetch-depth:1000 checkout + base-ref fetch above ensure the
# full ancestry needed to find the divergence point is available.
MERGE_BASE=$(git merge-base HEAD^2 "origin/${BASE_REF}" 2>/dev/null || echo "")
- if [ -n "$MERGE_BASE" ]; then
- echo "key=posthog-schema-master-${MERGE_BASE}" >> $GITHUB_OUTPUT
- else
+ if [ -z "$MERGE_BASE" ]; then
echo "key=" >> $GITHUB_OUTPUT
+ echo "migrations_key=" >> $GITHUB_OUTPUT
echo "::notice::merge-base not found (branch too stale?) — schema cache will be skipped"
+ exit 0
+ fi
+ # Exact branch-point key, kept as the fallback restore key below.
+ echo "key=posthog-schema-master-${MERGE_BASE}" >> $GITHUB_OUTPUT
+ # Shared key: hash merge-base schema inputs, not PR head, so PR migrations still
+ # apply as the pytest delta. uv.lock covers third-party migration changes; the
+ # postgres image is folded in so a server-version bump invalidates the key.
+ # Non-Django migration frameworks are excluded from this Postgres schema dump.
+ # SCHEMA_CACHE_EPOCH (workflow env) prefixes the key as a manual cache-bust knob.
+ MIG_FILES=$(git ls-tree -r --format='%(objectname) %(path)' "$MERGE_BASE" \
+ | grep -E '/migrations/[^/]+\.py$|^[0-9a-f]+ uv\.lock$' \
+ | grep -vE '/(clickhouse|async_migrations)/migrations/' \
+ | LC_ALL=C sort) || true
+ PG_IMAGE=$(git show "${MERGE_BASE}:docker-compose.base.yml" 2>/dev/null \
+ | grep -m1 -E '^[[:space:]]*image:[[:space:]]*postgres:' | tr -d '[:space:]')
+ if [ -z "$MIG_FILES" ]; then
+ echo "migrations_key=" >> $GITHUB_OUTPUT
+ echo "::notice::no migration files matched — restore will fall back to the SHA schema key"
+ else
+ MIG_HASH=$(printf '%s\n%s' "$MIG_FILES" "$PG_IMAGE" | sha256sum | cut -c1-40)
+ echo "migrations_key=posthog-schema-mig-${SCHEMA_CACHE_EPOCH}-${MIG_HASH}" >> $GITHUB_OUTPUT
fi
- - name: Setup pnpm
- uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8
- - name: Setup Node.js
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
- with:
- node-version-file: .nvmrc
- cache: pnpm
- cache-dependency-path: |
- pnpm-lock.yaml
- .depot/workflows/ci-backend.yml
- name: Install pnpm dependencies
- run: pnpm install --frozen-lockfile --filter=@posthog/root
+ uses: ./.depot/actions/pnpm-install
+ with:
+ install-command: pnpm install --frozen-lockfile --filter=@posthog/root
- name: Discover products to test
id: discover
env:
# On pushes to master, always run everything.
# On PRs, use the path filter to detect legacy changes.
LEGACY_CHANGED: ${{ github.event_name != 'pull_request' || needs.changes.outputs.legacy }}
+ SCHEMA_CHANGED: ${{ github.event_name != 'pull_request' || needs.changes.outputs.schema }}
TURBO_SCM_BASE: ${{ github.event_name == 'pull_request' && format('origin/{0}', github.event.pull_request.base.ref) || '' }}
TURBO_SCM_HEAD: ${{ github.sha }}
+ # Kill switch — drop comma-separated products from the matrix; empty = run all.
+ SKIP_PRODUCT_TESTS: ${{ vars.SKIP_PRODUCT_TESTS || '' }}
run: |
# turbo-discover.js uses Turbo's Git affectedness to detect
# changed products. Non-isolated product changes trigger the
@@ -458,7 +646,8 @@ jobs:
# Core (POE off): posthog ee/ (minus posthog/temporal, posthog/dags)
# Core POE on: posthog/clickhouse, posthog/queries, posthog/api/test/test_insight*,
# posthog/api/test/dashboards/test_dashboard.py, ee/clickhouse/
- # Temporal: posthog/temporal, products/{batch_exports,tasks}/backend/temporal
+ # Temporal: posthog/temporal, products/{batch_exports,tasks}/backend/temporal,
+ # products/warehouse_sources/backend/temporal, products/signals/backend/emission
# Files outside posthog/ and ee/ (e.g. products/foo/backend/test_*) are not in this
# matrix — turbo-tests handles them.
core=()
@@ -467,7 +656,7 @@ jobs:
while IFS= read -r f; do
[[ -z "$f" ]] && continue
case "$f" in
- posthog/temporal/*|products/batch_exports/backend/tests/temporal/*|products/tasks/backend/temporal/*)
+ posthog/temporal/*|products/batch_exports/backend/tests/temporal/*|products/tasks/backend/temporal/*|products/warehouse_sources/backend/temporal/*|products/signals/backend/emission/*)
temporal+=("$f")
;;
posthog/clickhouse/*|posthog/queries/*|ee/clickhouse/*|products/product_analytics/backend/api/test/*|posthog/api/test/test_insight*|posthog/api/test/dashboards/test_dashboard.py)
@@ -496,11 +685,11 @@ jobs:
# Each job gets its own runner + Docker stack, so no shared DB conflicts
# Small products (< 50 tests) are grouped into a single job to avoid setup overhead
turbo-tests:
- needs: [changes, turbo-discover]
+ needs: [changes, turbo-discover, detect-snapshot-mode]
if: >-
always() && (github.event.pull_request.draft != true || contains(github.event.pull_request.labels.*.name, 'run-ci-backend')) && needs.turbo-discover.result == 'success' && needs.turbo-discover.outputs.matrix != '[]' && needs.turbo-discover.outputs.matrix != ''
runs-on: depot-ubuntu-latest
- timeout-minutes: 60
+ timeout-minutes: 40
name: Product tests (${{ matrix.group }})
strategy:
fail-fast: false
@@ -531,21 +720,13 @@ jobs:
# nohup detaches the launch so it survives Depot's step-shell teardown
# (which SIGHUPs a plain `&` subshell). Isolated here; bin/ci-wait-for-docker stays == master.
nohup bin/ci-wait-for-docker launch --background --down \
- db redis7 clickhouse zookeeper kafka objectstorage feature-flags \
+ db redis7 clickhouse zookeeper kafka objectstorage \
temporal elasticsearch objectstorage-azure \
</dev/null >"${RUNNER_TEMP:-/tmp}/compose-launch.log" 2>&1
- - name: Setup pnpm
- uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8
- - name: Setup Node.js
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
- with:
- node-version-file: .nvmrc
- cache: pnpm
- cache-dependency-path: |
- pnpm-lock.yaml
- .depot/workflows/ci-backend.yml
- name: Install pnpm dependencies
- run: pnpm install --frozen-lockfile --filter=@posthog/root
+ uses: ./.depot/actions/pnpm-install
+ with:
+ install-command: pnpm install --frozen-lockfile --filter=@posthog/root
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
@@ -567,12 +748,6 @@ jobs:
with:
toolchain: 1.91.1
components: cargo
- - name: Cache Rust dependencies
- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
- with:
- shared-key: 'v2-rust-backend'
- workspaces: rust
- save-if: ${{ github.ref == 'refs/heads/master' }}
- name: Install sqlx-cli
uses: ./.depot/actions/setup-sqlx-cli
- name: Install Python dependencies
@@ -604,7 +779,10 @@ jobs:
uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
path: schema.sql.gz
- key: ${{ needs.turbo-discover.outputs.schema_cache_key }}
+ # Prefer the shared content key; fall back to the exact merge-base SHA key.
+ key: ${{ needs.turbo-discover.outputs.schema_migrations_key || needs.turbo-discover.outputs.schema_cache_key }}
+ restore-keys: |
+ ${{ needs.turbo-discover.outputs.schema_cache_key }}
- name: Prime test_posthog from cached schema
# No-op on cache miss; pytest --reuse-db falls back to a full migrate.
if: ${{ github.event_name == 'pull_request' }}
@@ -615,7 +793,9 @@ jobs:
fi
mkdir -p .postgres-backups
mv schema.sql.gz .postgres-backups/schema-latest.sql.gz
- ./bin/hogli db:restore-test-db
+ if ! ./bin/hogli db:restore-test-db; then
+ echo "::warning::Schema restore failed (stale/incompatible cached dump?) — pytest --reuse-db will run a full migrate"
+ fi
- name: 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
@@ -623,14 +803,18 @@ jobs:
env:
# --reuse-db: keep the test database between sequential product runs to avoid
# ClickHouse drop/create race conditions with ReplicatedMergeTree ZK metadata.
- # Shadow trial: no snapshot-update / store-durations side effects.
- PYTEST_ADDOPTS: --reuse-db
+ # --durations-path: turbo runs products from products/<name>/, so pytest-split
+ # needs an explicit path back to the repo-root durations file for balanced sharding.
+ PYTEST_ADDOPTS: >-
+ --reuse-db
+ --durations-path ../../.test_durations
+ ${{ needs.detect-snapshot-mode.outputs.mode == 'update' && '--snapshot-update --snapshot-warn-unused' || '' }}
run: pnpm turbo run backend:test ${{ matrix.filters }} --concurrency=1 --output-logs=full --force --log-order=stream ${{ matrix.pytest_args }}
# Lightweight repo-wide checks that only need Python + uv (no Docker/DB).
# Consolidates checks that previously each spun up their own runner.
repo-checks:
needs: [changes]
- if: needs.changes.outputs.backend == 'true'
+ if: needs.changes.outputs.backend == 'true' && github.event_name != 'push'
timeout-minutes: 10
name: Repo checks (depot-ubuntu-latest)
runs-on: depot-ubuntu-latest
@@ -660,13 +844,60 @@ jobs:
run: tach check --dependencies --interfaces
- name: Check product facade enforcement (import-linter)
run: lint-imports
+
+ validate-product-yamls:
+ needs: [changes]
+ if: >
+ needs.changes.outputs.product_yamls == 'true' &&
+ github.event_name == 'pull_request' &&
+ github.event.pull_request.head.repo.full_name == github.repository
+ timeout-minutes: 5
+ name: Validate product.yaml owners (depot-ubuntu-latest)
+ runs-on: depot-ubuntu-latest
+ steps:
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+ - name: Get app token
+ id: app-token
+ uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
+ with:
+ client-id: ${{ secrets.GH_APP_POSTHOG_ASSIGN_REVIEWERS_APP_ID }}
+ private-key: ${{ secrets.GH_APP_POSTHOG_ASSIGN_REVIEWERS_PRIVATE_KEY }}
+ owner: ${{ github.repository_owner }}
+ repositories: ${{ github.event.repository.name }}
+ - name: Set up Python
+ uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
+ with:
+ python-version: 3.13.13
+ token: ${{ steps.app-token.outputs.token || github.token }}
+ - name: Install uv
+ uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
+ with:
+ version: '0.11.14'
+ - name: Install Python dependencies
+ run: UV_PROJECT_ENVIRONMENT=$pythonLocation uv sync --frozen --dev
+ - name: Validate changed product.yaml owners
+ env:
+ GH_TOKEN: ${{ steps.app-token.outputs.token }}
+ CHANGED_FILES: ${{ needs.changes.outputs.product_yamls_files }}
+ run: |
+ mapfile -t names < <(echo "$CHANGED_FILES" | tr ' ' '\n' | sed -n 's|^products/\([^/]*\)/product.yaml$|\1|p')
+ existing=()
+ for n in "${names[@]}"; do
+ [ -f "products/$n/product.yaml" ] && existing+=("$n")
+ done
+ if [ "${#existing[@]}" -eq 0 ]; then
+ echo "No existing product.yaml files in diff after filtering"
+ exit 0
+ fi
+ ./bin/hogli product:lint:owners "${existing[@]}"
+
# Migration validation and OpenAPI type generation.
# This job needs Docker + DB — it checks out master first to run baseline
# migrations, then checks out the PR branch. All steps after the PR checkout
# require Django + DB. Lightweight checks belong in repo-checks above.
check-migrations:
needs: [changes]
- if: needs.changes.outputs.backend == 'true' || needs.changes.outputs.openapi_types == 'true'
+ if: needs.changes.outputs.backend == 'true' || needs.changes.outputs.migrations == 'true' || needs.changes.outputs.openapi_types == 'true'
timeout-minutes: 60
name: Validate migrations and OpenAPI types
runs-on: depot-ubuntu-latest
@@ -716,12 +947,6 @@ jobs:
with:
toolchain: 1.91.1
components: cargo
- - name: Cache Rust dependencies
- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
- with:
- shared-key: 'v2-rust-backend'
- workspaces: rust
- save-if: ${{ github.ref == 'refs/heads/master' }}
- name: Install sqlx-cli
uses: ./.depot/actions/setup-sqlx-cli
# First running migrations from master, to simulate the real-world scenario
@@ -783,11 +1008,36 @@ jobs:
# Verify the dump is valid
gunzip -t schema.sql.gz
- name: Save schema to Actions cache for PR shards
+ # Kept for fallback and for other workflows that still restore by merge-base SHA.
if: github.event_name == 'push'
uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
path: schema.sql.gz
key: posthog-schema-master-${{ github.sha }}
+ - name: Compute migration-set schema key
+ # Must match the merge-base computation in turbo-discover (inputs, hash, and key prefix).
+ if: github.event_name == 'push'
+ id: mig-schema-key
+ run: |
+ MIG_FILES=$(git ls-tree -r --format='%(objectname) %(path)' HEAD \
+ | grep -E '/migrations/[^/]+\.py$|^[0-9a-f]+ uv\.lock$' \
+ | grep -vE '/(clickhouse|async_migrations)/migrations/' \
+ | LC_ALL=C sort) || true
+ PG_IMAGE=$(git show "HEAD:docker-compose.base.yml" 2>/dev/null \
+ | grep -m1 -E '^[[:space:]]*image:[[:space:]]*postgres:' | tr -d '[:space:]')
+ if [ -z "$MIG_FILES" ]; then
+ echo "key=" >> $GITHUB_OUTPUT
+ echo "::notice::no migration files matched — skipping migration-set schema save"
+ else
+ MIG_HASH=$(printf '%s\n%s' "$MIG_FILES" "$PG_IMAGE" | sha256sum | cut -c1-40)
+ echo "key=posthog-schema-mig-${SCHEMA_CACHE_EPOCH}-${MIG_HASH}" >> $GITHUB_OUTPUT
+ fi
+ - name: Save schema to Actions cache (migration-set key)
+ if: github.event_name == 'push' && steps.mig-schema-key.outputs.key != ''
+ uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
+ with:
+ path: schema.sql.gz
+ key: ${{ steps.mig-schema-key.outputs.key }}
- name: Check migrations
# Skip migration safety check on master push (no migration_files from path filter)
if: github.event_name != 'push'
@@ -801,26 +1051,10 @@ jobs:
run: |
# Same as above, except now for CH looking at files that were added in posthog/clickhouse/migrations/
git diff --name-status origin/master..HEAD | grep "A\sposthog/clickhouse/migrations/" | grep -v README | awk '{print $2}' | python manage.py test_ch_migrations_are_safe
- - name: Install pnpm
- uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8
- - name: Fix node-gyp permissions
- # Depot CI's restored pnpm store can land node-gyp's gyp_main.py without +x.
- # Locate it across pnpm/action-setup layouts and never fail if it is absent.
- run: find ~/setup-pnpm -name gyp_main.py -path '*/node-gyp/*' -exec chmod +x {} + 2>/dev/null || true
- - name: Set up Node.js
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
- with:
- node-version-file: .nvmrc
- cache: pnpm
- cache-dependency-path: |
- pnpm-lock.yaml
- .depot/workflows/ci-backend.yml
- name: Install package.json dependencies with pnpm
- env:
- npm_config_fetch_retries: 3
- npm_config_fetch_retry_mintimeout: 10000
- npm_config_fetch_retry_maxtimeout: 60000
- run: pnpm --filter=@posthog/root --filter=@posthog/frontend... --filter=@posthog/mcp... install --frozen-lockfile
+ uses: ./.depot/actions/pnpm-install
+ with:
+ install-command: pnpm --filter=@posthog/root --filter=@posthog/frontend... --filter=@posthog/mcp... install --frozen-lockfile
- name: Add OpenAPI Problem Matcher
run: echo "::add-matcher::.github/openapi-problem-matcher.json"
# Shadow trial: OpenAPI types are check-only — no auto-commit side effect.
@@ -856,9 +1090,23 @@ jobs:
RUN_POE: ${{ needs.select-tests.outputs.run_poe }}
RUN_TEMPORAL: ${{ needs.select-tests.outputs.run_temporal }}
CORE_FILES: ${{ needs.select-tests.outputs.core_files }}
+ DATA_IMPORT_SOURCES_ONLY: ${{ needs.changes.outputs.data_import_sources_only }}
+ IS_DRAFT: ${{ github.event.pull_request.draft }}
+ FORCE_FULL: ${{ contains(github.event.pull_request.labels.*.name, 'run-ci-backend') }}
run: |
# :NOTE: Keep shard counts/group ranges in sync with historical Django matrix tuning.
# Consult #team-devex before changing.
+
+ # A draft PR must never fall back to the full matrix. select-tests only
+ # runs on drafts and sets MODE to "skip"/"selected"; an empty MODE on a
+ # draft means select-tests was cancelled or failed (typically
+ # ready_for_review superseding it mid-flight). Skip here and defer to the
+ # ready run. The run-ci-backend label intentionally forces full on a draft.
+ if [[ -z "$MODE" && "$IS_DRAFT" == "true" && "$FORCE_FULL" != "true" ]]; then
+ echo "::notice::Draft PR with no trusted Django selection — skipping heavy matrices; the ready-for-review run is the full gate"
+ MODE="skip"
+ fi
+
if [[ "$MODE" == "skip" ]]; then
# Draft PR where selection couldn't be trusted: skip the heavy
# matrices and defer to the full run on ready for review.
@@ -982,17 +1230,25 @@ jobs:
')
fi
- include=$(jq -cn \
- --argjson core "$core" \
- --argjson core_persons_on_events "$core_persons_on_events" \
- --argjson temporal "$temporal" \
- --argjson compat "$compat" \
- '$core + $core_persons_on_events + $temporal + $compat')
+ if [ "$DATA_IMPORT_SOURCES_ONLY" = "true" ]; then
+ # Only data warehouse import sources changed — the Temporal
+ # segment already covers posthog/temporal, so skip Core/CorePOE/compat.
+ echo "Only data warehouse import sources changed — running Temporal segment only"
+ include="$temporal"
+ else
+ include=$(jq -cn \
+ --argjson core "$core" \
+ --argjson core_persons_on_events "$core_persons_on_events" \
+ --argjson temporal "$temporal" \
+ --argjson compat "$compat" \
+ '$core + $core_persons_on_events + $temporal + $compat')
+ fi
echo "include=$include" >> "$GITHUB_OUTPUT"
echo "Django matrix size: $(jq -r 'length' <<< "$include") (mode=$MODE)"
django:
- needs: [changes, turbo-discover, get_clickhouse_versions, build_django_matrix, select-tests]
+ needs:
+ [changes, turbo-discover, detect-snapshot-mode, get_clickhouse_versions, build_django_matrix, select-tests]
# Run legacy pytest if:
# 1. Legacy code directly changed (ee/, posthog/)
# 2. OR product changes affect legacy code (turbo-discover outputs run_legacy=true)
@@ -1008,7 +1264,8 @@ jobs:
needs.turbo-discover.outputs.run_legacy == 'true' ||
(needs.turbo-discover.result != 'success' && needs.turbo-discover.result != 'skipped'))
# increase for tmate testing
- timeout-minutes: 60
+ # 45 to match canonical; the shadow is non-blocking so no deploy-gate coupling.
+ timeout-minutes: 45
name: Django tests – ${{ matrix.segment }}${{ matrix.compat && ' compat' || '' }} (persons-on-events ${{ matrix.person-on-events && 'on' || 'off' }}), Py ${{ matrix.python-version }}, ${{ matrix.clickhouse-server-image }} (${{matrix.group}}/${{ matrix.concurrency }})
# Match canonical's runner size. The shadow restores the same master-primed
# schema cache (turbo-discover key + check-migrations save), so shards skip
@@ -1026,6 +1283,9 @@ jobs:
ref: ${{ github.event.pull_request.head.ref }}
lfs: true
clean: false
+ - name: Install signal-fanout
+ shell: bash
+ run: sudo install -m 0755 .github/scripts/signal-fanout /usr/local/bin/signal-fanout
- name: Clean up data directories with container permissions
run: |
# Use docker to clean up files created by containers
@@ -1090,13 +1350,6 @@ jobs:
with:
toolchain: 1.91.1
components: cargo
- - name: Cache Rust dependencies
- if: needs.changes.outputs.backend == 'true'
- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
- with:
- shared-key: 'v2-rust-backend'
- workspaces: rust
- save-if: ${{ github.ref == 'refs/heads/master' }}
- name: Install sqlx-cli
if: needs.changes.outputs.backend == 'true'
uses: ./.depot/actions/setup-sqlx-cli
@@ -1182,7 +1435,10 @@ jobs:
uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
path: schema.sql.gz
- key: ${{ needs.turbo-discover.outputs.schema_cache_key }}
+ # Prefer the shared content key; fall back to the exact merge-base SHA key.
+ key: ${{ needs.turbo-discover.outputs.schema_migrations_key || needs.turbo-discover.outputs.schema_cache_key }}
+ restore-keys: |
+ ${{ needs.turbo-discover.outputs.schema_cache_key }}
- name: Prime test_posthog from cached schema
# No-op on cache miss; pytest --reuse-db falls back to a full migrate.
if: ${{ github.event_name == 'pull_request' }}
@@ -1193,8 +1449,22 @@ jobs:
fi
mkdir -p .postgres-backups
mv schema.sql.gz .postgres-backups/schema-latest.sql.gz
- ./bin/hogli db:restore-test-db
+ if ! ./bin/hogli db:restore-test-db; then
+ echo "::warning::Schema restore failed (stale/incompatible cached dump?) — pytest --reuse-db will run a full migrate"
+ fi
# Tests
+ - name: Set snapshot update flags
+ if: ${{ needs.changes.outputs.backend == 'true' && (needs.detect-snapshot-mode.outputs.mode == 'update' || matrix.person-on-events) }}
+ shell: bash
+ run: echo "PYTEST_ARGS=--snapshot-update --snapshot-warn-unused" >> "$GITHUB_ENV"
+ - name: Set compat snapshot flags
+ if: ${{ needs.changes.outputs.backend == 'true' && matrix.compat }}
+ shell: bash
+ run: echo "PYTEST_ARGS=--snapshot-update --snapshot-warn-unused" >> "$GITHUB_ENV"
+ - name: Set check-mode snapshot flags
+ if: ${{ needs.changes.outputs.backend == 'true' && needs.detect-snapshot-mode.outputs.mode != 'update' && !matrix.person-on-events && !matrix.compat }}
+ shell: bash
+ run: echo "PYTEST_ARGS=--snapshot-warn-unused" >> "$GITHUB_ENV"
- name: Log test environment diagnostics
if: ${{ needs.changes.outputs.backend == 'true' && matrix.segment == 'Core' }}
shell: bash
@@ -1225,15 +1495,31 @@ jobs:
MODE: ${{ needs.select-tests.outputs.mode }}
CORE_FILES: ${{ needs.select-tests.outputs.core_files }}
POE_FILES: ${{ needs.select-tests.outputs.poe_files }}
- shell: bash
+ shell: 'signal-fanout bash --noprofile --norc -eo pipefail {0}'
run: | # async_migrations covered in ci-async-migrations.yml
unset GITHUB_TOKEN # reserved var injected by Depot CI; can't override via env: (see workflow env note)
set +e
+ # Pick the split algorithm and granularity at runtime: optimal_chunks + file
+ # granularity only when the installed pytest-split offers them, else
+ # duration_based_chunks / item. A workflow edit runs merged with master, so an
+ # unrebased PR on older pytest-split must not hit an unknown flag.
+ SPLITTING_ALGORITHM=duration_based_chunks
+ SPLIT_GRANULARITY=()
+ if python -c "from pytest_split.algorithms import Algorithms; from pytest_split.plugin import PytestSplitFilePlugin; raise SystemExit(0 if 'optimal_chunks' in Algorithms.names() else 1)" 2>/dev/null; then
+ SPLITTING_ALGORITHM=optimal_chunks
+ SPLIT_GRANULARITY=(--split-granularity=file)
+ # Scope the file-mode plan to Core's clean per-segment durations when the
+ # pinned pytest-split supports it; only persons-on-events-off, non-compat Core
+ # matches the .core run-set, and a missing file falls back to the union.
+ if [ -f .test_durations.core ] && [[ "${{ matrix.person-on-events }}" != "true" ]] && [[ "${{ matrix.compat }}" != "true" ]] && python -c "from pytest_split.plugin import SUPPORTS_SPLIT_PLAN_PATH" 2>/dev/null; then
+ SPLIT_GRANULARITY+=(--split-plan-path .test_durations.core)
+ fi
+ fi
if [[ "$MODE" == "selected" ]]; then
# Selected mode: run only the test files chosen by the snob shadow selector.
# No --splits/--group (no sharding), no --reruns (selected runs should fail
# loud so flaky tests get fixed instead of masked; the ready-for-review full
- # run has reruns). Snapshot flags kept to match the depot shadow's full branch.
+ # run has reruns).
if [[ "${{ matrix.person-on-events }}" == "true" ]]; then
targets="$POE_FILES"
else
@@ -1241,9 +1527,9 @@ jobs:
fi
# shellcheck disable=SC2086
pytest -v --tb=short --reuse-db -o junit_duration_report=call $targets -m "not async_migrations" \
- --snapshot-update --snapshot-warn-unused \
-r fEsxX \
- --junitxml=junit-core.xml
+ --junitxml=junit-core.xml \
+ $PYTEST_ARGS
else
pytest -v --tb=short --reuse-db -o junit_duration_report=call ${{
matrix.compat
@@ -1259,13 +1545,15 @@ jobs:
--ignore=common/hogvm/python/test \
${{ matrix.person-on-events && '--ignore=posthog/hogql_queries' || '' }} \
${{ matrix.person-on-events && '--ignore=posthog/hogql' || '' }} \
- --snapshot-update --snapshot-warn-unused \
--splits ${{ matrix.concurrency }} --group ${{ matrix.group }} \
--durations=1000 --durations-min=1.0 \
- --splitting-algorithm=duration_based_chunks \
+ --pytest-durations=100 \
+ --splitting-algorithm="$SPLITTING_ALGORITHM" \
+ "${SPLIT_GRANULARITY[@]}" \
--reruns 2 --reruns-delay 1 \
-r fEsxX \
- --junitxml=junit-core.xml
+ --junitxml=junit-core.xml \
+ $PYTEST_ARGS
fi
exit_code=$?
set -e
@@ -1303,7 +1591,7 @@ jobs:
- name: Run Temporal tests
id: run-temporal-tests
if: ${{ needs.changes.outputs.backend == 'true' && matrix.segment == 'Temporal' }}
- shell: bash
+ shell: 'signal-fanout bash --noprofile --norc -eo pipefail {0}'
env:
AWS_S3_ALLOW_UNSAFE_RENAME: 'true'
MODAL_TOKEN_ID: ${{ needs.changes.outputs.tasks_temporal == 'true' && secrets.MODAL_TOKEN_ID || '' }}
@@ -1313,6 +1601,16 @@ jobs:
run: |
unset GITHUB_TOKEN # reserved var injected by Depot CI; can't override via env: (see workflow env note)
set +e
+ # Pick the split algorithm and granularity at runtime (see Run Core tests).
+ SPLITTING_ALGORITHM=duration_based_chunks
+ SPLIT_GRANULARITY=()
+ if python -c "from pytest_split.algorithms import Algorithms; from pytest_split.plugin import PytestSplitFilePlugin; raise SystemExit(0 if 'optimal_chunks' in Algorithms.names() else 1)" 2>/dev/null; then
+ SPLITTING_ALGORITHM=optimal_chunks
+ SPLIT_GRANULARITY=(--split-granularity=file)
+ if [ -f .test_durations.temporal ] && python -c "from pytest_split.plugin import SUPPORTS_SPLIT_PLAN_PATH" 2>/dev/null; then
+ SPLIT_GRANULARITY+=(--split-plan-path .test_durations.temporal)
+ fi
+ fi
# Depot-only quarantine: the data-modeling materialize path (get_s3_client) 403s on
# MinIO on Depot-native CI only — MinIO itself is reachable with the standard test creds
# (verified via boto3 LIST/CREATE/HEAD), so root cause is env-specific and not yet
@@ -1321,31 +1619,32 @@ jobs:
# The --deselect guards stay on both branches so a selected run can't re-enable them.
if [[ "$MODE" == "selected" ]]; then
# Selected mode: no sharding, no --reruns (fail loud; the ready full
- # run still reruns). See the core selected branch for the rationale. Snapshot
- # flags kept to match the depot shadow's full branch.
+ # run still reruns). See the core selected branch for the rationale.
# shellcheck disable=SC2086
pytest -v --tb=short --reuse-db -o junit_duration_report=call $TEMPORAL_FILES -m "not async_migrations" \
--deselect "posthog/temporal/tests/data_modeling/test_run_workflow.py::test_run_workflow_with_minio_bucket" \
--deselect "posthog/temporal/tests/data_modeling/test_run_workflow.py::test_run_workflow_timeout_does_not_pause_schedule_without_consecutive_failures" \
--deselect "posthog/temporal/tests/data_modeling/test_run_workflow.py::test_run_workflow_timeout_pauses_schedule_after_5_consecutive_failures" \
- --snapshot-update --snapshot-warn-unused \
-r fEsxX \
- --junitxml=junit-temporal.xml
+ --junitxml=junit-temporal.xml \
+ $PYTEST_ARGS
else
# No per-test pytest --timeout; rely on the job-level timeout-minutes as the single
# safety net (matches canonical — the per-test guillotine added nothing over it,
# since --timeout-method=thread os._exit()s the whole process anyway).
- pytest -v --tb=short --reuse-db -o junit_duration_report=call posthog/temporal products/batch_exports/backend/tests/temporal products/tasks/backend/temporal -m "not async_migrations" \
+ pytest -v --tb=short --reuse-db -o junit_duration_report=call posthog/temporal products/batch_exports/backend/tests/temporal products/tasks/backend/temporal products/warehouse_sources/backend/temporal products/signals/backend/emission -m "not async_migrations" \
--deselect "posthog/temporal/tests/data_modeling/test_run_workflow.py::test_run_workflow_with_minio_bucket" \
--deselect "posthog/temporal/tests/data_modeling/test_run_workflow.py::test_run_workflow_timeout_does_not_pause_schedule_without_consecutive_failures" \
--deselect "posthog/temporal/tests/data_modeling/test_run_workflow.py::test_run_workflow_timeout_pauses_schedule_after_5_consecutive_failures" \
- --snapshot-update --snapshot-warn-unused \
--splits ${{ matrix.concurrency }} --group ${{ matrix.group }} \
--durations=100 --durations-min=1.0 \
- --splitting-algorithm=duration_based_chunks \
+ --pytest-durations=100 \
+ --splitting-algorithm="$SPLITTING_ALGORITHM" \
+ "${SPLIT_GRANULARITY[@]}" \
--reruns 2 --reruns-delay 1 \
-r fEsxX \
- --junitxml=junit-temporal.xml
+ --junitxml=junit-temporal.xml \
+ $PYTEST_ARGS
fi
exit_code=$?
set -e
@@ -1357,14 +1656,14 @@ jobs:
fi
# Post tests
- name: Show docker compose logs on failure
- if: failure() && (needs.changes.outputs.backend == 'true' && steps.run-core-tests.outcome != 'failure' && steps.run-decide-read-replica-tests.outcome != 'failure' && steps.run-temporal-tests.outcome != 'failure')
+ if: failure() && (needs.changes.outputs.backend == 'true' && steps.run-core-tests.outcome != 'failure' && steps.run-temporal-tests.outcome != 'failure')
shell: bash
run: docker compose -f docker-compose.dev.yml logs
- # Aggregate and commit snapshot changes from all matrix jobs
+ # Read ClickHouse versions for the compat test matrix.
get_clickhouse_versions:
name: Get ClickHouse versions
needs: [changes]
- if: needs.changes.outputs.backend == 'true'
+ if: needs.changes.outputs.backend == 'true' && github.event_name != 'push'
runs-on: depot-ubuntu-latest # was: ubuntu-latest. Mapped standard GitHub runner to Depot equivalent.
timeout-minutes: 5
outputs:
@@ -1430,13 +1729,13 @@ jobs:
fi
# Job just to collate the status of the matrix jobs for requiring passing status
django_tests:
- needs: [django, check-migrations, async-migrations, turbo-discover, turbo-tests, repo-checks]
- name: Django Tests Pass
+ needs: [sample, django, check-migrations, async-migrations, turbo-discover, turbo-tests, repo-checks]
+ name: '[optional, does not block merge] Django Tests Pass'
runs-on: depot-ubuntu-latest # was: ubuntu-latest. Mapped standard GitHub runner to Depot equivalent.
timeout-minutes: 5
- # always() collates skipped/failed matrix jobs; gated so it doesn't spin up a
- # lone runner when the shadow is off.
- if: always() && vars.CI_ENABLE_DEPOT_SHADOW == 'true'
+ # always() collates skipped/failed matrix jobs; gated on the sampling result so it
+ # doesn't spin up a lone runner when this run was sampled out (or the shadow is off).
+ if: always() && needs.sample.outputs.sampled == 'true'
steps:
- name: Summarize dependency results
run: |
@@ -1489,6 +1788,7 @@ jobs:
# Run if legacy code changed, product changes affect legacy, or turbo-discover failed
if: |
always() &&
+ github.event_name != 'push' &&
needs.changes.outputs.backend == 'true' &&
(needs.changes.outputs.legacy == 'true' ||
needs.turbo-discover.outputs.run_legacy == 'true' ||
@@ -1544,12 +1844,6 @@ jobs:
with:
toolchain: 1.91.1
components: cargo
- - name: Cache Rust dependencies
- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
- with:
- shared-key: 'v2-rust-backend'
- workspaces: rust
- save-if: ${{ github.ref == 'refs/heads/master' }}
- name: Install sqlx-cli
uses: ./.depot/actions/setup-sqlx-cli
- name: Install python dependencies
@@ -1578,7 +1872,10 @@ jobs:
uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
path: schema.sql.gz
- key: ${{ needs.turbo-discover.outputs.schema_cache_key }}
+ # Prefer the shared content key; fall back to the exact merge-base SHA key.
+ key: ${{ needs.turbo-discover.outputs.schema_migrations_key || needs.turbo-discover.outputs.schema_cache_key }}
+ restore-keys: |
+ ${{ needs.turbo-discover.outputs.schema_cache_key }}
- name: Prime test_posthog from cached schema
# No-op on cache miss; pytest --reuse-db falls back to a full migrate.
if: ${{ github.event_name == 'pull_request' }}
@@ -1589,7 +1886,9 @@ jobs:
fi
mkdir -p .postgres-backups
mv schema.sql.gz .postgres-backups/schema-latest.sql.gz
- ./bin/hogli db:restore-test-db
+ if ! ./bin/hogli db:restore-test-db; then
+ echo "::warning::Schema restore failed (stale/incompatible cached dump?) — pytest --reuse-db will run a full migrate"
+ fi
- name: Run async migrations tests
run: |
# Scope async migration tests directly and reuse the primed test database.
diff --git a/.github/workflows/ci-backend-shadow-drift.yml b/.github/workflows/ci-backend-shadow-drift.yml
index 8d2236efb8bf..393064afdb9d 100644
--- a/.github/workflows/ci-backend-shadow-drift.yml
+++ b/.github/workflows/ci-backend-shadow-drift.yml
@@ -6,12 +6,12 @@ name: Backend CI shadow drift check
# without this check, canonical drifts silently and the depot timing trial stops
# measuring the same work.
#
-# Cheap to run — only triggers when one of the two files changes. Gated on the
-# CI_ENABLE_DEPOT_SHADOW GitHub repository variable so drift enforcement tracks the
-# shadow's on/off state — no point keeping the shadow in sync while it is off. This
-# workflow runs on GitHub Actions, so its `vars` come from GitHub (Settings →
-# Secrets and variables → Actions → Variables), separate from the same-named Depot
-# CI variable that gates the shadow itself.
+# Cheap to run — only triggers when one of the two files changes, so it costs ~nothing.
+# Always enforced (no variable gate): keeping the depot mirror in sync with canonical is
+# a structural invariant worth holding whether or not the shadow is currently sampling —
+# you want them already in sync the moment the shadow is switched on. The sampling rate
+# lives in the CI_DEPOT_SHADOW_PERCENT Depot CI variable, which this check deliberately
+# does not read.
on:
pull_request:
@@ -29,7 +29,6 @@ concurrency:
jobs:
check:
name: Both ci-backend files updated together
- if: vars.CI_ENABLE_DEPOT_SHADOW == 'true'
runs-on: ubuntu-latest
# 5 min absorbs cold-runner startup + the explicit depth=100 fetch of BASE_SHA below.
# `actions/checkout` defaults to depth=1 (HEAD only); a full-history clone is unnecessary