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): revert the backend gate move to depot (#117140)

Raúl Negrón-Oteroa009cd56453c
diff --git a/.agents/skills/authoring-ci-workflows/SKILL.md b/.agents/skills/authoring-ci-workflows/SKILL.md
index db9d71b225e8..f111346c327c 100644
--- a/.agents/skills/authoring-ci-workflows/SKILL.md
+++ b/.agents/skills/authoring-ci-workflows/SKILL.md
@@ -361,7 +361,7 @@ Make those runs pass, and never let untrusted code reach a secret.
- Comment or label only on same-repo PRs — the fork token can't write.
- To act on a fork PR with secrets/write (reviewer or label bots), use `pull_request_target`: base-repo permissions, but it must **never check out and run fork code**. That's why those workflows can't fold into a `pull_request` parent.
- First-time contributors need maintainer approval before workflows run (`action_required`) — expected.
-- Depot CI runs no fork PR at all, so a fork PR never gets the required backend check and is re-created in-repo after review. Never re-push a fork's head in-repo to get it a Depot run before that review. See [Pull requests from forks](../../../docs/published/handbook/engineering/fork-pull-requests.md).
+- Depot CI runs no fork PR at all, so the backend router keeps fork PRs on GitHub Actions and the required check stays on the head. Never re-push a fork's head in-repo to get it a Depot run. See [Pull requests from forks](../../../docs/published/handbook/engineering/fork-pull-requests.md).
## Timeouts
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.yml
index 58a635ac1e17..3022460f3c4c 100644
--- a/.depot/workflows/ci-backend.yml
+++ b/.depot/workflows/ci-backend.yml
@@ -1,6 +1,6 @@
# Depot CI copy of .github/workflows/ci-backend.yml. Lives under .depot/ so
-# GitHub Actions ignores it; only Depot CI parses this file. Depot CI runs every
-# pull request event here, and the gate job's own check is the required one.
+# GitHub Actions ignores it; only Depot CI parses this file. Canonical's required
+# `Django Tests Pass` relays this workflow's gate for the events routed here.
#
# Apples-to-apples is the whole point — keep action pins, env vars, runner
# sizes, and pytest flags in sync with the canonical workflow. A drift-check
@@ -8,9 +8,16 @@
# changes without a matching depot bump.
#
# Intentional deltas vs canonical (everything else is kept apples-to-apples):
-# - Every pull request event runs here. Canonical runs no backend tests on pull requests;
-# its `Django Tests Pass` job only points at this workflow. Depot's own checks carry no
-# output, so the gate posts a `Test results` check with the failure summary.
+# - The `wait-for-handoff` job waits for GitHub Actions to hand the event off and exposes
+# `handed_off`, true only when GitHub Actions handed the tests to this engine. Canonical's
+# `Django Tests Pass` gate then relays this workflow's gate verdict. Its first step posts the
+# `Depot run started` check that canonical's router waits for. Neither the router, the
+# hand-off job, nor the relay has a counterpart here. A GitHub rerun does not restart this
+# workflow, so a re-run of the relay job retries this workflow's failed and cancelled jobs with
+# `depot ci retry`.
+# The relay's failure log prints the label that sends the PR back to GitHub Actions, and each
+# failed step and its log lines, read with `depot ci diagnose`, because Depot's own checks
+# carry no output.
# - runs-on: depot-* labels instead of GitHub-hosted ubuntu-24.04
# - turbo-discover adds the `origin` remote before its history fetch when it is missing.
# Depot CI serves an input-less actions/checkout from a fast clone that has no remote.
@@ -36,7 +43,8 @@
# - Artifact uploads, run-scoped sharding plans, and the failing-test rollup
# require side effects, including duration writes. Depot stores these separately
# from GitHub Actions.
-# - Hourly scheduled master run: only this workflow has the `schedule` trigger. Every `schedule` arm
+# - Hourly scheduled master run: only this workflow has the `schedule` trigger, so the run
+# needs no hand-off and `wait-for-handoff` accepts it outright. Every `schedule` arm
# here is depot-only: the paths-filter skip, the `!= 'schedule'` gates on the per-commit
# checks, the events_json cron in build_django_matrix, the events schema recording and
# its upload, and POSTHOG_PYTEST_HARD_EXIT.
@@ -55,11 +63,12 @@
# .github/scripts/capture_depot_running_time.py reads the workflow with `depot ci workflow show`
# and DEPOT_CI_CANCEL_TOKEN, then sends the same events with the same property keys and
# runner `depot-ci`. Its attempt guard sits on the steps, as canonical's does.
-# - The workflow name is part of the required check's name, so renaming it means changing
-# the ruleset.
+# - Workflow-name expressions remain literal, so the role cannot switch names through a
+# variable; the cutover renames the workflow in a plain edit. The gate's hand-off `&&`
+# is safe only while its status remains optional.
# - events_json variants: the doubled matrices are gated on the test-new-events-schema label
# only; canonical also doubles them on workflow_dispatch, but a shadow dispatch runs the
-# events_json rows instead, so trial runs match PR runs
+# events_json rows instead, so trial runs match handed-off PR runs
# - per-segment split plans (.test_durations.core/.temporal): the restore steps mirror
# canonical but miss until the depot timing refresher saves those files to Depot Cache;
# shards fall back to the union .test_durations
@@ -67,7 +76,7 @@
# so shared keys with canonical (schema, uv, pnpm) do not collide
# - hypothesis constants cache: the restore and save steps mirror canonical verbatim, but the
# save only fires on master test-matrix runs and the shadow skips those, so the Depot Cache
-# entry only exists after a master workflow_dispatch. PR shards run cold (they rebuild
+# entry only exists after a master workflow_dispatch. Routed PR shards run cold (they rebuild
# the pool, as canonical did before this cache existed) until then: bounded and documented.
# - GITHUB_TOKEN / OTEL_SERVICE_NAME neutralized (ambient on Depot, not on GHA)
# - GitHub App tokens: the mint steps' vars.* / secrets.* resolve from Depot's store, not
@@ -82,7 +91,8 @@
# does not attach them to the job's GitHub check run. The file annotations from
# `hogli lint:migration-deletions` therefore have no GitHub counterpart here; the failing
# Repo checks run carries the verdict.
-# - `depot ci run` fires with event_name `api`, which the `workflow_dispatch` arms cover.
+# - `depot ci run` fires with event_name `api`; the hand-off wait treats it like
+# workflow_dispatch: it runs only when GitHub Actions already handed the commit off.
# Depot caps an inline workflow at 64 KiB, which this file exceeds, so
# trial a branch with `depot ci dispatch --workflow ci-backend.yml --ref <branch>` instead.
# - Three data-modeling tests deselected (Depot-only MinIO 403 quarantine)
@@ -117,6 +127,8 @@
# fallback.
# - No push trigger: canonical primes the shared schema cache on master, and Depot Cache
# serves both engines. The `github.event_name != 'push'` guards stay to mirror canonical.
+# Trunk merge-queue PRs run here only when canonical's router hands them off, which its own
+# CI_BACKEND_DEPOT_MERGE_QUEUE_PERCENT controls apart from source PRs.
# - Fresh-master cache waiting is canonical-only: it waits on the GitHub Actions
# warmer, which cannot signal readiness for Depot's separate cache channel.
@@ -125,17 +137,22 @@
# Shards derive from .test_durations (Amdahl), restored from Depot Cache (else committed);
# .github/workflows/ci-backend-update-test-timing.yml keeps that cache fresh.
name: Backend CI on Depot
-# Depot CI copy of canonical Backend CI. Branch protection requires this workflow's gate,
-# `Backend CI on Depot / Django Tests Pass on Depot`, posted by the Depot Code Access app.
-# Pull requests, manual runs and the hourly master run start here on their own; canonical
-# keeps the master push.
+# Depot CI copy of canonical Backend CI. Branch protection requires only canonical's
+# `Django Tests Pass`, which relays this workflow's gate when the event ran here. Each event runs on
+# exactly one engine, and GitHub Actions picks it. The `wait-for-handoff` job waits for the
+# `Hand off backend tests to Depot CI` check from .github/workflows/ci-backend.yml and
+# `changes` (root of the needs graph) only runs when that check succeeded, so the whole
+# workflow cascades off otherwise. A manual run needs that check on its commit too.
+# The hourly master run is the exception: only this workflow has a schedule trigger, so that
+# run starts here with no hand-off.
# The drift check (.github/workflows/ci-backend-shadow-drift.yml) keeps this file in sync
-# with canonical; it runs whenever either file changes.
+# with canonical; it runs whenever either file changes, independent of the percent.
on:
schedule:
# Hourly full-matrix run against the newest master state. The merge queue's
# trunk-merge/** run already gated every commit before it landed, so this is where
# master's matrix coverage, flaky-test baseline, and per-test timing data come from.
+ # GitHub Actions has no schedule trigger for Backend CI, so this run needs no hand-off.
# Keep the events_json cadence tied to the trigger, even when a job starts late.
- cron: '23 */3 * * *'
- cron: '23 1,2,4,5,7,8,10,11,13,14,16,17,19,20,22,23 * * *'
@@ -151,10 +168,10 @@ on:
# Add the `run-ci-backend` label to force the full matrices on a PR; the
# `no-ci` label silences the workflow on a draft entirely. No
# labeled/unlabeled triggers, so a label takes effect from the next push
- # or from ready_for_review. Every pull request event, merge-queue PRs included,
- # runs here.
+ # or from ready_for_review. Every event, merge-queue PRs included, runs here
+ # only when GitHub Actions hands it off (see the `wait-for-handoff` job).
# The events_json leg runs wherever the legacy tests run, over the paths in
- # .github/new-events-schema-targets.txt, the same as canonical, so a PR
+ # .github/new-events-schema-targets.txt, the same as canonical, so a routed PR
# cannot pass here and fail the queue. The `test-new-events-schema` label runs
# the doubled matrices in place of that leg.
types: [opened, synchronize, reopened, ready_for_review]
@@ -225,6 +242,142 @@ permissions:
actions: read
pull-requests: read
jobs:
+ # GitHub Actions alone decides which engine runs an event. Every other job here
+ # needs this one, so Depot CI runs nothing GitHub Actions did not hand off, and the
+ # tests and their side effects never run on both engines.
+ wait-for-handoff:
+ if: >-
+ github.event_name != 'pull_request'
+ || github.event.pull_request.draft != true
+ || !contains(github.event.pull_request.labels.*.name, 'no-ci')
+ runs-on: depot-ubuntu-24.04
+ timeout-minutes: 15
+ # The check name carries the event, so GitHub Actions can tell this run's checks from other
+ # runs on the commit. .github/scripts/ci_backend_relay.py builds the same name; change both.
+ name: Wait for GitHub Actions to hand off backend tests${{ github.event_name == 'pull_request' && format(' (PR {0}, event {1})', github.event.pull_request.number, github.event.pull_request.updated_at) || '' }}
+ # Depot scopes the ambient token by this block, and the workflow-level block has no
+ # `checks`, so without it the check-runs read below answers 403.
+ permissions:
+ checks: read
+ outputs:
+ handed_off: ${{ steps.handoff.outputs.handed_off }}
+ github_run_url: ${{ steps.handoff.outputs.github_run_url }}
+ steps:
+ # Depot's ambient token can come from an installation spent for the hour. It answers 403,
+ # and the wait would decline a real hand-off. The same token posts the relay's checks.
+ - name: Mint hand-off token
+ id: handoff-token
+ if: contains(fromJSON('["pull_request", "workflow_dispatch", "api"]'), github.event_name) && github.event.pull_request.head.repo.fork != true
+ continue-on-error: true
+ uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
+ with:
+ client-id: ${{ secrets.GH_APP_POSTHOG_TESTS_APP_ID }}
+ private-key: ${{ secrets.GH_APP_POSTHOG_TESTS_PRIVATE_KEY }}
+ permission-checks: write
+ # .github/scripts/ci_backend_route.py waits for this check. Depot posts its own check
+ # for this job only when the job ends, which is after the hand-off.
+ - name: Tell GitHub Actions that Depot started a run for this event
+ if: github.event_name == 'pull_request' && steps.handoff-token.outputs.token != ''
+ continue-on-error: true
+ env:
+ GH_TOKEN: ${{ steps.handoff-token.outputs.token }}
+ REPO: ${{ github.repository }}
+ SHA: ${{ github.event.pull_request.head.sha }}
+ STARTED_CHECK: Backend CI on Depot / Depot run started (PR ${{ github.event.pull_request.number }}, event ${{ github.event.pull_request.updated_at }})
+ run: |
+ gh api "repos/$REPO/check-runs" --method POST -f name="$STARTED_CHECK" -f head_sha="$SHA" \
+ -f status=completed -f conclusion=success -f details_url="$DEPOT_JOB_URL" --silent
+ - name: Wait for the hand-off check from GitHub Actions
+ id: handoff
+ env:
+ GH_TOKEN: ${{ steps.handoff-token.outputs.token || github.token }}
+ REPO: ${{ github.repository }}
+ EVENT: ${{ github.event_name }}
+ IS_FORK: ${{ github.event.pull_request.head.repo.fork == true }}
+ SHA: ${{ github.event.pull_request.head.sha || github.sha }}
+ # A no-ci draft marked ready keeps its SHA, so its earlier skipped hand-off
+ # check is still on the commit. Only a check that started after this event counts.
+ EVENT_AT: ${{ github.event.pull_request.updated_at }}
+ # Two open PRs can share a head SHA, so only this PR's hand-off counts.
+ # A manual run has no PR and accepts the newest hand-off from any PR.
+ PR_NUMBER: ${{ github.event.pull_request.number }}
+ # Must match the job name in .github/workflows/ci-backend.yml.
+ HANDOFF_CHECK: Hand off backend tests to Depot CI
+ GITHUB_ACTIONS_APP_ID: '15368'
+ run: |
+ set -uo pipefail
+ handed_off=false
+ state=absent
+ run_url=
+ # A person's run does not wait: it runs only when GitHub Actions already handed
+ # this commit off, so the tests never run on both engines.
+ attempts=30
+ [ "$EVENT" = pull_request ] || attempts=1
+ if [ "$IS_FORK" = true ]; then
+ # The fork controls its own copy of the GitHub Actions workflow, so its hand-off is not trusted.
+ echo "::notice::Fork pull requests never run on Depot CI."
+ elif [ "$EVENT" = schedule ]; then
+ # Only this workflow has the hourly trigger, so no other engine can run it.
+ handed_off=true
+ echo "::notice::The hourly master run belongs to Depot CI."
+ elif [ "$EVENT" != pull_request ] && [ "$EVENT" != workflow_dispatch ] && [ "$EVENT" != api ]; then
+ # A reused commit can still carry a pull request's hand-off, and GitHub Actions
+ # runs every non-PR event itself.
+ echo "::notice::$EVENT events never run on Depot CI."
+ else
+ url="https://api.github.com/repos/$REPO/commits/$SHA/check-runs?check_name=$(jq -rn --arg n "$HANDOFF_CHECK" '$n | @uri')&app_id=$GITHUB_ACTIONS_APP_ID&filter=all&per_page=100"
+ for attempt in $(seq 1 "$attempts"); do
+ # curl rewrites the saved ETag empty on a 304, so promote it only after a 200.
+ code=$(curl -s -o /tmp/handoff-body -w '%{http_code}' --max-time 15 --etag-compare /tmp/handoff-etag --etag-save /tmp/handoff-etag.new \
+ -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" "$url")
+ case "$code" in
+ 200)
+ mv /tmp/handoff-etag.new /tmp/handoff-etag
+ # A cancelled hand-off comes from a GitHub run that was cancelled before its
+ # hand-off job finished, so it carries no decision, as in ci_backend_route.py.
+ # GitHub posts it with started_at set to the cancel time, which can follow this event.
+ # The hand-off check links its GitHub job. The gate check links the run instead.
+ IFS=$'\t' read -r state run_url < <(jq -r --arg since "$EVENT_AT" --argjson pr "${PR_NUMBER:-null}" '[.check_runs[] | select(.conclusion != "cancelled" and (.started_at // "") >= $since and ($pr == null or any(.pull_requests[]?; .number == $pr)))] | max_by(.id) | [(if . == null then "absent" elif .status == "completed" then .conclusion else .status end), (.details_url // "" | sub("/job/[0-9]+$"; ""))] | @tsv' /tmp/handoff-body)
+ ;;
+ 304) ;;
+ 401|403) echo "::warning::check-runs API returned $code; cannot read the hand-off"; break ;;
+ *) echo "::warning::check-runs API returned $code" ;;
+ esac
+ case "$state" in
+ success) handed_off=true; break ;;
+ absent|queued|in_progress|pending|waiting|requested) ;;
+ *) break ;;
+ esac
+ [ "$attempt" -lt "$attempts" ] && sleep 20
+ done
+ if [ "$handed_off" = true ]; then
+ echo "::notice::GitHub Actions handed the backend tests to Depot CI."
+ echo "github_run_url=$run_url" >> "$GITHUB_OUTPUT"
+ else
+ echo "::notice::GitHub Actions kept the backend tests (hand-off check: $state). Depot CI runs nothing."
+ fi
+ fi
+ echo "handed_off=$handed_off" >> "$GITHUB_OUTPUT"
+ # Mirrors Depot's own checks for .github/scripts/ci_backend_relay.py (see MIRROR_APP_ID).
+ # A declined event also gets the gate's skipped check, as Depot posts it. The mirrored
+ # gate has its own name (see MIRRORED_GATE_CHECK), which differs from the gate job's name.
+ - name: Post the hand-off checks for the relay
+ if: github.event_name == 'pull_request' && steps.handoff-token.outputs.token != ''
+ continue-on-error: true
+ env:
+ GH_TOKEN: ${{ steps.handoff-token.outputs.token }}
+ REPO: ${{ github.repository }}
+ SHA: ${{ github.event.pull_request.head.sha }}
+ WAIT_CHECK: Backend CI on Depot / Wait for GitHub Actions to hand off backend tests (PR ${{ github.event.pull_request.number }}, event ${{ github.event.pull_request.updated_at }})
+ GATE_CHECK: Backend CI on Depot / Test results
+ HANDED_OFF: ${{ steps.handoff.outputs.handed_off }}
+ run: |
+ post() {
+ gh api "repos/$REPO/check-runs" --method POST -f name="$1" -f head_sha="$SHA" \
+ -f status=completed -f conclusion="$2" -f details_url="$DEPOT_JOB_URL" --silent
+ }
+ post "$WAIT_CHECK" success
+ [ "$HANDED_OFF" = true ] || post "$GATE_CHECK" skipped
cancel-superseded-runs:
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
runs-on: depot-ubuntu-24.04
@@ -248,17 +401,10 @@ jobs:
# Job to decide if we should run backend ci
# See .github/actions/paths-filter/README.md for filter semantics
changes:
- # A draft PR labeled `no-ci` skips this workflow entirely (prototypes):
- # every other job needs this one, and the gates treat skipped as success.
- # ready_for_review re-runs everything, so the merge gate is unaffected.
- # A fork never runs here: its code must not reach this workflow's secrets, and the
- # gate fails closed for it below.
- if: >-
- github.event_name != 'pull_request'
- || (github.event.pull_request.head.repo.full_name == github.repository
- && (github.event.pull_request.draft != true
- || startsWith(github.head_ref, 'trunk-merge/')
- || !contains(github.event.pull_request.labels.*.name, 'no-ci')))
+ # Root of the `needs` graph: skipped when `wait-for-handoff` saw no hand-off (or is itself skipped),
+ # which cascades the whole workflow off.
+ needs: wait-for-handoff
+ if: needs.wait-for-handoff.outputs.handed_off == 'true'
runs-on: depot-ubuntu-24.04
timeout-minutes: 5
name: Determine need to run backend and migration checks
@@ -668,7 +814,7 @@ jobs:
# 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]
+ needs: [wait-for-handoff, changes]
# 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-24.04
@@ -886,6 +1032,7 @@ jobs:
enable-cache: false
- name: Snapshot the sharding plan for this run
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' }}
# The timing caches float to their newest entry, so a re-run can shard
# differently from attempt 1 and, under "re-run failed jobs", a failing
# test can move to a shard that never re-runs while the gate goes green.
@@ -960,7 +1107,7 @@ jobs:
# test-selection-verdict reads it instead of running the selector again. An
# upload failure must not fail this job; the verdict regenerates the selection.
continue-on-error: true
- if: ${{ always() && steps.select.outcome == 'success' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (always() && steps.select.outcome == 'success') }}
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: select-tests-output
@@ -1098,6 +1245,7 @@ jobs:
turbo-tests:
needs:
[
+ wait-for-handoff,
changes,
turbo-discover,
prime-schema-cache,
@@ -1279,6 +1427,7 @@ 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: Download the run's sharding plan snapshot
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' }}
# Same pinning as the Django job; falls back to the floating cache.
id: pinned-plan
continue-on-error: true
@@ -1288,7 +1437,7 @@ jobs:
path: /tmp/test-durations-plan
- name: Apply the pinned sharding plan
- if: ${{ steps.pinned-plan.outcome == 'success' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (steps.pinned-plan.outcome == 'success') }}
shell: bash
run: |
if [ ! -f /tmp/test-durations-plan/.test_durations ]; then
@@ -1299,12 +1448,12 @@ jobs:
echo "Sharding plan pinned to this run's snapshot"
- name: Warn when a re-run reshards unpinned
- if: ${{ github.run_attempt != '1' && steps.pinned-plan.outcome != 'success' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (github.run_attempt != '1' && steps.pinned-plan.outcome != 'success') }}
shell: bash
run: echo "::warning::Sharding-plan snapshot unavailable, this re-run reshards from the floating timing cache and may not re-execute tests that failed in earlier attempts"
- name: Run product tests
- continue-on-error: true
+ continue-on-error: ${{ needs.wait-for-handoff.outputs.handed_off == '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
@@ -1339,8 +1488,8 @@ jobs:
PYTEST_ADDOPTS: >-
--reuse-db
--durations-path ../../.test_durations
- ${{ env.IS_MASTER == 'true' && '--store-durations' || '' }}
- --junitxml=junit-product.xml
+ ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && env.IS_MASTER == 'true' && '--store-durations' || '' }}
+ ${{ needs.wait-for-handoff.outputs.handed_off == '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=' || '' }}
# turbo runs each product's backend:test with the product dir as CWD, so --cov=backend
@@ -1395,7 +1544,7 @@ jobs:
- name: Prepare product JUnit for Trunk
id: prepare_product_junit
- if: ${{ always() }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (always()) }}
shell: bash
env:
PRODUCT_FILTERS: ${{ matrix.filters }}
@@ -1407,7 +1556,7 @@ jobs:
- name: Quarantine gate
id: quarantine_gate
continue-on-error: true
- if: ${{ !cancelled() && env.RUNS_ON_INTERNAL_PR == 'true' && github.repository == 'PostHog/posthog' && github.actor != 'dependabot[bot]' && vars.TRUNK_UPLOAD_ENABLED == 'true' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == '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
@@ -1419,12 +1568,12 @@ jobs:
token: ${{ secrets.TRUNK_API_TOKEN }}
- name: Fail on test failure
- if: ${{ !cancelled() && (steps.prepare_product_junit.outcome == 'failure' || (steps.run-product-tests.outcome == 'failure' && (vars.TRUNK_QUARANTINE_ENABLED != 'true' || steps.quarantine_gate.outcome != 'success'))) }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == '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
- name: Stage product JUnit
- if: ${{ always() }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (always()) }}
shell: bash
run: |
mkdir -p junit-staging
@@ -1435,7 +1584,7 @@ jobs:
- name: Upload product test results
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
- if: ${{ always() }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (always()) }}
with:
name: product-junit-results-${{ strategy.job-index }}
path: junit-staging/junit-product-*.xml
@@ -1450,7 +1599,7 @@ jobs:
# timings either. Its artifact would hold only the restored map, and the timing
# refresh then rejects the whole Products slice because the timing and JUnit shard
# sets differ.
- if: ${{ env.IS_MASTER == 'true' && !matrix.new-events-schema && hashFiles('junit-staging/junit-product-*.xml') != '' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (env.IS_MASTER == 'true' && !matrix.new-events-schema && hashFiles('junit-staging/junit-product-*.xml') != '') }}
with:
name: timing_data-Products-${{ strategy.job-index }}
path: .test_durations
@@ -1460,7 +1609,7 @@ jobs:
- name: Stage product coverage
# Rename each products/<name>/.coverage to <name>.coverage so the product name
# survives upload-artifact's least-common-ancestor path collapse.
- if: ${{ always() && github.event_name == 'pull_request' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (always() && github.event_name == 'pull_request') }}
shell: bash
run: |
mkdir -p cov-staging
@@ -1473,7 +1622,7 @@ jobs:
- name: Upload product coverage
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
# always(): a failing test shard still has partial coverage worth reporting.
- if: ${{ always() && github.event_name == 'pull_request' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (always() && github.event_name == 'pull_request') }}
with:
name: coverage-products-${{ strategy.job-index }}
path: cov-staging/*.coverage
@@ -1482,7 +1631,7 @@ jobs:
overwrite: true # artifacts are immutable per run; re-run shards would 409 otherwise
- name: Verify new snapshots for flakiness
- if: ${{ always() && needs.detect-snapshot-mode.outputs.mode == 'update' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (always() && needs.detect-snapshot-mode.outputs.mode == 'update' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog') }}
shell: bash
# The reruns must write the same schema mode's snapshot file as the main
# run, or the new-schema file removed before each rerun never comes back.
@@ -1492,7 +1641,7 @@ jobs:
.github/scripts/verify-new-snapshots.sh
- name: Generate snapshot patch
- if: ${{ always() && needs.detect-snapshot-mode.outputs.mode == 'update' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (always() && needs.detect-snapshot-mode.outputs.mode == 'update' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog') }}
shell: bash
env:
NEW_EVENTS_SCHEMA: ${{ matrix.new-events-schema && 'true' || 'false' }}
@@ -1514,7 +1663,7 @@ jobs:
fi
- name: Upload snapshot patch
- if: ${{ always() && needs.detect-snapshot-mode.outputs.mode == 'update' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (always() && needs.detect-snapshot-mode.outputs.mode == 'update' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog') }}
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: snapshot-patch-Products-${{ strategy.job-index }}
@@ -1737,7 +1886,7 @@ jobs:
# This job needs Docker + DB. Canonical master is checked out beside the comparison
# branch so repository switches cannot disturb live Compose bind mounts.
check-migrations:
- needs: [changes]
+ needs: [wait-for-handoff, changes]
# migration_replay is listed because it reaches files the others miss:
# products/db_routing.yaml is neither Python nor under a backend/ directory, and
# a migration in a future top-level app matches none of them. Without it the
@@ -1908,7 +2057,7 @@ jobs:
# posthog-tests token that can write pull requests and nothing else. When the
# mint fails, the CI report check below marks the report unavailable, so a mint
# failure never reddens migration validation.
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false
+ if: needs.wait-for-handoff.outputs.handed_off == 'true' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false
id: ci-report-app-token
continue-on-error: true
uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
@@ -2118,7 +2267,7 @@ jobs:
# PR code, so that code never holds a token that can publish this check.
# continue-on-error: publishing the check is auxiliary. On failure the
# token output is empty and the publish step below is skipped.
- if: ${{ !cancelled() && github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false }}
+ if: ${{ !cancelled() && needs.wait-for-handoff.outputs.handed_off == 'true' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false }}
id: migration-risk-app-token
continue-on-error: true
uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
@@ -2223,7 +2372,7 @@ jobs:
| gh api "repos/$REPO/check-runs" --method POST --input -
- name: Upload migration analysis artifact
- if: ${{ always() && github.event_name == 'pull_request' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (always() && github.event_name == 'pull_request') }}
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: migration-analysis
@@ -2279,7 +2428,7 @@ jobs:
gunzip -t schema.sql.gz
- name: Upload migrated schema artifact
- if: ${{ github.event_name == 'push' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (github.event_name == 'push') }}
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: migrated-schema
@@ -3064,7 +3213,15 @@ 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:
+ [
+ wait-for-handoff,
+ 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)
@@ -3457,6 +3614,7 @@ jobs:
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" || true
echo "==================================="
- name: Download the run's sharding plan snapshot
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' }}
# Pin every attempt to the plan turbo-discover snapshotted (rationale on
# that step); a missing snapshot falls back to the floating caches above.
id: pinned-plan
@@ -3467,7 +3625,7 @@ jobs:
path: /tmp/test-durations-plan
- name: Apply the pinned sharding plan
- if: ${{ steps.pinned-plan.outcome == 'success' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (steps.pinned-plan.outcome == 'success') }}
shell: bash
run: |
if [ ! -f /tmp/test-durations-plan/.test_durations ]; then
@@ -3483,12 +3641,12 @@ jobs:
echo "Sharding plan pinned to this run's snapshot"
- name: Warn when a re-run reshards unpinned
- if: ${{ github.run_attempt != '1' && steps.pinned-plan.outcome != 'success' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (github.run_attempt != '1' && steps.pinned-plan.outcome != 'success') }}
shell: bash
run: echo "::warning::Sharding-plan snapshot unavailable, this re-run reshards from the floating timing caches and may not re-execute tests that failed in earlier attempts"
- name: Run Core tests
- continue-on-error: true
+ continue-on-error: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' }}
id: run-core-tests
if: ${{ needs.changes.outputs.backend == 'true' && matrix.segment == 'Core' }}
env:
@@ -3645,7 +3803,7 @@ jobs:
--ignore=posthog/test/repo_invariants \
"${full_ignores[@]}" \
--splits ${{ matrix.concurrency }} --group ${{ matrix.group }} \
- --durations=1000 --durations-min=1.0 --store-durations \
+ --durations=1000 --durations-min=1.0 ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && '--store-durations' || '' }} \
--pytest-durations=100 \
--splitting-algorithm="$SPLITTING_ALGORITHM" \
"${SPLIT_GRANULARITY[@]}" \
@@ -3686,7 +3844,7 @@ jobs:
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" || true
echo "==================================="
- name: Run Temporal tests
- continue-on-error: true
+ continue-on-error: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' }}
id: run-temporal-tests
if: ${{ needs.changes.outputs.backend == 'true' && matrix.segment == 'Temporal' }}
shell: 'signal-fanout bash --noprofile --norc -eo pipefail {0}'
@@ -3744,7 +3902,7 @@ jobs:
# no protection beyond the job timeout.
pytest -v --tb=short --reuse-db -o junit_duration_report=call posthog/temporal products/signals/backend/emission -m "not async_migrations" \
--splits ${{ matrix.concurrency }} --group ${{ matrix.group }} \
- --durations=100 --durations-min=1.0 --store-durations \
+ --durations=100 --durations-min=1.0 ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && '--store-durations' || '' }} \
--pytest-durations=100 \
--splitting-algorithm="$SPLITTING_ALGORITHM" \
"${SPLIT_GRANULARITY[@]}" \
@@ -3789,7 +3947,7 @@ jobs:
- name: Upload test results
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
- if: ${{ always() }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (always()) }}
with:
# Re-run attempts suffix the name: a same-name upload supersedes attempt 1's
# artifact, and the timing reporter needs both to pair a re-run recovery
@@ -3801,7 +3959,7 @@ jobs:
- name: Upload events schema recording
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
- if: ${{ always() && matrix.json-targets && github.event_name == 'schedule' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (always() && matrix.json-targets && github.event_name == 'schedule') }}
with:
name: events-schema-record-${{ matrix.artifact_key }}${{ github.run_attempt != '1' && format('-attempt{0}', github.run_attempt) || '' }}
path: events-schema-record.json
@@ -3812,7 +3970,7 @@ jobs:
- name: Archive email renders
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
- if: ${{ needs.changes.outputs.backend == 'true' && matrix.segment == 'Core' && !matrix.person-on-events && !matrix.new-events-schema && !matrix.compat }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (needs.changes.outputs.backend == 'true' && matrix.segment == 'Core' && !matrix.person-on-events && !matrix.new-events-schema && !matrix.compat) }}
with:
name: email_renders-${{ github.sha }}-${{ github.run_attempt }}-${{ matrix.segment }}-${{ matrix.person-on-events }}-${{ matrix.group }}
path: posthog/tasks/test/__emails__
@@ -3820,7 +3978,7 @@ jobs:
- name: Upload core coverage
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
- if: ${{ always() && github.event_name == 'pull_request' && needs.turbo-discover.outputs.mode != 'selected' && matrix.segment == 'Core' && !matrix.json-targets }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (always() && github.event_name == 'pull_request' && needs.turbo-discover.outputs.mode != 'selected' && matrix.segment == 'Core' && !matrix.json-targets) }}
with:
name: coverage-core-${{ strategy.job-index }}
path: .coverage
@@ -3832,7 +3990,7 @@ jobs:
- name: Upload updated timing data as artifacts
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
# Upload on master, or on PRs that change timing/sharding scripts (for validation)
- if: ${{ (env.IS_MASTER == 'true' || needs.changes.outputs.timing_scripts == 'true') && needs.changes.outputs.backend == 'true' && !matrix.person-on-events && !matrix.new-events-schema && matrix.clickhouse-server-image == needs.get_clickhouse_versions.outputs.oldest_supported_image }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && ((env.IS_MASTER == 'true' || needs.changes.outputs.timing_scripts == 'true') && needs.changes.outputs.backend == 'true' && !matrix.person-on-events && !matrix.new-events-schema && matrix.clickhouse-server-image == needs.get_clickhouse_versions.outputs.oldest_supported_image) }}
with:
name: timing_data-${{ matrix.segment }}-${{ matrix.group }}
path: .test_durations
@@ -3841,7 +3999,7 @@ jobs:
- name: Verify new snapshots for flakiness
# Only in UPDATE mode - CHECK mode doesn't update snapshots
- if: ${{ needs.detect-snapshot-mode.outputs.mode == 'update' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog' && needs.changes.outputs.backend == 'true' && !matrix.person-on-events && !matrix.compat && steps.run-core-tests.outcome != 'failure' && steps.run-temporal-tests.outcome != 'failure' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (needs.detect-snapshot-mode.outputs.mode == 'update' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog' && needs.changes.outputs.backend == 'true' && !matrix.person-on-events && !matrix.compat && steps.run-core-tests.outcome != 'failure' && steps.run-temporal-tests.outcome != 'failure') }}
shell: bash
# The reruns must write the same schema mode's snapshot file as the main
# run, or the new-schema file removed before each rerun never comes back.
@@ -3853,7 +4011,7 @@ jobs:
- name: Generate snapshot patch
# Only in UPDATE mode - CHECK mode verifies snapshots match exactly
- if: ${{ needs.detect-snapshot-mode.outputs.mode == 'update' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog' && needs.changes.outputs.backend == 'true' && !matrix.person-on-events && !matrix.compat && steps.run-core-tests.outcome != 'failure' && steps.run-temporal-tests.outcome != 'failure' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (needs.detect-snapshot-mode.outputs.mode == 'update' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog' && needs.changes.outputs.backend == 'true' && !matrix.person-on-events && !matrix.compat && steps.run-core-tests.outcome != 'failure' && steps.run-temporal-tests.outcome != 'failure') }}
shell: bash
env:
NEW_EVENTS_SCHEMA: ${{ matrix.new-events-schema && 'true' || 'false' }}
@@ -3880,7 +4038,7 @@ jobs:
- name: Upload snapshot patch
# Only in UPDATE mode
- if: ${{ needs.detect-snapshot-mode.outputs.mode == 'update' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog' && needs.changes.outputs.backend == 'true' && !matrix.person-on-events && !matrix.compat && steps.run-core-tests.outcome != 'failure' && steps.run-temporal-tests.outcome != 'failure' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (needs.detect-snapshot-mode.outputs.mode == 'update' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog' && needs.changes.outputs.backend == 'true' && !matrix.person-on-events && !matrix.compat && steps.run-core-tests.outcome != 'failure' && steps.run-temporal-tests.outcome != 'failure') }}
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: snapshot-patch-${{ matrix.artifact_key }}
@@ -3890,7 +4048,7 @@ jobs:
# The helper sets TRUNK_CODEOWNERS_PATH so Trunk attributes uploaded tests to their owners.
- name: Build the Trunk ownership map
- if: ${{ !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' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == '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
@@ -3899,7 +4057,7 @@ jobs:
- name: Quarantine gate (Core)
id: quarantine_gate_core
continue-on-error: true
- if: ${{ !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' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == '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
env:
TRUNK_HIDE_TEST_COLLECTION_LINKS: 'true'
@@ -3918,7 +4076,7 @@ jobs:
- name: Quarantine gate (Temporal)
id: quarantine_gate_temporal
continue-on-error: true
- if: ${{ !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' }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == '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
env:
TRUNK_HIDE_TEST_COLLECTION_LINKS: 'true'
@@ -3935,7 +4093,7 @@ jobs:
token: ${{ secrets.TRUNK_API_TOKEN }}
- name: Fail on test failure
- if: ${{ !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'))) }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == '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
@@ -4120,6 +4278,7 @@ jobs:
django_tests:
needs:
[
+ wait-for-handoff,
changes,
get_clickhouse_versions,
build_django_matrix,
@@ -4138,21 +4297,18 @@ jobs:
runs-on: depot-ubuntu-24.04
timeout-minutes: 8
# !cancelled() collates skipped/failed matrix jobs without reporting failure on a
- # superseded run (mirrors canonical).
+ # superseded run (mirrors canonical); gated on the hand-off so it doesn't
+ # spin up a lone runner when GitHub Actions kept this event.
if: >
- !cancelled()
+ (!cancelled()
|| needs.repo-checks.outputs.deterministic_failure == 'true'
- || needs.check-openapi-types.outputs.deterministic_failure == 'true'
+ || needs.check-openapi-types.outputs.deterministic_failure == 'true')
+ && needs.wait-for-handoff.outputs.handed_off == 'true'
env:
# The gate check posts the summary as its output, titled by the first line of the title file.
GATE_SUMMARY: /tmp/gate-check-summary.md
GATE_TITLE: /tmp/gate-check-title
steps:
- - name: Refuse a fork pull request
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
- run: |
- echo "::error::Depot CI does not run fork pull requests. Re-create the change on a branch in this repository after review."
- exit 1
- name: Summarize dependency results
run: |
{
@@ -4182,7 +4338,7 @@ jobs:
} | tee -a "$GITHUB_STEP_SUMMARY" "$GATE_SUMMARY"
- name: Download shard JUnit results
- if: ${{ always() && (needs.django.result != 'success' || needs.turbo-tests.result != 'success') }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (always() && (needs.django.result != 'success' || needs.turbo-tests.result != 'success')) }}
continue-on-error: true
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
@@ -4190,7 +4346,7 @@ jobs:
path: /tmp/junit-gate/
- name: Keep only each shard's latest attempt
- if: ${{ always() && (needs.django.result != 'success' || needs.turbo-tests.result != 'success') }}
+ if: ${{ needs.wait-for-handoff.outputs.handed_off == 'true' && (always() && (needs.django.result != 'success' || needs.turbo-tests.result != 'success')) }}
continue-on-error: true
run: |
cd /tmp/junit-gate 2>/dev/null || exit 0
@@ -4298,6 +4454,7 @@ jobs:
check_required_result "Django test matrix" "${{ needs.django.result }}"
check_required_result "Migration checks" "${{ needs.check-migrations.result }}"
check_required_result "OpenAPI type checks" "${{ needs.check-openapi-types.result }}"
+ check_required_result "Hand-off wait" "${{ needs.wait-for-handoff.result }}"
check_required_result "Repo checks" "${{ needs.repo-checks.result }}"
check_required_result "SDK major guard" "${{ needs.sdk-major-guard.result }}"
check_required_result "Turbo discover" "${{ needs.turbo-discover.result }}"
@@ -4318,10 +4475,12 @@ jobs:
client-id: ${{ secrets.GH_APP_POSTHOG_TESTS_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_TESTS_PRIVATE_KEY }}
permission-checks: write
+ # Mirrors Depot's own check for .github/scripts/ci_backend_relay.py (see MIRROR_APP_ID),
+ # under the name in MIRRORED_GATE_CHECK so that the two rows on a pull request differ.
# Depot's own checks carry no output and their pages need a Depot login, so this
# check carries the gate summary: GitHub shows the title on the PR's check row
# and the summary on the Checks tab.
- - name: Post the test results check
+ - name: Post the gate check for the relay
if: ${{ always() && steps.gate-token.outputs.token != '' }}
continue-on-error: true
env:
@@ -4329,12 +4488,11 @@ jobs:
REPO: ${{ github.repository }}
SHA: ${{ github.event.pull_request.head.sha }}
GATE_CHECK: Backend CI on Depot / Test results
- # A `no-ci` draft skips change detection and every check, so its row says so.
- CONCLUSION: ${{ job.status == 'cancelled' && 'cancelled' || needs.changes.result == 'skipped' && 'skipped' || (steps.verdict.outcome == 'success' && 'success' || 'failure') }}
+ CONCLUSION: ${{ job.status == 'cancelled' && 'cancelled' || (steps.verdict.outcome == 'success' && 'success' || 'failure') }}
+ RELAY_RUN_URL: ${{ needs.wait-for-handoff.outputs.github_run_url }}
run: |
case "$CONCLUSION" in
success) title="Backend tests passed on Depot" ;;
- skipped) title="No backend checks ran on Depot" ;;
cancelled) title="Backend tests cancelled on Depot" ;;
*) title=$(head -1 "$GATE_TITLE" 2>/dev/null || true); title="${title:-Backend tests failed on Depot}" ;;
esac
@@ -4344,11 +4502,11 @@ jobs:
# under that however the characters are encoded.
touch "$GATE_SUMMARY"
jq -n --arg name "$GATE_CHECK" --arg sha "$SHA" --arg conclusion "$CONCLUSION" --arg url "$DEPOT_JOB_URL" \
- --arg title "$title" --rawfile summary "$GATE_SUMMARY" \
+ --arg title "$title" --arg run_url "$RELAY_RUN_URL" --rawfile summary "$GATE_SUMMARY" \
'{name: $name, head_sha: $sha, status: "completed", conclusion: $conclusion, details_url: $url,
- output: {title: $title, summary: ($summary | if utf8bytelength > 60000 then until(utf8bytelength <= 60000; .[:-1000]) + "\n\n(truncated)" else . end)}}' \
+ output: {title: $title, summary: ("GitHub Actions run: \($run_url)\n\n" + ($summary | if utf8bytelength > 60000 then until(utf8bytelength <= 60000; .[:-1000]) + "\n\n(truncated)" else . end))}}' \
| gh api "repos/$REPO/check-runs" --method POST --input - --silent && exit 0
- # A rejected output must not lose the check.
+ # The relay reads this check for its verdict, so a rejected output must not lose the check.
echo "::warning::Could not post the gate check with its summary. Posting it without."
gh api "repos/$REPO/check-runs" --method POST -f name="$GATE_CHECK" \
-f head_sha="$SHA" -f status=completed -f conclusion="$CONCLUSION" -f details_url="$DEPOT_JOB_URL" --silent
diff --git a/.github/scripts/capture_depot_running_time.py b/.github/scripts/capture_depot_running_time.py
index 32b11fdc97d0..ebabb9938f99 100644
--- a/.github/scripts/capture_depot_running_time.py
+++ b/.github/scripts/capture_depot_running_time.py
@@ -32,6 +32,7 @@ CONCLUSION_BY_STATUS = {"finished": "success", "failed": "failure"}
# Depot posts one placeholder job per matrix that it expands from `fromJSON`. The placeholder runs nothing.
MATRIX_PLACEHOLDER_SUFFIX = ":_dynamicMatrix"
KNOWN_BOT_ACTORS = frozenset({"Copilot"})
+HANDOFF_JOB = "wait-for-handoff"
def conclusion(status: str) -> str:
@@ -115,7 +116,10 @@ def build_events(
group_key = f"{context['repositoryOwner']}/{context['repository']}/{context['runId']}"
groups = {"workflow_run": group_key}
jobs = shown.get("jobs") or []
- started_at = shown["workflow"]["started_at"]
+ # The workflow starts on every pull request event and idles in wait-for-handoff until GitHub
+ # routes the event here. The run starts after that wait, so the duration compares with GitHub's.
+ handoff = next((job for job in jobs if job_id(job) == HANDOFF_JOB), None)
+ started_at = (handoff and latest_attempt(handoff).get("finished_at")) or shown["workflow"]["started_at"]
properties: JSONObject = {
"duration_seconds": seconds_between(started_at, now.isoformat()),
"url": workflow_url,
diff --git a/.github/scripts/test_capture_depot_running_time.py b/.github/scripts/test_capture_depot_running_time.py
index db0fcf1375b4..a40dfc110956 100644
--- a/.github/scripts/test_capture_depot_running_time.py
+++ b/.github/scripts/test_capture_depot_running_time.py
@@ -23,6 +23,12 @@ ENV = {
SHOWN = {
"workflow": {"started_at": "2026-01-01T00:00:00Z"},
"jobs": [
+ {
+ "job_key": "ci-backend.yml:wait-for-handoff",
+ "job_display_name": "Wait for GitHub Actions to hand off backend tests",
+ "status": "finished",
+ "attempts": [{"attempt": 1, "started_at": "2026-01-01T00:00:05Z", "finished_at": "2026-01-01T00:00:30Z"}],
+ },
{
"job_key": "ci-backend.yml:django_tests",
"job_display_name": "Django Tests Pass on Depot",
@@ -68,10 +74,10 @@ def test_build_events_matches_the_action_event_shape() -> None:
"timestamp": now.isoformat(),
"event": "posthog-ci-running-time",
"properties": {
- "duration_seconds": 1290,
+ "duration_seconds": 1260,
"url": "https://depot.dev/orgs/org/workflows/wf",
"attempt": 1,
- "started_at": "2026-01-01T00:00:00Z",
+ "started_at": "2026-01-01T00:00:30Z",
"conclusion": "failure",
"runner": "depot-ci",
"sha": ENV["GITHUB_SHA"],
@@ -94,6 +100,7 @@ def test_build_events_matches_the_action_event_shape() -> None:
(e["properties"]["name"], e["properties"]["duration_seconds"], e["properties"]["conclusion"])
for e in events[2:]
] == [
+ ("Wait for GitHub Actions to hand off backend tests", 25, "success"),
("Django Tests Pass on Depot", 5, "failure"),
("Django tests - Core (1/2)", 450, "success"),
("Validate product.yaml owners", 0, "skipped"),
diff --git a/.github/scripts/test_ci_backend_relay.py b/.github/scripts/test_ci_backend_relay.py
index 39d0c73185c4..70e171c8950a 100644
--- a/.github/scripts/test_ci_backend_relay.py
+++ b/.github/scripts/test_ci_backend_relay.py
@@ -1,3 +1,4 @@
+import re
import json
import subprocess
import dataclasses
@@ -12,6 +13,8 @@ from typing import Any
import pytest
+import yaml
+
SCRIPT_PATH = Path(__file__).with_name("ci_backend_relay.py")
SPEC = importlib.util.spec_from_file_location("ci_backend_relay", SCRIPT_PATH)
assert SPEC is not None
@@ -19,6 +22,7 @@ assert SPEC.loader is not None
relay = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(relay)
+DEPOT_WORKFLOW_FILE = Path(__file__).parents[2] / ".depot" / "workflows" / "ci-backend.yml"
PR = 105723
EVENT_AT = "2026-09-24T09:54:20Z"
EVENT = relay.Event(repo="PostHog/posthog", sha="a8a3755cf964", pr_number=PR, event_at=EVENT_AT)
@@ -44,6 +48,34 @@ def run(id: int, state: str, workflow: str = "live", started_at: str = "2026-09-
return relay.CheckRun.from_api({**api_run(id, state, workflow), "started_at": started_at})
+def test_wait_job_name_matches_the_depot_workflow() -> None:
+ text = DEPOT_WORKFLOW_FILE.read_text()
+ job = text[text.index("\n wait-for-handoff:") :]
+ name = re.search(r"\n name: (.+)\n", job)
+ assert name is not None
+ expected = (
+ relay.WAIT_JOB
+ + "${{ github.event_name == 'pull_request' && format('"
+ + relay.EVENT_SUFFIX.replace("{pr}", "{0}").replace("{event_at}", "{1}")
+ + "', github.event.pull_request.number, github.event.pull_request.updated_at) || '' }}"
+ )
+ assert name.group(1) == expected
+
+
+def test_mirrored_checks_carry_the_names_the_relay_reads() -> None:
+ jobs = yaml.safe_load(DEPOT_WORKFLOW_FILE.read_text())["jobs"]
+ steps = [step for job in jobs.values() for step in job.get("steps", [])]
+ handoff = next(step for step in steps if step.get("name") == "Post the hand-off checks for the relay")
+ gate = next(step for step in steps if step.get("name") == "Post the gate check for the relay")
+ wait_check = (
+ handoff["env"]["WAIT_CHECK"]
+ .replace("${{ github.event.pull_request.number }}", str(PR))
+ .replace("${{ github.event.pull_request.updated_at }}", EVENT_AT)
+ )
+ assert wait_check == EVENT_WAIT
+ assert handoff["env"]["GATE_CHECK"] == gate["env"]["GATE_CHECK"] == relay.MIRRORED_GATE_CHECK
+
+
@pytest.mark.parametrize(
"event_waits,gates,expected",
[
diff --git a/.github/workflows/ci-backend-shadow-drift.yml b/.github/workflows/ci-backend-shadow-drift.yml
index 3cf1a1e0e7cf..2e7e58565f22 100644
--- a/.github/workflows/ci-backend-shadow-drift.yml
+++ b/.github/workflows/ci-backend-shadow-drift.yml
@@ -8,8 +8,10 @@ name: Backend CI shadow drift check
# `hogli ci:preflight` also runs before a push.
#
# Cheap to run: it triggers only on changes to the backend workflow, local actions, Depot files, or the check itself.
-# Always enforced: every pull request's backend tests run on Depot, so the mirror and
-# canonical have to agree on every commit.
+# Always enforced (no variable gate): keeping the depot mirror in sync with canonical is
+# a structural invariant worth holding whatever the rollout percent is: you want them
+# already in sync the moment an event is routed to Depot. The percent lives in the
+# CI_BACKEND_DEPOT_PERCENT GitHub variable, which this check deliberately does not read.
on:
pull_request:
diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.yml
index 4a8713239c73..4f04dc1fed77 100644
--- a/.github/workflows/ci-backend.yml
+++ b/.github/workflows/ci-backend.yml
@@ -101,6 +101,7 @@ permissions:
contents: read
actions: read
pull-requests: write
+ checks: read # the router reads this commit's earlier hand-off check
jobs:
# Learning mode: nothing reads these outputs, so a recommendation cannot change what runs.
@@ -131,10 +132,14 @@ jobs:
changes:
runs-on: depot-ubuntu-24.04
timeout-minutes: 5
- # Depot CI runs every pull request event from .depot/workflows/ci-backend.yml, and
- # its gate posts the required check. Every job that needs this one skips on a pull
- # request, and the gate treats skipped as success.
- if: github.event_name != 'pull_request'
+ # A draft PR labeled `no-ci` skips this workflow entirely (prototypes):
+ # every other job needs this one, and the gates treat skipped as success.
+ # ready_for_review re-runs everything, so the merge gate is unaffected.
+ if: >-
+ github.event_name != 'pull_request'
+ || github.event.pull_request.draft != true
+ || startsWith(github.head_ref, 'trunk-merge/')
+ || !contains(github.event.pull_request.labels.*.name, 'no-ci')
name: Determine need to run backend and migration checks
# Set job outputs to values from filter step
outputs:
@@ -166,6 +171,9 @@ jobs:
sdk_manifests: ${{ steps.filter.outputs.sdk_manifests || 'true' }}
product_yamls_files: ${{ steps.filter.outputs.product_yamls_files }}
timing_scripts: ${{ steps.filter.outputs.timing_scripts }}
+ # Which engine runs this event's backend tests. Depot CI never decides on its
+ # own: it waits for the hand-off job below and runs only when that succeeded.
+ engine: ${{ steps.route.outputs.engine || 'github' }}
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
@@ -174,6 +182,9 @@ jobs:
clean: false
sparse-checkout: |
.github/actions/paths-filter
+ .github/scripts/ci_backend_route.py
+ .github/scripts/ci_backend_relay.py
+ .github/scripts/ci_backend_depot_failures.py
sparse-checkout-cone-mode: false
- name: Clean up data directories with container permissions
run: |
@@ -181,12 +192,19 @@ jobs:
[ -d "data" ] && docker run --rm -v "$(pwd)/data:/data" alpine sh -c "rm -rf /data/seaweedfs /data/minio" || true
continue-on-error: true
+ - uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
+ id: app-token
+ if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ continue-on-error: true
+ with:
+ client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
+ private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
- uses: ./.github/actions/paths-filter
# Skipped on master push: every output then defaults to true.
if: github.event_name != 'push'
id: filter
with:
- token: ${{ github.token }}
+ token: ${{ steps.app-token.outputs.token || github.token }}
list-files: 'escape'
filters: |
backend:
@@ -495,6 +513,41 @@ jobs:
- 'products/desktop/packages/api-client/package.json'
- 'products/desktop/packages/api-client/scripts/**'
- 'bin/build-desktop-api-client.sh'
+ # Last, so the paths filter runs while Depot starts its run for this event.
+ - name: Pick the engine that runs the backend tests
+ id: route
+ if: github.event_name == 'pull_request'
+ env:
+ PERCENT: ${{ vars.CI_BACKEND_DEPOT_PERCENT }}
+ MERGE_QUEUE_PERCENT: ${{ vars.CI_BACKEND_DEPOT_MERGE_QUEUE_PERCENT }}
+ EVENT: ${{ github.event_name }}
+ PR_NUMBER: ${{ github.event.pull_request.number }}
+ LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }}
+ IS_FORK: ${{ github.event.pull_request.head.repo.fork }}
+ IS_DRAFT: ${{ github.event.pull_request.draft }}
+ HEAD_REF: ${{ github.head_ref }}
+ # The script reads this commit's earlier hand-off check, the durable record
+ # of the engine that already ran its tests and side effects, and the check of
+ # the Depot wait job that names this event.
+ GH_TOKEN: ${{ github.token }}
+ REPO: ${{ github.repository }}
+ SHA: ${{ github.event.pull_request.head.sha }}
+ EVENT_AT: ${{ github.event.pull_request.updated_at }}
+ run: python3 .github/scripts/ci_backend_route.py
+
+ # The only signal Depot CI acts on. Its wait job in .depot/workflows/ci-backend.yml
+ # polls this check by name and runs the backend tests only when it concluded
+ # `success`, so a skipped hand-off keeps the event on GitHub Actions. Renaming
+ # this job breaks that lookup.
+ hand-off-to-depot:
+ name: Hand off backend tests to Depot CI
+ runs-on: ubuntu-24.04
+ timeout-minutes: 2
+ needs: [changes]
+ if: needs.changes.outputs.engine == 'depot'
+ permissions: {}
+ steps:
+ - run: echo "::notice::Depot CI runs the backend tests for this event. GitHub Actions runs none."
detect-snapshot-mode:
name: Detect snapshot mode
@@ -503,7 +556,7 @@ jobs:
needs: [changes]
# Master pushes skip the matrices (see the trigger comment); skipping this
# root cascades to every downstream test job via their result checks.
- if: needs.changes.outputs.backend == 'true' && github.event_name != 'push'
+ if: needs.changes.outputs.backend == 'true' && github.event_name != 'push' && needs.changes.outputs.engine != 'depot'
outputs:
mode: ${{ steps.detect.outputs.mode }}
steps:
@@ -542,7 +595,7 @@ jobs:
needs: changes
# Skipped on master push: the merge queue already ran the full matrices for
# every landed commit, and the hourly scheduled run keeps master coverage.
- if: needs.changes.outputs.backend == 'true' && github.event_name != 'push'
+ if: needs.changes.outputs.backend == 'true' && github.event_name != 'push' && needs.changes.outputs.engine != 'depot'
runs-on: depot-ubuntu-24.04
timeout-minutes: 20
name: Discover product tests
@@ -1387,7 +1440,7 @@ jobs:
# bots rewrite manifests across majors, so this is the block. Stdlib only, no venv.
sdk-major-guard:
needs: [changes]
- if: needs.changes.outputs.sdk_manifests == 'true'
+ if: needs.changes.outputs.sdk_manifests == 'true' && needs.changes.outputs.engine != 'depot'
timeout-minutes: 5
permissions: {}
name: SDK major-version guard
@@ -1400,7 +1453,7 @@ jobs:
repo-checks:
needs: [changes]
# product_yamls: ownership-only PRs still need the owners.yaml lint below.
- if: (needs.changes.outputs.backend == 'true' || needs.changes.outputs.product_yamls == 'true' || needs.changes.outputs.repo_invariants == 'true')
+ if: (needs.changes.outputs.backend == 'true' || needs.changes.outputs.product_yamls == 'true' || needs.changes.outputs.repo_invariants == 'true') && needs.changes.outputs.engine != 'depot'
timeout-minutes: 10
outputs:
deterministic_failure: ${{ steps.deterministic-failure.outputs.deterministic_failure || 'false' }}
@@ -1567,6 +1620,7 @@ jobs:
needs.changes.outputs.product_yamls == 'true' &&
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository
+ && needs.changes.outputs.engine != 'depot'
timeout-minutes: 5
name: Validate product.yaml owners (ubuntu-24.04)
runs-on: ubuntu-24.04
@@ -1640,7 +1694,7 @@ jobs:
# products/db_routing.yaml is neither Python nor under a backend/ directory, and
# a migration in a future top-level app matches none of them. Without it the
# replay gate could be on while the job that runs it never starts.
- if: (needs.changes.outputs.backend == 'true' || needs.changes.outputs.migrations == 'true' || needs.changes.outputs.persons_sql == 'true' || needs.changes.outputs.migration_replay == 'true')
+ if: (needs.changes.outputs.backend == 'true' || needs.changes.outputs.migrations == 'true' || needs.changes.outputs.persons_sql == 'true' || needs.changes.outputs.migration_replay == 'true') && needs.changes.outputs.engine != 'depot'
# On master this job replays the full migration history from scratch to
# produce the schema dump every PR job restores, and a merge queue batch that
# changes a Django migration replays it a second time onto an empty database.
@@ -2397,7 +2451,7 @@ jobs:
check-openapi-types:
needs: [changes]
- if: (needs.changes.outputs.backend == 'true' || needs.changes.outputs.openapi_types == 'true')
+ if: (needs.changes.outputs.backend == 'true' || needs.changes.outputs.openapi_types == 'true') && needs.changes.outputs.engine != 'depot'
timeout-minutes: 20
outputs:
deterministic_failure: ${{ steps.deterministic-failure.outputs.deterministic_failure || 'false' }}
@@ -4035,7 +4089,7 @@ jobs:
name: Get ClickHouse versions
needs: [changes]
# Only feeds the test matrices, which master pushes skip.
- if: needs.changes.outputs.backend == 'true' && github.event_name != 'push'
+ if: needs.changes.outputs.backend == 'true' && github.event_name != 'push' && needs.changes.outputs.engine != 'depot'
runs-on: depot-ubuntu-24.04
timeout-minutes: 5
outputs:
@@ -4215,8 +4269,10 @@ jobs:
permissions:
contents: read
actions: read # the failure rollup downloads each shard's JUnit artifact
- # Headroom for downloading every shard's JUnit for the failure rollup.
- timeout-minutes: 8
+ checks: read # the relay reads Depot's gate check run
+ # Headroom for downloading every shard's JUnit for the failure rollup, or for
+ # waiting out a full Depot run when this job only relays its verdict.
+ timeout-minutes: ${{ needs.changes.outputs.engine == 'depot' && 95 || 8 }}
# Intentional !cancelled(): the gate inspects failed dependencies and fails
# closed on live runs; a superseded run records cancelled, not failure.
# The deterministic-failure disjuncts cover this workflow cancelling its
@@ -4227,13 +4283,37 @@ jobs:
|| needs.repo-checks.outputs.deterministic_failure == 'true'
|| needs.check-openapi-types.outputs.deterministic_failure == 'true'
steps:
- # Kept on pull requests so the ruleset entry for this job stays satisfied until the
- # Depot gate replaces it there.
- - name: Point at the Depot gate
- if: github.event_name == 'pull_request'
- run: echo "::notice::Depot CI runs the backend tests for pull requests. The required check is 'Backend CI on Depot / Django Tests Pass on Depot'."
+ - name: Check out the relay script
+ if: needs.changes.outputs.engine == 'depot'
+ uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+ with:
+ sparse-checkout: |
+ .github/scripts/ci_backend_relay.py
+ .github/scripts/ci_backend_depot_failures.py
+ sparse-checkout-cone-mode: false
+ persist-credentials: false
+ # The relay reads a failed run's steps and log lines with the Depot CLI. Without
+ # the CLI, the relay prints a warning and still reports the verdict.
+ - uses: depot/setup-action@15c09a5f77a0840ad4bce955686522a257853461 # v1.7.1
+ if: needs.changes.outputs.engine == 'depot'
+ continue-on-error: true
+ # The script finds this event's Depot run by the event in its wait job's check
+ # name, then waits for that run's gate. Its docstring explains why check times
+ # and pull request lists cannot identify the run.
+ - name: Relay the Depot verdict
+ if: needs.changes.outputs.engine == 'depot'
+ env:
+ DEPOT_TOKEN: ${{ secrets.DEPOT_TOKEN }}
+ GH_TOKEN: ${{ github.token }}
+ REPO: ${{ github.repository }}
+ SHA: ${{ github.event.pull_request.head.sha }}
+ EVENT_AT: ${{ github.event.pull_request.updated_at }}
+ PR_NUMBER: ${{ github.event.pull_request.number }}
+ HEAD_REF: ${{ github.head_ref }}
+ # Unbuffered, so each poll shows in the live log instead of all at once when the step ends.
+ run: python3 -u .github/scripts/ci_backend_relay.py gate
- name: Summarize dependency results
- if: github.event_name != 'pull_request'
+ if: needs.changes.outputs.engine != 'depot'
run: |
{
echo "### Backend CI dependency results"
@@ -4266,7 +4346,7 @@ jobs:
# on green runs (the common case) to avoid pulling every shard artifact for nothing.
# continue-on-error so a flaky fetch can't fail this required gate.
- name: Download shard JUnit results
- if: always() && github.event_name != 'pull_request' && (needs.django.result != 'success' || needs.turbo-tests.result != 'success')
+ if: always() && needs.changes.outputs.engine != 'depot' && (needs.django.result != 'success' || needs.turbo-tests.result != 'success')
continue-on-error: true
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
@@ -4275,7 +4355,7 @@ jobs:
# Re-run attempts upload under suffixed names, so superseded attempts must be dropped
# here or the rollup below lists attempt-1 failures the re-run already recovered.
- name: Keep only each shard's latest attempt
- if: always() && github.event_name != 'pull_request' && (needs.django.result != 'success' || needs.turbo-tests.result != 'success')
+ if: always() && needs.changes.outputs.engine != 'depot' && (needs.django.result != 'success' || needs.turbo-tests.result != 'success')
continue-on-error: true
run: |
cd /tmp/junit-gate 2>/dev/null || exit 0
@@ -4504,6 +4584,7 @@ jobs:
!cancelled() && github.actor != 'dependabot[bot]' && (
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog') ||
(github.event_name != 'pull_request' && github.repository == 'PostHog/posthog'))
+ && needs.changes.outputs.engine != 'depot'
&& needs.changes.result == 'success'
permissions:
contents: read
@@ -4669,6 +4750,7 @@ jobs:
needs.turbo-discover.outputs.mode != 'selected' &&
github.event.pull_request.head.repo.full_name == 'PostHog/posthog' &&
(needs.turbo-tests.result != 'skipped' || needs.django_tests.result != 'skipped')
+ && needs.changes.outputs.engine != 'depot'
&& needs.changes.result == 'success'
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
diff --git a/docs/published/handbook/engineering/fork-pull-requests.md b/docs/published/handbook/engineering/fork-pull-requests.md
index fd0816668de5..2ea8ce299faa 100644
--- a/docs/published/handbook/engineering/fork-pull-requests.md
+++ b/docs/published/handbook/engineering/fork-pull-requests.md
@@ -3,18 +3,19 @@ title: Pull requests from forks
sidebar: Handbook
---
-Backend CI runs on Depot CI, from `.depot/workflows/ci-backend.yml`, and its gate check `Backend CI on Depot / Django Tests Pass on Depot` is required on `master`.
-Depot CI never runs a fork's code, so a fork pull request gets no backend run and that check stays pending.
-A fork pull request cannot merge as it is.
-After review, a PostHog engineer re-creates the change on a branch in this repository, which gets a Depot run and the required check.
+Backend CI runs on one of two engines per pull request, decided by `.github/scripts/ci_backend_route.py`: GitHub Actions or Depot CI.
+Depot CI never runs a fork's code, so the router sends every fork pull request to GitHub Actions.
+The required `Django Tests Pass` check is a GitHub Actions job on every head, fork or not, and nothing about the merge queue changes for a fork.
+For in-repository PRs, an unreadable prior routing decision stops CI instead of switching engines.
+The Depot relay matches the PR event's named wait check and reads only that Depot workflow's verdict; it never starts GitHub tests after a timeout.
What a fork contributor sees:
-- Every other CI workflow runs on GitHub Actions and selects the same tests it selects for any other pull request.
-- The backend check stays pending. Depot starts no run for a fork, and the gate fails for one if it ever does.
-- Steps that need a secret skip. The same-repo `if:` guard that makes that safe is in the [CI authoring skill](https://github.com/PostHog/posthog/blob/master/.agents/skills/authoring-ci-workflows/SKILL.md).
+- Backend CI runs on GitHub Actions, as it always has, and selects the same tests it selects for any other pull request.
+- Depot's optional checks show as skipped. They are not required and nothing waits on them.
+- Steps that need a secret skip, on both engines. The same-repo `if:` guard that makes that safe is in the [CI authoring skill](https://github.com/PostHog/posthog/blob/master/.agents/skills/authoring-ci-workflows/SKILL.md).
- Visual Review needs a secret, so a fork pull request gets no Visual Review run. Each Storybook shard instead compares its screenshots with `frontend/snapshots.yml` offline. This fallback accepts only an exact pixel match. It does not know the tolerated hashes or the quarantine of Visual Review, so a flaky story can fail it. A snapshot that differs fails `Visual regression tests pass` until a maintainer updates the baseline. Without the check, the merge queue would be the first run to compare the screenshots.
-Never push a fork's head to a branch inside this repository before it is reviewed.
+Never push a fork's head to a branch inside this repository to get it a Depot run.
An in-repo branch is trusted: every secret-gated step runs, with the fork's code in control of the job.
-Review the fork PR as it is, then re-create it in-repo.
+Review the fork PR as it is, and let the merge queue test it on its own branch.
diff --git a/tools/workflow-plan/README.md b/tools/workflow-plan/README.md
index f66668bd4d01..40e1846b28fd 100644
--- a/tools/workflow-plan/README.md
+++ b/tools/workflow-plan/README.md
@@ -1,6 +1,6 @@
# workflow-plan
-Evaluates the `if:` conditions in `.github/workflows/*.yml` and `.depot/workflows/*.yml` the way GitHub does, against synthetic PR, push, schedule, and cancellation scenarios, and reports which jobs and steps run.
+Evaluates the `if:` conditions in `.github/workflows/*.yml` the way GitHub does, against synthetic PR, push, schedule, and cancellation scenarios, and reports which jobs and steps run.
The evaluator is GitHub's own [`@actions/expressions`](https://www.npmjs.com/package/@actions/expressions), so operator precedence, coercion, `contains`, `fromJSON`, and the `labels.*.name` filter syntax behave as they do in Actions.
## See a workflow's run plan
@@ -15,7 +15,7 @@ A cell reads `▶` for a job that runs, `✗` for one that fails, `⊘` for one
In a terminal the header row is bold and every second row has a shaded background; set `NO_COLOR` to turn that off.
Every paths filter is stubbed as if all of its filters matched.
Outputs that scripts produce at runtime are empty, so a job gated on `needs.x.outputs.matrix != ''` shows as skipped and a matrix built from such an output has no cell count.
-Where a workflow cannot be planned without such a value, `SCRIPT_STUBS` in `src/scenarios.ts` supplies it per workflow path, for example the release plan output.
+Where a workflow cannot be planned without such a value, `SCRIPT_STUBS` in `src/scenarios.ts` supplies it per workflow path: the release plan output, and the Depot shadow's sampling variable and dice roll so `.depot/workflows/ci-backend.yml` plans as sampled in.
## Pin the intended behavior in a test
diff --git a/tools/workflow-plan/src/scenarios.ts b/tools/workflow-plan/src/scenarios.ts
index 4eb53ba422bd..9381d58c06ca 100644
--- a/tools/workflow-plan/src/scenarios.ts
+++ b/tools/workflow-plan/src/scenarios.ts
@@ -194,6 +194,8 @@ export const REPO_ROOT = fileURLToPath(new URL('../../../', import.meta.url))
type ScriptStubs = Pick<Scenario, 'vars' | 'jobOutputs'>
// Values only a script produces at runtime, without which a workflow's gates cannot be planned.
+const DEPOT_BACKEND = '.depot/workflows/ci-backend.yml'
+
export const SCRIPT_STUBS: Record<string, ScriptStubs> = {
'.github/workflows/build-deltalite.yml': {
jobOutputs: { 'check-version': { 'deltalite-release-needed': 'true' } },
@@ -205,19 +207,30 @@ export const SCRIPT_STUBS: Record<string, ScriptStubs> = {
},
},
},
+ // The Depot graph hangs off a hand-off check the planner cannot read; plan it as handed
+ // off, which is the only case where its jobs do any work.
+ [DEPOT_BACKEND]: {
+ jobOutputs: { 'wait-for-handoff': { handed_off: 'true' } },
+ },
}
+// The router keeps forks, merge queue batches, pushes and the schedule on GitHub Actions,
+// so Depot's wait job declines those events; only same-repo pull requests and manual
+// dispatches run there.
+const NOT_HANDED_OFF: ScriptStubs = { jobOutputs: { 'wait-for-handoff': { handed_off: 'false' } } }
+
export function defaultScenarios(workflow: Workflow, workflowPath: string): Scenario[] {
const steps = allFiltersChanged(workflow)
const key = path.relative(REPO_ROOT, workflowPath).split(path.sep).join('/')
const common = { steps, ...SCRIPT_STUBS[key] }
+ const keptOnGitHub = { ...common, ...(key === DEPOT_BACKEND ? NOT_HANDED_OFF : {}) }
return [
{ name: 'draft', github: pullRequest({ draft: true }), ...common },
{ name: 'ready', github: pullRequest(), ...common },
- { name: 'fork', github: pullRequest({ fork: true }), ...common },
- { name: 'queued', github: mergeQueue(), ...common },
- { name: 'merged', github: push(), ...common },
- { name: 'scheduled', github: schedule(), ...common },
+ { name: 'fork', github: pullRequest({ fork: true }), ...keptOnGitHub },
+ { name: 'queued', github: mergeQueue(), ...keptOnGitHub },
+ { name: 'merged', github: push(), ...keptOnGitHub },
+ { name: 'scheduled', github: schedule(), ...keptOnGitHub },
{ name: 'dispatched', github: workflowDispatch(), ...common },
]
}
diff --git a/tools/workflow-plan/tests/backend-diff.test.ts b/tools/workflow-plan/tests/backend-diff.test.ts
index 749c2ead3e73..f4145765902e 100644
--- a/tools/workflow-plan/tests/backend-diff.test.ts
+++ b/tools/workflow-plan/tests/backend-diff.test.ts
@@ -9,7 +9,6 @@ import { type RawStep, type Workflow, loadWorkflow, planWorkflow } from '../src/
import { REPO_ROOT, allFiltersChanged, mergeQueue, pullRequest } from '../src/scenarios.ts'
const WORKFLOWS = ['.github/workflows/ci-backend.yml', '.depot/workflows/ci-backend.yml']
-const [GITHUB_BACKEND, DEPOT_BACKEND] = WORKFLOWS
const functions = planFunctions({ dependenciesSucceeded: true, dependenciesFailed: false, cancelled: false })
const lowerFile = 'products/engineering_analytics/backend/lower.py'
const layerFiles = [
@@ -221,7 +220,7 @@ describe('Backend CI comparison boundaries', () => {
(failure) => {
const repo = createGraph()
try {
- const wf = loadWorkflow(path.join(REPO_ROOT, DEPOT_BACKEND!))
+ const wf = loadWorkflow(path.join(REPO_ROOT, WORKFLOWS[0]!))
const context = prContext(repo.merge, failure === 'wrong-head' ? repo.lower : repo.head, 'lower')
if (failure === 'wrong-checkout') {
repo.git('checkout', '--detach', repo.head)
@@ -269,7 +268,7 @@ describe('Backend CI comparison boundaries', () => {
])('regenerates a missing verdict selection for $name', ({ queued }) => {
const repo = createGraph()
try {
- const wf = loadWorkflow(path.join(REPO_ROOT, GITHUB_BACKEND!))
+ const wf = loadWorkflow(path.join(REPO_ROOT, WORKFLOWS[0]!))
const sha = queued ? repo.queueMerge : repo.merge
const context = prContext(sha, queued ? repo.merge : repo.head, queued ? 'master' : 'lower', queued)
const target = wf.jobs['test-selection-verdict']!.steps!.find(
diff --git a/tools/workflow-plan/tests/workflows.test.ts b/tools/workflow-plan/tests/workflows.test.ts
index eb0a959b39d4..1a5b68536232 100644
--- a/tools/workflow-plan/tests/workflows.test.ts
+++ b/tools/workflow-plan/tests/workflows.test.ts
@@ -1,4 +1,4 @@
-// These tests check the CI workflows, not the planner. A failure here means a
+// These tests check the workflows under .github/workflows, not the planner. A failure here means a
// job condition in a workflow file changed what runs; the planner itself is covered by plan.test.ts.
import { spawnSync } from 'node:child_process'
import { mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
@@ -32,15 +32,13 @@ import {
const WORKFLOWS_DIR = path.join(REPO_ROOT, '.github/workflows')
const workflowFiles = readdirSync(WORKFLOWS_DIR).filter((file) => file.endsWith('.yml') || file.endsWith('.yaml'))
-// A bare file name lives under .github/workflows; a repo-relative path names a Depot CI workflow.
-const workflowKey = (file: string): string => (file.includes('/') ? file : `.github/workflows/${file}`)
const cache = new Map<string, Workflow>()
const workflow = (file: string): Workflow => {
const cached = cache.get(file)
if (cached) {
return cached
}
- const loaded = loadWorkflow(path.join(REPO_ROOT, workflowKey(file)))
+ const loaded = loadWorkflow(path.join(WORKFLOWS_DIR, file))
cache.set(file, loaded)
return loaded
}
@@ -75,7 +73,7 @@ type ExpectationBuilder = (
const suite = (file: string, selectors: Stubs = {}): ExpectationBuilder => {
const filters = allFiltersChanged(workflow(file))
- const scripted = SCRIPT_STUBS[workflowKey(file)]
+ const scripted = SCRIPT_STUBS[`.github/workflows/${file}`]
return (overrides, rest) => ({
file,
scenario: {
@@ -87,12 +85,10 @@ const suite = (file: string, selectors: Stubs = {}): ExpectationBuilder => {
...rest,
})
}
-const DEPOT_BACKEND = '.depot/workflows/ci-backend.yml'
const backend = suite('ci-backend.yml', backendSelectors)
-const depotBackend = suite(DEPOT_BACKEND, backendSelectors)
const frontend = suite('ci-frontend.yml', frontendSelectors)
const deltalite = suite('build-deltalite.yml')
-const PINNED_WORKFLOWS = ['ci-backend.yml', DEPOT_BACKEND, 'ci-frontend.yml']
+const PINNED_WORKFLOWS = ['ci-backend.yml', 'ci-frontend.yml']
interface ReleaseWorkflow {
file: string
@@ -159,59 +155,8 @@ const frontendOnlyFilters: Stubs = {
},
}
-const allJobsExcept = (file: string, kept: string[]): string[] =>
- Object.keys(workflow(file).jobs).filter((id) => !kept.includes(id))
-
const EXPECTATIONS: Expectation[] = [
- // Depot CI runs every pull request event. GitHub Actions keeps only the `Django Tests Pass`
- // job, which points at the Depot gate, so every other job stands down on a pull request.
- ...(
- [
- ['draft PR', pullRequest({ draft: true }), ['dynamic-ci-filter']],
- ['ready PR', pullRequest(), ['dynamic-ci-filter']],
- ['merge queue', mergeQueue(), []],
- ['fork PR', pullRequest({ fork: true }), []],
- ['draft PR labeled no-ci', pullRequest({ draft: true, labels: ['no-ci'] }), []],
- ] as const
- ).map(([name, github, alsoRuns]) =>
- backend(
- { name, github },
- {
- runs: ['django_tests', ...alsoRuns],
- skipped: allJobsExcept('ci-backend.yml', ['django_tests', ...alsoRuns]),
- }
- )
- ),
backend(
- { name: 'master push', github: push() },
- {
- runs: [
- 'changes',
- 'repo-checks',
- 'sdk-major-guard',
- 'check-migrations',
- 'mirror-schema-cache',
- 'django_tests',
- ],
- skipped: [
- 'dynamic-ci-filter',
- 'detect-snapshot-mode',
- 'turbo-tests',
- 'django',
- 'get_clickhouse_versions',
- 'build-product-test-matrix',
- 'build_django_matrix',
- 'test-selection-verdict',
- ],
- }
- ),
- ...[backend, depotBackend].map((build) =>
- build(
- { name: 'ready PR, superseded and cancelled', cancelled: true },
- { results: { django_tests: 'cancelled' } }
- )
- ),
- depotBackend(
{ name: 'draft PR', github: pullRequest({ draft: true }) },
{
runs: [
@@ -227,7 +172,7 @@ const EXPECTATIONS: Expectation[] = [
skipped: ['turbo-tests', 'backend-coverage-report'],
}
),
- depotBackend(
+ backend(
{
name: 'draft PR labeled run-ci-backend',
github: pullRequest({ draft: true, labels: ['run-ci-backend'] }),
@@ -236,11 +181,11 @@ const EXPECTATIONS: Expectation[] = [
runs: ['turbo-tests', 'django'],
}
),
- depotBackend(
+ backend(
{ name: 'ready PR' },
{
runs: [
- 'cancel-superseded-runs',
+ 'dynamic-ci-filter',
'turbo-tests',
'django',
'backend-coverage-report',
@@ -248,24 +193,74 @@ const EXPECTATIONS: Expectation[] = [
'get_clickhouse_versions',
'build-product-test-matrix',
'build_django_matrix',
- 'prime-schema-cache',
'test-selection-verdict',
'capture-test-selection',
],
- skipped: ['handle-snapshots', 'cancel-backend-on-openapi-check-failure'],
+ skipped: ['handle-snapshots', 'cancel-backend-on-openapi-check-failure', 'hand-off-to-depot'],
+ }
+ ),
+ // Handed off to Depot: it runs the tests and the side effects, GitHub Actions relays the
+ // verdict. Every heavy job and every side effect here stands down, and the required gate
+ // keeps reporting.
+ backend(
+ {
+ name: 'ready PR handed off to Depot',
+ steps: { changes: { route: { outputs: { engine: 'depot' } } } },
+ },
+ {
+ runs: ['changes', 'hand-off-to-depot', 'django_tests'],
+ skipped: [
+ 'detect-snapshot-mode',
+ 'turbo-discover',
+ 'repo-checks',
+ 'sdk-major-guard',
+ 'validate-product-yamls',
+ 'check-migrations',
+ 'check-openapi-types',
+ 'get_clickhouse_versions',
+ 'build_django_matrix',
+ 'build-product-test-matrix',
+ 'django',
+ 'turbo-tests',
+ 'handle-snapshots',
+ 'test-selection-verdict',
+ 'capture-test-selection',
+ 'report-test-timings',
+ 'calculate-running-time',
+ 'backend-coverage-report',
+ 'cancel-backend-on-repo-check-failure',
+ 'cancel-backend-on-openapi-check-failure',
+ ],
+ }
+ ),
+ backend(
+ { name: 'routing record unreadable', steps: { changes: { route: { outcome: 'failure' } } } },
+ {
+ runs: ['django_tests'],
+ results: { changes: 'failure' },
+ skipped: [
+ 'hand-off-to-depot',
+ 'django',
+ 'turbo-tests',
+ 'check-migrations',
+ 'handle-snapshots',
+ 'report-test-timings',
+ 'calculate-running-time',
+ 'backend-coverage-report',
+ ],
}
),
- depotBackend(
+ backend(
{ name: 'merge queue', github: mergeQueue() },
{
runs: ['turbo-tests', 'django', 'django_tests'],
- skipped: ['backend-coverage-report'],
+ skipped: ['backend-coverage-report', 'dynamic-ci-filter'],
}
),
// A product change that reaches no legacy code skips the Django suite, but the events_json
// rows still run the changed products' listed paths, because product jobs read the legacy
// events table only.
- depotBackend(
+ backend(
{
name: 'product-only PR whose products have events_json paths',
steps: {
@@ -284,7 +279,7 @@ const EXPECTATIONS: Expectation[] = [
},
{ runs: ['turbo-tests', 'django', 'django_tests'] }
),
- depotBackend(
+ backend(
{
name: 'product-only PR without events_json paths',
steps: {
@@ -303,19 +298,36 @@ const EXPECTATIONS: Expectation[] = [
},
{ runs: ['turbo-tests', 'django_tests'], skipped: ['django'] }
),
- depotBackend(
+ backend(
{ name: 'draft PR labeled no-ci', github: pullRequest({ draft: true, labels: ['no-ci'] }) },
{
- runs: ['cancel-superseded-runs', 'django_tests'],
- skipped: ['changes', 'django', 'turbo-tests', 'repo-checks', 'sdk-major-guard', 'check-migrations'],
+ runs: ['django_tests'],
+ skipped: [
+ 'changes',
+ 'django',
+ 'turbo-tests',
+ 'repo-checks',
+ 'sdk-major-guard',
+ 'check-migrations',
+ 'dynamic-ci-filter',
+ ],
}
),
- // Depot CI never runs a fork's code. Only the gate runs, and it fails closed.
- depotBackend(
+ backend(
{ name: 'fork PR', github: pullRequest({ fork: true }) },
- { runs: ['django_tests'], skipped: allJobsExcept(DEPOT_BACKEND, ['django_tests']) }
+ {
+ runs: ['changes', 'django', 'django_tests'],
+ skipped: [
+ 'dynamic-ci-filter',
+ 'validate-product-yamls',
+ 'calculate-running-time',
+ 'report-test-timings',
+ 'capture-test-selection',
+ 'handle-snapshots',
+ ],
+ }
),
- depotBackend(
+ backend(
{ name: 'frontend-only PR', steps: frontendOnlyFilters },
{
runs: ['changes', 'django_tests'],
@@ -329,7 +341,36 @@ const EXPECTATIONS: Expectation[] = [
],
}
),
- depotBackend(
+ backend(
+ { name: 'master push', github: push() },
+ {
+ runs: [
+ 'changes',
+ 'repo-checks',
+ 'sdk-major-guard',
+ 'check-migrations',
+ 'mirror-schema-cache',
+ 'django_tests',
+ ],
+ skipped: [
+ 'dynamic-ci-filter',
+ 'detect-snapshot-mode',
+ 'turbo-tests',
+ 'django',
+ 'get_clickhouse_versions',
+ 'build-product-test-matrix',
+ 'build_django_matrix',
+ 'test-selection-verdict',
+ ],
+ }
+ ),
+ backend(
+ { name: 'ready PR, superseded and cancelled', cancelled: true },
+ {
+ results: { django_tests: 'cancelled' },
+ }
+ ),
+ backend(
{
name: 'ready PR, self-cancelled after a deterministic repo-checks failure',
cancelled: true,
@@ -346,7 +387,7 @@ const EXPECTATIONS: Expectation[] = [
results: { 'repo-checks': 'failure' },
}
),
- depotBackend(
+ backend(
{
name: 'ready PR, cancelled after repo-checks failed during setup',
cancelled: true,
@@ -485,9 +526,9 @@ const STEP_EXPECTATIONS: StepExpectation[] = [
scenario: { name: 'hourly schedule', github: schedule() },
runs: false,
},
- // The GitHub Actions backend workflow skips change detection on pull requests, which run on Depot CI.
- ...PINNED_WORKFLOWS.filter((file) => file !== 'ci-backend.yml').flatMap((file) => [
+ ...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: 'app-token', scenario: { name: 'ready PR', github: pullRequest() }, runs: true },
{
file,
@@ -497,13 +538,6 @@ const STEP_EXPECTATIONS: StepExpectation[] = [
runs: false,
},
]),
- ...PINNED_WORKFLOWS.map((file) => ({
- file,
- job: 'changes',
- step: 'filter',
- scenario: { name: 'master push', github: push() },
- 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 },
]
@@ -517,7 +551,7 @@ const namedJobs = (file: string): Set<string> =>
])
)
-describe('CI workflow run plans', () => {
+describe('.github/workflows run plans', () => {
it.each([
['failed install', 'failure', 'src/example.ts', 'full'],
['empty source selection', 'skipped', '', 'selective'],
@@ -605,13 +639,14 @@ describe('CI workflow run plans', () => {
})
it.each(['refs/heads/master', ''])('the hourly Depot run keeps master coverage with ref %j', (ref) => {
- const depot = workflow(DEPOT_BACKEND)
+ const depot = loadWorkflow(path.join(REPO_ROOT, '.depot/workflows/ci-backend.yml'))
const plan = planWorkflow(depot, {
name: 'hourly schedule',
github: { ...schedule(), ref },
steps: {
...allFiltersChanged(depot),
...backendSelectors,
+ 'wait-for-handoff': { handoff: { outputs: { handed_off: 'true' } } },
},
})
expect(plan.errors).toEqual([])
@@ -627,11 +662,29 @@ describe('CI workflow run plans', () => {
}).toEqual({ didNotRun: [], didNotSkip: [], filterRuns: false, productTimings: true })
})
+ it('the scheduled Depot hand-off succeeds without a GitHub receipt', () => {
+ const depot = loadWorkflow(path.join(REPO_ROOT, '.depot/workflows/ci-backend.yml'))
+ const script = depot.jobs['wait-for-handoff']?.steps?.find((step) => step.id === 'handoff')?.run
+ expect(script).toBeTypeOf('string')
+ const directory = mkdtempSync(path.join(os.tmpdir(), 'depot-handoff-'))
+ const output = path.join(directory, 'output')
+ try {
+ const result = spawnSync('/bin/bash', ['-c', String(script)], {
+ env: { EVENT: 'schedule', IS_FORK: 'false', GITHUB_OUTPUT: output },
+ encoding: 'utf8',
+ })
+ expect({ status: result.status, stderr: result.stderr }).toEqual({ status: 0, stderr: '' })
+ expect(readFileSync(output, 'utf8')).toContain('handed_off=true')
+ } finally {
+ rmSync(directory, { recursive: true, force: true })
+ }
+ })
+
it.each([
['23 */3 * * *', true],
['23 1,2,4,5,7,8,10,11,13,14,16,17,19,20,22,23 * * *', false],
])('the events_json leg follows the scheduled trigger %s', (cron, runs) => {
- const depot = workflow(DEPOT_BACKEND)
+ const depot = loadWorkflow(path.join(REPO_ROOT, '.depot/workflows/ci-backend.yml'))
const step = depot.jobs.build_django_matrix?.steps?.find((step) => step.id === 'build')
const github = { ...schedule(), event: { schedule: cron } }
const functions = planFunctions({ dependenciesSucceeded: true, dependenciesFailed: false, cancelled: false })
@@ -717,16 +770,13 @@ describe('CI workflow run plans', () => {
expect(unnamed).toEqual([])
})
- it.each([...workflowFiles, DEPOT_BACKEND])(
- '%s evaluates every job and step condition under the built-in scenarios',
- (file) => {
- const wf = workflow(file)
- const errors = defaultScenarios(wf, path.join(REPO_ROOT, workflowKey(file))).flatMap((scenario) =>
- planWorkflow(wf, scenario).errors.map((error) => formatPlanError(scenario.name, error))
- )
- expect(errors).toEqual([])
- }
- )
+ it.each(workflowFiles)('%s evaluates every job and step condition under the built-in scenarios', (file) => {
+ const wf = workflow(file)
+ const errors = defaultScenarios(wf, path.join(WORKFLOWS_DIR, file)).flatMap((scenario) =>
+ planWorkflow(wf, scenario).errors.map((error) => formatPlanError(scenario.name, error))
+ )
+ expect(errors).toEqual([])
+ })
it.each(EXPECTATIONS)(
'$file on $scenario.name runs the intended jobs',