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(e2e): cache schema setup on manual runs (#106273)

Raúl Negrón-Oterob004b2644fdd
diff --git a/.github/workflows/ci-e2e-playwright.yml b/.github/workflows/ci-e2e-playwright.yml
index c9dcf857ddd8..5d69b14e52c3 100644
--- a/.github/workflows/ci-e2e-playwright.yml
+++ b/.github/workflows/ci-e2e-playwright.yml
@@ -299,24 +299,24 @@ jobs:
- name: Compute schema cache keys
id: schema-key
- # Both PRs and master pushes restore the schema dump ci-backend saves on
+ # Every run restores the schema dump ci-backend saves on
# master push, skipping the replay of the full migration history —
# the migrate step in the heavy job still layers on anything newer. On a PR
- # the migration-set key is the merge-base's; on a master push it's HEAD's.
+ # the migration-set key is the merge-base's; on a push or dispatch it's HEAD's.
# ci-backend already validates the full history on every master push (it's
# what saves the cache), so replaying it here too bought nothing. A cache
# miss falls through to a full migrate, so an absent/wrong key is never a
# correctness risk.
- if: steps.decide.outputs.shouldRun == 'true' && (github.event_name == 'pull_request' || github.event_name == 'push')
+ if: steps.decide.outputs.shouldRun == 'true'
env:
BASE_REF: ${{ github.event.pull_request.base.ref }}
- IS_PUSH: ${{ github.event_name == 'push' }}
+ IS_PR: ${{ github.event_name == 'pull_request' }}
# Manual cache-bust knob — keep in sync with SCHEMA_CACHE_EPOCH in
# ci-backend.yml, which saves these caches on master pushes.
SCHEMA_CACHE_EPOCH: v2
run: |
- if [ "$IS_PUSH" = "true" ]; then
- # Pushed commit is checked out directly — no merge commit, no base ref.
+ if [ "$IS_PR" != "true" ]; then
+ # Pushed or dispatched commit is checked out directly: no merge commit, no base ref.
# The per-SHA key points at this same push's cache (saved concurrently
# by ci-backend, so racy); rely on the stable migration-set key below.
REF=HEAD
@@ -349,8 +349,9 @@ jobs:
# commit: a stale checkout can lack migrations the newest dump records,
# and the migrate top-ups only apply forward, so they cannot repair a
# dump that is newer than the code.
+ # Dispatches can target arbitrary revisions, so require an exact key.
HEAD_AGE_SECONDS=$(( $(date +%s) - $(git show -s --format=%ct HEAD) ))
- if [ "$HEAD_AGE_SECONDS" -lt 86400 ]; then
+ if [ "$GITHUB_EVENT_NAME" != "workflow_dispatch" ] && [ "$HEAD_AGE_SECONDS" -lt 86400 ]; then
echo "prefix_key=posthog-schema-mig-${SCHEMA_CACHE_EPOCH}-" >> $GITHUB_OUTPUT
fi
# Shared migration-set key: mirrors the save-side computation in
@@ -810,14 +811,14 @@ jobs:
uses: ./.github/actions/setup-sqlx-cli
- name: Restore schema cache from master
- # PRs and master pushes alike. Both keys are produced by ci-backend on
- # master push. Prefer the shared migration-set key (stable while master's
- # migration files are unchanged); fall back to the exact merge-base SHA key
- # (PRs only), then to the newest dump of any migration set — right after a
- # migration lands on master both exact keys miss until ci-backend re-dumps,
- # and the migrate step below tops a slightly stale dump up in seconds.
- # Cache miss falls through to a full migrate below.
- if: (github.event_name == 'pull_request' || github.event_name == 'push') && (needs.changes.outputs.schema_migrations_key != '' || needs.changes.outputs.schema_cache_key != '')
+ # Both keys are produced by ci-backend on master push. Prefer the shared
+ # migration-set key (stable while master's migration files are unchanged);
+ # fall back to the exact merge-base SHA key (PRs only), then to the newest
+ # dump of any migration set (not on dispatch). Right after a migration lands
+ # on master both exact keys miss until ci-backend re-dumps, and the migrate
+ # step below tops a slightly stale dump up in seconds.
+ # A missing or failed cache download falls through to a full migrate below.
+ if: needs.changes.outputs.schema_migrations_key != '' || needs.changes.outputs.schema_cache_key != ''
uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
id: schema-cache
with:
@@ -836,7 +837,6 @@ jobs:
# the historical migration work. Treat cache/restore problems as misses:
# restore-schema-fresh leaves a fresh empty db on failure, so the migrate
# step below runs the full history.
- if: github.event_name == 'pull_request' || github.event_name == 'push'
env:
TARGET_DB: posthog_e2e_test
run: |
diff --git a/tools/workflow-plan/tests/workflows.test.ts b/tools/workflow-plan/tests/workflows.test.ts
index 764bddd7b556..3dfe40637fd2 100644
--- a/tools/workflow-plan/tests/workflows.test.ts
+++ b/tools/workflow-plan/tests/workflows.test.ts
@@ -466,19 +466,40 @@ interface StepExpectation {
runs: boolean
}
-const STEP_EXPECTATIONS: StepExpectation[] = PINNED_WORKFLOWS.flatMap((file) => [
- { file, job: 'changes', step: 'filter', scenario: { name: 'ready PR', github: pullRequest() }, runs: true },
- { file, job: 'changes', step: 'filter', scenario: { name: 'master push', github: push() }, runs: false },
- { file, job: 'changes', step: 'filter', scenario: { name: 'hourly schedule', github: schedule() }, runs: false },
- { file, job: 'changes', step: 'app-token', scenario: { name: 'ready PR', github: pullRequest() }, runs: true },
- {
- file,
- job: 'changes',
- step: 'app-token',
- scenario: { name: 'fork PR', github: pullRequest({ fork: true }) },
- runs: false,
+const E2E_DISPATCH: Scenario = {
+ name: 'manual dispatch',
+ github: workflowDispatch('feat/example'),
+ steps: {
+ changes: {
+ decide: { outputs: { shouldRun: 'true' } },
+ 'schema-key': { outputs: { migrations_key: 'posthog-schema-mig-test' } },
+ },
},
-])
+}
+
+const STEP_EXPECTATIONS: StepExpectation[] = [
+ ...PINNED_WORKFLOWS.flatMap((file) => [
+ { file, job: 'changes', step: 'filter', scenario: { name: 'ready PR', github: pullRequest() }, runs: true },
+ { file, job: 'changes', step: 'filter', scenario: { name: 'master push', github: push() }, runs: false },
+ {
+ file,
+ job: 'changes',
+ step: 'filter',
+ scenario: { name: 'hourly schedule', github: schedule() },
+ runs: false,
+ },
+ { file, job: 'changes', step: 'app-token', scenario: { name: 'ready PR', github: pullRequest() }, runs: true },
+ {
+ file,
+ job: 'changes',
+ step: 'app-token',
+ scenario: { name: 'fork PR', github: pullRequest({ fork: true }) },
+ runs: false,
+ },
+ ]),
+ { file: 'ci-e2e-playwright.yml', job: 'changes', step: 'schema-key', scenario: E2E_DISPATCH, runs: true },
+ { file: 'ci-e2e-playwright.yml', job: 'playwright', step: 'schema-cache', scenario: E2E_DISPATCH, runs: true },
+]
const namedJobs = (file: string): Set<string> =>
new Set(