: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): shift test timing updates to daily cache with monthly commits (#64464)
Julian Bez2cd6738f219a
diff --git a/.github/workflows/ci-backend-update-test-timing.yml b/.github/workflows/ci-backend-update-test-timing.ymlindex cf68a9bf21ca..147f86de3f79 100644--- a/.github/workflows/ci-backend-update-test-timing.yml+++ b/.github/workflows/ci-backend-update-test-timing.yml@@ -12,8 +12,14 @@ on:required: falsetype: stringschedule:- # Run weekly on Sunday at 3am UTC- - cron: '0 3 * * 0'+ # Daily: merge the latest CI timing artifacts and refresh the Actions cache that+ # ci-backend / ci-dagster restore for sharding. This is the day-to-day freshness.+ - cron: '0 3 * * *'+ # Monthly (1st): same merge, but this run also commits the .test_durations fallback+ # via PR. The committed file is only the cold-start / cache-miss floor, so it doesn't+ # need a daily commit. Distinguished from the daily run via github.event.schedule+ # below — keep this string in sync with the should_commit check.+ - cron: '0 4 1 * *'permissions:contents: write@@ -197,6 +203,41 @@ jobs:# belt-and-braces guard.rm -rf timing_artifacts junit_artifacts /tmp/core_durations /tmp/temporal_durations /tmp/products_durations /tmp/dagster_durations+ - name: Compute cache key and monthly-commit flag+ id: durations-meta+ env:+ EVENT_NAME: ${{ github.event_name }}+ REF: ${{ github.ref }}+ SCHEDULE: ${{ github.event.schedule }}+ run: |+ # Per-day cache key → one new entry per day. Restores match by prefix and only+ # ever touch the newest entry, so each prior day's entry ages out 7 days after+ # it stops being newest: up to ~7 daily entries (~1 MB zstd each, ~7 MB total)+ # coexist before eviction. Tiny, self-pruning, no shared-budget pressure.+ echo "cache_key=posthog-test-durations-$(date -u +%F)" >> "$GITHUB_OUTPUT"+ # Every run refreshes the cache; only the monthly cron (or a manual dispatch)+ # also commits the repo fallback, so the daily runs don't churn the 11 MB file.+ # SCHEDULE is the cron that triggered the run — keep it in sync with the monthly+ # entry under `on.schedule`. Gated to master so a workflow_dispatch on another+ # branch can't reset chore/update-test-timings to a non-master SHA and open a PR+ # full of unrelated diffs (the cache still saves on any branch).+ if [ "$REF" = "refs/heads/master" ] && { [ "$EVENT_NAME" = "workflow_dispatch" ] || [ "$SCHEDULE" = "0 4 1 * *" ]; }; then+ echo "should_commit=true" >> "$GITHUB_OUTPUT"+ else+ echo "should_commit=false" >> "$GITHUB_OUTPUT"+ fi++ - name: Save test durations to Actions cache+ # The merged file is the source of truth for PR + master sharding (ci-backend and+ # ci-dagster restore it by the posthog-test-durations- prefix). Scheduled/dispatch+ # runs are on master, so the cache is readable from every branch. Saved every run;+ # a same-day key is an immutable no-op.+ uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3+ continue-on-error: true+ with:+ path: .test_durations+ key: ${{ steps.durations-meta.outputs.cache_key }}+- name: Check for changesid: check-changesrun: |@@ -221,9 +262,10 @@ jobs:env:GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}- # On schedule/dispatch: clean up stale branch if no changes+ # On schedule/dispatch: clean up stale branch if no changes. Gated to the monthly+ # commit window so a mid-month "no diff" day can't close the open monthly PR.- name: Clean up stale branch- if: steps.check-changes.outputs.changed == 'false' && github.event_name != 'pull_request'+ if: steps.check-changes.outputs.changed == 'false' && github.event_name != 'pull_request' && steps.durations-meta.outputs.should_commit == 'true'env:GH_TOKEN: ${{ steps.app-token.outputs.token }}run: |@@ -240,7 +282,7 @@ jobs:# matches workspace HEAD — otherwise a merge to master during the run could# leave ghcommit-action with a parent mismatch and the same# "Expected branch to point to X but it did not" failure mode.- if: steps.check-changes.outputs.changed == 'true' && github.event_name != 'pull_request'+ if: steps.check-changes.outputs.changed == 'true' && github.event_name != 'pull_request' && steps.durations-meta.outputs.should_commit == 'true'env:GH_TOKEN: ${{ steps.app-token.outputs.token }}TARGET_SHA: ${{ github.sha }}@@ -256,7 +298,7 @@ jobs:# On schedule/dispatch: commit to a branch and create a PR- name: Commit via GitHub API (signed)- if: steps.check-changes.outputs.changed == 'true' && github.event_name != 'pull_request'+ if: steps.check-changes.outputs.changed == 'true' && github.event_name != 'pull_request' && steps.durations-meta.outputs.should_commit == 'true'uses: planetscale/ghcommit-action@25309d8005ac7c3bcd61d3fe19b69e0fe47dbdde # v0.2.20with:commit_message: 'chore(ci): update backend and dagster test timings'@@ -267,7 +309,7 @@ jobs:GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}- name: Create pull request- if: steps.check-changes.outputs.changed == 'true' && github.event_name != 'pull_request'+ if: steps.check-changes.outputs.changed == 'true' && github.event_name != 'pull_request' && steps.durations-meta.outputs.should_commit == 'true'env:GH_TOKEN: ${{ steps.app-token.outputs.token }}BACKEND_RUN_ID: ${{ steps.find-backend-run.outputs.run_id }}diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.ymlindex b11d4e94788b..d660b444f449 100644--- a/.github/workflows/ci-backend.yml+++ b/.github/workflows/ci-backend.yml@@ -423,6 +423,19 @@ jobs:- name: Install pnpm dependenciesrun: pnpm install --frozen-lockfile --filter=@posthog/root+ - name: Restore test durations from cache+ # Shard counts are derived from .test_durations (Amdahl). Restore the newest+ # cache (refreshed daily by ci-backend-update-test-timing.yml) over the+ # committed file so counts track current timings; on a miss the committed file+ # is the fallback. turbo-discover.js disables sharding gracefully if it's absent.+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3+ with:+ path: .test_durations+ # run_id never matches — forces the prefix restore-key to the newest entry.+ key: posthog-test-durations-${{ github.run_id }}+ restore-keys: |+ posthog-test-durations-+- name: Discover products to testid: discoverenv:@@ -759,6 +772,18 @@ jobs:bin/wait-for-docker temporalpython manage.py register_temporal_search_attributes+ - name: Restore test durations from cache+ # pytest-split distributes this product's tests across shards using+ # .test_durations. Restore the newest cache (refreshed daily) over the committed+ # file; a miss leaves the committed fallback and pytest-split still runs.+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3+ with:+ path: .test_durations+ # run_id never matches — forces the prefix restore-key to the newest entry.+ key: posthog-test-durations-${{ github.run_id }}+ restore-keys: |+ posthog-test-durations-+- 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@@ -2231,6 +2256,18 @@ jobs:mv schema.sql.gz .postgres-backups/schema-latest.sql.gz./bin/hogli db:restore-test-db+ - name: Restore test durations from cache+ # pytest-split distributes Core/Temporal tests across shards using+ # .test_durations. Restore the newest cache (refreshed daily) over the committed+ # file; a miss leaves the committed fallback and pytest-split still runs.+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3+ with:+ path: .test_durations+ # run_id never matches — forces the prefix restore-key to the newest entry.+ key: posthog-test-durations-${{ github.run_id }}+ restore-keys: |+ posthog-test-durations-+- name: Determine if --snapshot-update should be on# UPDATE mode: human commits - update snapshots# CHECK mode: bot commits (after snapshot update) - verify snapshots match exactlydiff --git a/.github/workflows/ci-dagster.yml b/.github/workflows/ci-dagster.ymlindex 3ff6a031e0d5..c2dc882538c9 100644--- a/.github/workflows/ci-dagster.yml+++ b/.github/workflows/ci-dagster.yml@@ -380,6 +380,19 @@ jobs:- name: Run clickhouse migrationsrun: python manage.py migrate_clickhouse+ - name: Restore test durations from cache+ # pytest-split distributes Dagster tests across shards using .test_durations.+ # Restore the newest cache (refreshed daily by ci-backend-update-test-timing.yml,+ # which merges all segments into one file) over the committed file; a miss leaves+ # the committed fallback and pytest-split still runs.+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3+ with:+ path: .test_durations+ # run_id never matches — forces the prefix restore-key to the newest entry.+ key: posthog-test-durations-${{ github.run_id }}+ restore-keys: |+ posthog-test-durations-+- name: Run Dagster testsrun: |pytest posthog/dags products/**/dags \