Trunk flaky-test upload runs after Free Tests, off the pull request's checks (GST-3303) (#4579)

Pull requests no longer wait on the upload that sends Free Tests results
to Trunk. It now runs on its own after Free Tests finishes.

The quick test tier's flaky passes now reach Trunk too, so a test that
fails once and passes on its retry shows up there wherever it ran.

Nothing to do: no required check changes, and the upload still never
affects whether a check passes.

Refs: GST-3303
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/red-team#1 reader=red-team
Review-Finding: p1/red-team#2 reader=red-team
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-20 23:33:09 +00:00
1 parent 92c57ca4ce
commit faae7f725a
12 files changed
+214 -119

No files matched your search

+19 -61
View File
@@ -8,9 +8,9 @@ name: Free Tests
# provider keys at all — least privilege, and fork PRs get real test signal
# here (the eval matrix skips fork PRs because repository secrets can't reach
# them). test/free-tests-workflow-wiring.test.ts fails CI if a secret sneaks in.
# The exceptions are TRUNK_API_TOKEN in the trunk-dynamic-ci observer and
# TRUNK_ORG_API_TOKEN in the trunk-flaky-tests uploader. Each runs no
# pull-request code and nothing depends on it (see those jobs).
# The one exception is TRUNK_API_TOKEN in the trunk-dynamic-ci observer, which
# runs no pull-request code and nothing depends on it (see that job). The Trunk
# Flaky Tests uploader runs after this workflow, in trunk-flaky-tests.yml.
#
# This is a REQUIRED check from day one (branch protection lists it). If it's
# red, fix or quarantine-with-issue — don't make it advisory; an advisory lane
@@ -588,7 +588,21 @@ jobs:
env:
GSTACK_FREE_RETRY_FLAKY: "1"
GSTACK_FLAKE_LEDGER: ${{ runner.temp }}/flake-ledger.jsonl
run: xvfb-run -a bun run test:quick
run: xvfb-run -a bun run test:quick --junit-dir "$RUNNER_TEMP/quick-junit"
# Kept for trunk-flaky-tests.yml, which uploads them to Trunk as the
# bun-default variant after the run, so a flaky pass here reaches Trunk
# as well as the flake ledger (GST-3303).
- name: Upload the quick tier's JUnit reports
if: always()
timeout-minutes: 3
continue-on-error: true
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: quick-junit
path: ${{ runner.temp }}/quick-junit/*.xml
if-no-files-found: ignore
retention-days: 7
# The quick tier retries a failing file once too, so its flaky passes go
# in the same flake-ledger-* series the aggregate summarizes and
@@ -846,7 +860,7 @@ jobs:
if-no-files-found: error
# bun's JUnit report from every child of this shard, the flaky retry
# included. Only trunk-flaky-tests reads it; no verdict does.
# included. Only trunk-flaky-tests.yml reads it; no verdict does.
- name: Upload shard JUnit reports
if: always()
timeout-minutes: 3
@@ -888,62 +902,6 @@ jobs:
include-hidden-files: true
if-no-files-found: ignore
# Trunk Flaky Tests, DETECTION ONLY (GST-1859). Uploads every free-suite
# shard's JUnit reports, failures included, to the Trunk test collection
# 7yDVXXE3 so Trunk can flag tests that fail and then pass on the same code.
# Nothing is quarantined or skipped: the uploader runs with quarantine off,
# the collection has quarantining off, and no job needs this one or reads it,
# so it cannot change which tests gate or turn free-tests red. It is the only
# job that sees TRUNK_ORG_API_TOKEN (Trunk's v1 organization token; the v2 API
# key in TRUNK_API_TOKEN does not work with the uploader), so the token never
# shares a job with pull-request code: it checks out nothing, downloads only
# the XML artifacts and runs one pinned action with no GITHUB_TOKEN scopes.
# The CLI version is pinned and use-cache is off, so the binary always comes
# from Trunk's checksummed release, never from an Actions cache entry that a
# pull-request job could have written.
# Same-repository pull requests, main pushes and dispatch runs (the CI runs
# lanes dispatch on their own branches, which only someone with write access
# can start); a missing token skips both steps. Dispatch runs were left out
# until GST-3303 found a retried flake on one that Trunk never saw. Fail-open at step and job level. Review:
# docs/TESTING_INTERNALS.md.
trunk-flaky-tests:
name: Trunk Flaky Tests (detection only)
needs: free-suite
if: always() && needs.free-suite.result != 'skipped' && ((github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository))
runs-on: ubuntu-24.04
timeout-minutes: 10
continue-on-error: true
permissions: {}
env:
TRUNK_ORG_API_TOKEN: ${{ secrets.TRUNK_ORG_API_TOKEN }}
steps:
- name: Download every shard's JUnit reports
if: env.TRUNK_ORG_API_TOKEN != ''
timeout-minutes: 3
continue-on-error: true
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
pattern: free-junit-*
path: ${{ runner.temp }}/free-junit
- name: Upload them to Trunk Flaky Tests (detection only, quarantine off)
if: env.TRUNK_ORG_API_TOKEN != ''
timeout-minutes: 5
continue-on-error: true
uses: trunk-io/analytics-uploader@9886de74a788c450c793109577a4d97bfb3e799f # v2.1.8
with:
junit-paths: ${{ runner.temp }}/free-junit/**/*.xml
org-slug: garry-tan
token: ${{ env.TRUNK_ORG_API_TOKEN }}
test-collection-id: 7yDVXXE3
cli-version: 0.17.0
use-cache: 'false'
quarantine: 'false'
use-uncloned-repo: 'true'
github-token: ''
gh-repo-url: ${{ github.server_url }}/${{ github.repository }}
gh-repo-head-sha: ${{ github.event.pull_request.head.sha || github.sha }}
gh-repo-head-branch: ${{ github.event.pull_request.head.ref || github.ref_name }}
# Branch protection already requires the `free-tests` context. Keep that
# stable name as an always-running aggregate so every platform-specific CSO
# gate is merge-blocking without a separate branch-protection migration.
+106
View File
@@ -0,0 +1,106 @@
# Trunk Flaky Tests, DETECTION ONLY (GST-1859). After every Free Tests run
# completes, this uploads that run's JUnit reports, failures included, to the
# Trunk test collection 7yDVXXE3 so Trunk can flag tests that fail and then
# pass on the same code: every free-suite shard's reports (free-junit-*), and
# the quick tier's on the install-default Bun (quick-junit) as the separate
# bun-default variant, since the same files also run on the pinned Bun.
#
# It runs from workflow_run instead of as a free-tests.yml job (GST-3303), so a
# pull request's checks no longer wait on it; it was the last job to finish in
# about one Free Tests run in four (61 of 223, 11-06 to 11-20). A workflow_run
# workflow runs from the default branch's copy of this file, never from the
# pull request's.
#
# Nothing is quarantined or skipped: the uploader runs with quarantine off, the
# collection has quarantining off, and nothing reads this workflow's result, so
# it cannot change which tests gate or turn a check red. It is the only job that
# sees TRUNK_ORG_API_TOKEN (Trunk's v1 organization token; the v2 API key in
# TRUNK_API_TOKEN does not work with the uploader). It checks out nothing, runs
# no shell, downloads only the XML artifacts of the run that triggered it, and
# its GITHUB_TOKEN can only read Actions artifacts. The CLI version is pinned
# and use-cache is off, so the binary always comes from Trunk's checksummed
# release, never from an Actions cache entry a pull-request job could write.
# Same-repository pull requests, main pushes and dispatch runs (which only
# someone with write access can start), as before; fork pull requests are
# skipped because workflow_run hands this workflow repository secrets, which
# must never meet a fork's artifacts.
# A missing token skips every step. Fail-open at step and job level. Review:
# docs/TESTING_INTERNALS.md.
name: Trunk Flaky Tests
on:
workflow_run:
workflows: [Free Tests]
types: [completed]
permissions: {}
jobs:
trunk-flaky-tests:
name: Trunk Flaky Tests (detection only)
if: github.event.workflow_run.conclusion != 'skipped' && ((github.event.workflow_run.event == 'push' && github.event.workflow_run.head_branch == 'main') || github.event.workflow_run.event == 'workflow_dispatch' || (github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.head_repository.full_name == github.repository))
runs-on: ubuntu-24.04
timeout-minutes: 10
continue-on-error: true
permissions:
actions: read
env:
TRUNK_ORG_API_TOKEN: ${{ secrets.TRUNK_ORG_API_TOKEN }}
steps:
- name: Download every shard's JUnit reports from the Free Tests run
if: env.TRUNK_ORG_API_TOKEN != ''
timeout-minutes: 3
continue-on-error: true
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
pattern: free-junit-*
path: ${{ github.workspace }}/free-junit
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
- name: Download the quick tier's JUnit reports from the Free Tests run
if: env.TRUNK_ORG_API_TOKEN != ''
timeout-minutes: 3
continue-on-error: true
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
name: quick-junit
path: ${{ github.workspace }}/quick-junit
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
- name: Upload the shard reports to Trunk Flaky Tests (detection only, quarantine off)
if: env.TRUNK_ORG_API_TOKEN != '' && hashFiles('free-junit/**/*.xml') != ''
timeout-minutes: 5
continue-on-error: true
uses: trunk-io/analytics-uploader@9886de74a788c450c793109577a4d97bfb3e799f # v2.1.8
with:
junit-paths: ${{ github.workspace }}/free-junit/**/*.xml
org-slug: garry-tan
token: ${{ env.TRUNK_ORG_API_TOKEN }}
test-collection-id: 7yDVXXE3
cli-version: 0.17.0
use-cache: 'false'
quarantine: 'false'
use-uncloned-repo: 'true'
github-token: ''
gh-repo-url: ${{ github.server_url }}/${{ github.repository }}
gh-repo-head-sha: ${{ github.event.workflow_run.head_sha }}
gh-repo-head-branch: ${{ github.event.workflow_run.head_branch }}
- name: Upload the quick tier's reports as the bun-default variant (detection only, quarantine off)
if: env.TRUNK_ORG_API_TOKEN != '' && hashFiles('quick-junit/**/*.xml') != ''
timeout-minutes: 5
continue-on-error: true
uses: trunk-io/analytics-uploader@9886de74a788c450c793109577a4d97bfb3e799f # v2.1.8
with:
junit-paths: ${{ github.workspace }}/quick-junit/**/*.xml
org-slug: garry-tan
token: ${{ env.TRUNK_ORG_API_TOKEN }}
test-collection-id: 7yDVXXE3
cli-version: 0.17.0
use-cache: 'false'
quarantine: 'false'
use-uncloned-repo: 'true'
variant: bun-default
github-token: ''
gh-repo-url: ${{ github.server_url }}/${{ github.repository }}
gh-repo-head-sha: ${{ github.event.workflow_run.head_sha }}
gh-repo-head-branch: ${{ github.event.workflow_run.head_branch }}