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): add artifacts to Depot backend CI (#96923)

Raúl Negrón-Oteroaaa446e57660
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.yml
index ffdcbd029b91..4c4bb74e6e76 100644
--- a/.depot/workflows/ci-backend.yml
+++ b/.depot/workflows/ci-backend.yml
@@ -18,7 +18,7 @@
# canonical: Depot resolves ./.github/actions/<x> from .depot/actions/<x>, so a missing
# mirror fails the step at setup with "action manifest not found".
# - permissions: pull-requests:read (no comment/auto-commit side effects)
-# - Stripped side effects: artifact uploads, CI report section posters (canonical
+# - Stripped side effects: CI report section posters (canonical
# additionally skips these on trunk-merge/** branches to save GITHUB_TOKEN budget;
# the shadow strips them entirely, so that gating has nothing to mirror), snapshot
# auto-commit (handle-snapshots), posthog-github-action telemetry (including the
@@ -26,25 +26,18 @@
# stay apples-to-apples, they just have no consumer here; canonical mints the
# telemetry token from the GH_APP_TELEMETRY_APP_ID org variable rather than the
# secret, which the shadow has no token step to mirror),
-# --store-durations write, and test-selection verdict.
+# test-selection verdict.
# - Trunk uploads and quarantine verdicts match canonical only when side effects
# are enabled. Disabled test steps retain their direct failure verdict.
# - dynamic-ci-filter: canonical asks Trunk which jobs a diff needs and records the verdict
# in that job's log. Nothing reads its outputs, so the job and its action pin are
# depot-exempt. Its fail-open step and its `no-ci` draft guard belong to that job, so
# they need no depot bump either.
-# - Per-test failure rollup: canonical's django_tests gate uploads product JUnit and, when a
-# test job fails, downloads that shard's JUnit to list the actual failing tests. The shadow
-# strips artifact uploads (above), so it has nothing to download and keeps the plain
-# dependency-result table — depot-exempt for the same reason as the other uploads.
-# - report-test-timings: canonical emits per-test OTLP spans from the uploaded JUnit. The shadow
-# strips artifact uploads (above) and posts no telemetry, so the whole job is depot-exempt —
-# changes confined to it (script deps, the reporter's availability guard, emission secret
-# plumbing such as dual-project tokens, the JUnit-artifact download pattern, re-run attempt
-# handling — including the attempt-suffixed junit artifact names canonical uploads so the
-# reporter can pair re-run recoveries with attempt-1 failures, and the guard that skips the
-# job when both test matrices were skipped, with the needs: entries that feed it) need no
-# depot bump.
+# - Artifact uploads, run-scoped sharding plans, and the failing-test rollup
+# require side effects, including duration writes. Depot stores these separately
+# from GitHub Actions.
+# - report-test-timings and the other telemetry jobs remain omitted until their
+# events distinguish the CI engine and use Depot run metadata.
# - Hourly scheduled master run: canonical no longer runs the test matrices on master push
# (the merge queue's trunk-merge/** run gates every commit) and runs them from an hourly
# `schedule` trigger instead — the shape this shadow always had (its `!= 'push'` gates on
@@ -55,11 +48,8 @@
# - mirror-schema-cache: canonical's master run copies the migrated schema dump out of the
# migrated-schema artifact into GitHub Actions Cache, so fork PRs (which run without
# secrets and cannot authenticate to Depot Cache) prime instead of migrating from scratch.
-# The shadow strips artifact uploads (above) and routes every cache write to Depot Cache
-# (below), so it has neither the artifact to download nor a GitHub cache to fill: the job,
-# and the check-migrations mig_schema_key output that feeds it, are depot-exempt.
-# - migrated-schema upload settings: canonical tunes the upload retention; the shadow
-# strips artifact uploads (above), so those changes are depot-exempt.
+# The shadow routes cache writes to Depot Cache, so it must not fill the GitHub
+# cache. This job and the mig_schema_key output that feeds it remain depot-exempt.
# - OpenAPI types: validation remains a separate job like canonical, but its
# auto-commit side effect is dropped
# - sqlmigrate SQL preview: canonical's check-migrations resolves changed migration files
@@ -67,13 +57,11 @@
# failure to a placeholder before posting the SQL preview comment. The shadow strips
# comment side effects (above) and runs no sqlmigrate loop, so those changes need no
# depot bump.
-# - Deterministic-failure self-cancel: canonical cancels its own run when repo-checks or
-# check-openapi-types fails deterministically, and ORs those jobs' deterministic_failure
-# outputs onto the gate condition so a real failure still reports failure rather than
-# cancelled. The shadow has neither the cancelling jobs nor those outputs, so the
-# disjuncts are depot-exempt. The gate keeps its sampling `&&` for the same reason
-# canonical may not use one: an `&&` can skip the gate, and only here is that harmless,
-# because this status never blocks a merge.
+# - Deterministic-failure self-cancel remains omitted: the injected Depot job token
+# cannot authorize the CLI's run lookup. Workflow-name expressions also 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: gated on the test-new-events-schema label only; canonical also
# doubles the matrices on workflow_dispatch, but shadow dispatches stay legacy-only so
# trial runs do the same work as sampled PR runs
@@ -115,10 +103,6 @@
# - Test durations restored from Depot Cache (posthog-test-durations- prefix), refreshed by
# .depot/workflows/ci-backend-update-test-timing.yml, so shard counts match GitHub Actions.
# Committed .test_durations is the fallback.
-# - Sharding-plan pinning: canonical snapshots the durations files as a run-scoped
-# artifact and every test job applies it, so re-runs shard like attempt 1. The shadow
-# strips artifact uploads (above), so it keeps floating restores; no depot bump needed
-# for changes confined to that pinning.
# - master (push) runs only check-migrations to prime the shared schema cache; the
# test matrices are skipped on master (canonical runs them). Sampled source PRs and
# dispatches run the full graph — that is where the apples-to-apples comparison happens.
@@ -305,6 +289,7 @@ jobs:
# filter says false. Nothing under .github/ is in the backend filter, so
# a sharding or timing script change was untestable on its own PR.
backend: ${{ contains(github.event.pull_request.labels.*.name, 'run-ci-backend') && 'true' || (steps.filter.outputs.backend || 'true') }}
+ timing_scripts: ${{ fromJSON(toJSON(steps.filter.outputs)).timing_scripts }}
backend_files: ${{ steps.filter.outputs.backend_files }}
migrations: ${{ steps.filter.outputs.migrations || 'true' }}
migrations_files: ${{ steps.filter.outputs.migrations_files }}
@@ -541,6 +526,9 @@ jobs:
- 'products/db_routing.yaml'
- 'posthog/product_db_config.py'
- 'posthog/product_db_router.py'
+ timing_scripts:
+ - '.github/scripts/optimize_test_durations.py'
+ - '.github/scripts/turbo-discover.js'
tasks_temporal:
- 'products/tasks/backend/temporal/**/*'
repo_invariants:
@@ -613,7 +601,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: [sample, 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
@@ -811,6 +799,29 @@ jobs:
with:
enable-cache: false
+ - name: Snapshot the sharding plan for this run
+ if: ${{ needs.sample.outputs.side_effects == '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.
+ # Every test job applies this snapshot instead, so all attempts shard
+ # identically. Best-effort (consumers fall back to the floating caches);
+ # overwrite lets a "re-run all jobs" attempt re-snapshot.
+ continue-on-error: true
+ uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
+ with:
+ name: test-durations-plan
+ path: |
+ .test_durations
+ .test_durations.core
+ .test_durations.temporal
+ include-hidden-files: true
+ overwrite: true
+ # The per-segment files are cache-only and may legitimately be absent.
+ if-no-files-found: warn
+ # GitHub allows re-runs for 30 days.
+ retention-days: 30
+
- name: Run the backend test selector
id: select
# A selector failure or hang must not fail this job, which gates every test job
@@ -858,6 +869,18 @@ jobs:
echo "django_shards=$(echo "$RESULT" | jq -c '.django_shards // empty')" >> $GITHUB_OUTPUT
echo "$RESULT" | jq -r '"mode=\(.selection.mode)", "selection=\(.selection | tojson)", "telemetry=\(.telemetry | tojson)"' >> "$GITHUB_OUTPUT"
+ - name: Upload selection artifact
+ # 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: ${{ needs.sample.outputs.side_effects == 'true' && (always() && steps.select.outcome == 'success') }}
+ uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
+ with:
+ name: select-tests-output
+ path: /tmp/selection.json
+ if-no-files-found: ignore
+ retention-days: 14
+
# Depot shadow note: canonical uploads /tmp/selection.json for its
# test-selection-verdict job. The shadow strips that job and all artifact
# uploads, so there is no Upload selection artifact step here.
@@ -1167,6 +1190,32 @@ jobs:
fi
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.sample.outputs.side_effects == 'true' }}
+ # Same pinning as the Django job; falls back to the floating cache.
+ id: pinned-plan
+ continue-on-error: true
+ uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
+ with:
+ name: test-durations-plan
+ path: /tmp/test-durations-plan
+
+ - name: Apply the pinned sharding plan
+ if: ${{ needs.sample.outputs.side_effects == 'true' && (steps.pinned-plan.outcome == 'success') }}
+ shell: bash
+ run: |
+ if [ ! -f /tmp/test-durations-plan/.test_durations ]; then
+ echo "::warning::Sharding-plan snapshot is incomplete, keeping the floating cache restore"
+ exit 0
+ fi
+ cp /tmp/test-durations-plan/.test_durations .test_durations
+ echo "Sharding plan pinned to this run's snapshot"
+
+ - name: Warn when a re-run reshards unpinned
+ if: ${{ needs.sample.outputs.side_effects == '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: ${{ needs.sample.outputs.side_effects == 'true' }}
id: run-product-tests
@@ -1205,6 +1254,7 @@ jobs:
PYTEST_ADDOPTS: >-
--reuse-db
--durations-path ../../.test_durations
+ ${{ needs.sample.outputs.side_effects == 'true' && github.ref == 'refs/heads/master' && '--store-durations' || '' }}
${{ needs.sample.outputs.side_effects == '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=xml:coverage.xml' || '' }}
@@ -1290,6 +1340,60 @@ jobs:
shell: bash
run: exit 1
+ - name: Stage product JUnit
+ if: ${{ needs.sample.outputs.side_effects == 'true' && (always()) }}
+ shell: bash
+ run: |
+ mkdir -p junit-staging
+ for f in products/*/junit-product.xml; do
+ [ -f "$f" ] || continue
+ cp "$f" "junit-staging/junit-product-$(basename "$(dirname "$f")").xml"
+ done
+
+ - name: Upload product test results
+ uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
+ if: ${{ needs.sample.outputs.side_effects == 'true' && (always()) }}
+ with:
+ name: product-junit-results-${{ strategy.job-index }}
+ path: junit-staging/junit-product-*.xml
+ if-no-files-found: ignore
+ overwrite: true # artifacts are immutable per run; re-run shards would 409 otherwise
+
+ - name: Upload timing data
+ uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
+ # Only the legacy-schema variant uploads durations — both schema variants run the
+ # same test IDs, and two artifacts for the same tests would race in the merge.
+ if: ${{ needs.sample.outputs.side_effects == 'true' && (github.ref == 'refs/heads/master' && !matrix.new-events-schema) }}
+ with:
+ name: timing_data-Products-${{ strategy.job-index }}
+ path: .test_durations
+ include-hidden-files: true
+ retention-days: 2
+
+ - name: Stage product coverage
+ # Rename each products/<name>/coverage.xml to <name>.xml so the product name
+ # survives upload-artifact's least-common-ancestor path collapse.
+ if: ${{ needs.sample.outputs.side_effects == 'true' && (always() && github.event_name == 'pull_request') }}
+ shell: bash
+ run: |
+ mkdir -p cov-staging
+ for f in products/*/coverage.xml; do
+ [ -f "$f" ] || continue
+ product=$(basename "$(dirname "$f")")
+ cp "$f" "cov-staging/${product}.xml"
+ done
+
+ - name: Upload product coverage
+ uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
+ # always(): a failing test shard still has partial coverage worth reporting.
+ if: ${{ needs.sample.outputs.side_effects == 'true' && (always() && github.event_name == 'pull_request') }}
+ with:
+ name: coverage-xml-${{ strategy.job-index }}
+ path: cov-staging/*.xml
+ if-no-files-found: ignore
+ retention-days: 2
+ overwrite: true # artifacts are immutable per run; re-run shards would 409 otherwise
+
# Lightweight repo-wide checks that only need Python + uv (no Docker/DB).
# Consolidates checks that previously each spun up their own runner.
repo-checks:
@@ -1435,7 +1539,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: [sample, 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
@@ -1649,6 +1753,16 @@ jobs:
docker compose -f docker-compose.dev.yml exec -T db pg_dump --data-only --table=django_migrations -U posthog posthog) | gzip > schema.sql.gz
# Verify the dump is valid
gunzip -t schema.sql.gz
+
+ - name: Upload migrated schema artifact
+ if: ${{ needs.sample.outputs.side_effects == 'true' && (github.event_name == 'push') }}
+ uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
+ with:
+ name: migrated-schema
+ path: schema.sql.gz
+ # Consumers only ever take the newest artifact, so a longer window just
+ # adds pages to the artifacts listing that db:download-schema walks.
+ retention-days: 7
- name: Save schema to Actions cache for PR shards
# Kept as the exact PR-base key that every consumer's restore-keys falls back to.
if: github.event_name == 'push'
@@ -1707,6 +1821,7 @@ jobs:
fi
# Same as above, except now for CH looking at files that were added in posthog/clickhouse/migrations/
git diff --name-status "$DIFF_BASE"..HEAD | grep "A\sposthog/clickhouse/migrations/" | grep -v README | awk '{print $2}' | python manage.py test_ch_migrations_are_safe
+
check-openapi-types:
needs: [changes]
# Not on master push: master only primes the schema cache.
@@ -2483,6 +2598,38 @@ jobs:
echo "Docker containers:"
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" || true
echo "==================================="
+ - name: Download the run's sharding plan snapshot
+ if: ${{ needs.sample.outputs.side_effects == '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
+ continue-on-error: true
+ uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
+ with:
+ name: test-durations-plan
+ path: /tmp/test-durations-plan
+
+ - name: Apply the pinned sharding plan
+ if: ${{ needs.sample.outputs.side_effects == 'true' && (steps.pinned-plan.outcome == 'success') }}
+ shell: bash
+ run: |
+ if [ ! -f /tmp/test-durations-plan/.test_durations ]; then
+ echo "::warning::Sharding-plan snapshot is incomplete, keeping the floating cache restores"
+ exit 0
+ fi
+ # rm first so segment files the snapshot lacks don't survive the floating restore
+ rm -f .test_durations.core .test_durations.temporal
+ cp /tmp/test-durations-plan/.test_durations .test_durations
+ for f in .test_durations.core .test_durations.temporal; do
+ if [ -f "/tmp/test-durations-plan/$f" ]; then cp "/tmp/test-durations-plan/$f" "$f"; fi
+ done
+ echo "Sharding plan pinned to this run's snapshot"
+
+ - name: Warn when a re-run reshards unpinned
+ if: ${{ needs.sample.outputs.side_effects == '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: ${{ needs.sample.outputs.side_effects == 'true' }}
id: run-core-tests
@@ -2591,7 +2738,7 @@ jobs:
--ignore=posthog/test/repo_invariants \
"${full_ignores[@]}" \
--splits ${{ matrix.concurrency }} --group ${{ matrix.group }} \
- --durations=1000 --durations-min=1.0 \
+ --durations=1000 --durations-min=1.0 ${{ needs.sample.outputs.side_effects == 'true' && '--store-durations' || '' }} \
--pytest-durations=100 \
--splitting-algorithm="$SPLITTING_ALGORITHM" \
"${SPLIT_GRANULARITY[@]}" \
@@ -2689,7 +2836,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 \
+ --durations=100 --durations-min=1.0 ${{ needs.sample.outputs.side_effects == 'true' && '--store-durations' || '' }} \
--pytest-durations=100 \
--splitting-algorithm="$SPLITTING_ALGORITHM" \
"${SPLIT_GRANULARITY[@]}" \
@@ -2732,6 +2879,46 @@ jobs:
shell: bash
run: docker compose -f docker-compose.dev.yml logs
+ - name: Upload test results
+ uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
+ if: ${{ needs.sample.outputs.side_effects == '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
+ # (attempt-N pass) with the attempt-1 failure it proves flaky.
+ name: junit-results-backend-${{ matrix.artifact_key }}${{ github.run_attempt != '1' && format('-attempt{0}', github.run_attempt) || '' }}
+ path: |
+ junit-*.xml
+ !junit-*-retry-failures.xml
+
+ - name: Archive email renders
+ uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
+ if: ${{ needs.sample.outputs.side_effects == '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__
+ retention-days: 1
+
+ - name: Upload core coverage
+ uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
+ if: ${{ needs.sample.outputs.side_effects == 'true' && (always() && github.event_name == 'pull_request' && needs.turbo-discover.outputs.mode != 'selected' && matrix.segment == 'Core') }}
+ with:
+ name: coverage-core-${{ strategy.job-index }}
+ path: coverage-core.xml
+ if-no-files-found: ignore
+ retention-days: 2
+ overwrite: true # artifacts are immutable per run; re-run shards would 409 otherwise
+
+ - 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: ${{ needs.sample.outputs.side_effects == 'true' && ((github.ref == 'refs/heads/master' || 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
+ include-hidden-files: true
+ retention-days: 2
+
# Exports TRUNK_CODEOWNERS_PATH for the uploads below, so Trunk attributes each test to
# the team that owns its file. The guard is for an unrebased branch: this job checks out
# the PR head ref, which may predate the script. Without it the uploader keeps reading
@@ -2881,7 +3068,7 @@ jobs:
]
name: '[optional, does not block merge] Django Tests Pass'
runs-on: depot-ubuntu-24.04
- timeout-minutes: 5
+ timeout-minutes: 8
# !cancelled() collates skipped/failed matrix jobs without reporting failure on a
# superseded run (mirrors canonical); gated on the sampling result so it doesn't
# spin up a lone runner when this run was sampled out (or the shadow is off).
@@ -2905,8 +3092,97 @@ jobs:
echo "| turbo-tests | ${{ needs.turbo-tests.result }} |"
} | tee -a "$GITHUB_STEP_SUMMARY"
+ - name: Download shard JUnit results
+ if: ${{ needs.sample.outputs.side_effects == 'true' && (always() && (needs.django.result != 'success' || needs.turbo-tests.result != 'success')) }}
+ continue-on-error: true
+ uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
+ with:
+ pattern: '{junit-results-backend,product-junit-results}-*'
+ path: /tmp/junit-gate/
+
+ - name: Keep only each shard's latest attempt
+ if: ${{ needs.sample.outputs.side_effects == '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
+ shopt -s nullglob
+ for d in *-attempt[0-9]*; do
+ base="${d%-attempt*}"
+ latest="$(printf '%s\n' "$base"-attempt[0-9]* | sort -V | tail -1)"
+ rm -rf "$base"
+ [[ "$d" == "$latest" ]] || rm -rf "$d"
+ done
+
- name: Check dependency results
+ env:
+ SIDE_EFFECTS: ${{ needs.sample.outputs.side_effects }}
run: |
+ if [ "$SIDE_EFFECTS" = "true" ]; then
+ # Per-test failure rollup, emitted from THIS step because GitHub only
+ # auto-expands the failed step in the log view. Best-effort via `|| true`
+ # so a parser hiccup never changes the verdict computed below.
+ python3 <<'PY' || true
+ import glob, os, xml.etree.ElementTree as ET
+
+ ROOT = "/tmp/junit-gate"
+ rows = [] # (shard, nodeid, repo_file, message)
+
+ def clean(s):
+ # Collapse newlines so PR-authored test names can't inject ::workflow-commands::
+ return " ".join((s or "").split())
+
+ for path in glob.glob(os.path.join(ROOT, "**", "junit-*.xml"), recursive=True):
+ artifact = os.path.relpath(path, ROOT).split(os.sep)[0]
+ base = os.path.basename(path)
+ # Product JUnit is staged as junit-product-<name>.xml; backend keeps its key.
+ product = base[len("junit-product-"):-len(".xml")] if base.startswith("junit-product-") else ""
+ shard = f"products/{product}" if product else artifact.removeprefix("junit-results-backend-")
+ with open(path, "rb") as fh:
+ raw = fh.read()
+ # Refuse DTD/entity payloads (XXE, billion-laughs). pytest JUnit has neither,
+ # so real failures are never dropped; a crafted file is simply skipped.
+ if b"<!DOCTYPE" in raw or b"<!ENTITY" in raw:
+ continue
+ try:
+ tree = ET.fromstring(raw)
+ except ET.ParseError:
+ continue
+ for tc in tree.iter("testcase"):
+ bad = tc.find("failure")
+ if bad is None:
+ bad = tc.find("error")
+ if bad is None:
+ continue
+ name = tc.get("name", "")
+ file_ = tc.get("file", "") or tc.get("classname", "")
+ repo_file = f"products/{product}/{file_}" if product and file_ else file_
+ nodeid = clean("::".join(p for p in (repo_file, name) if p))
+ msg = clean(bad.get("message") or bad.text or "")[:200]
+ rows.append((clean(shard), nodeid, clean(repo_file), msg))
+
+ # Print only when something failed; on a green gate this stays silent.
+ if rows:
+ out = ["### Failing backend & product tests", "", f"{len(rows)} failing test(s):",
+ "", "| Shard | Test | Message |", "| --- | --- | --- |"]
+ for shard, nodeid, _f, msg in rows[:100]:
+ out.append(f"| {shard} | `{nodeid.replace('|', r'\|')}` | {msg.replace('|', r'\|')} |")
+ if len(rows) > 100:
+ out += ["", f"…and {len(rows) - 100} more."]
+ text = "\n".join(out) + "\n"
+ summary = os.environ.get("GITHUB_STEP_SUMMARY")
+ if summary:
+ with open(summary, "a") as fh:
+ fh.write(text)
+ print(text)
+ for shard, nodeid, repo_file, msg in rows[:30]:
+ title = f"Backend test failed ({shard})"
+ body = f"{nodeid}: {msg}" if msg else nodeid
+ loc = f"file={repo_file}," if repo_file else ""
+ print(f"::error {loc}title={title}::{body}")
+ PY
+
+ fi
+
check_required_result() {
local label="$1"
local result="$2"