Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions .github/actions/flaky-tests-quarantine/action.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
name: Flaky tests set aside
description: >-
Reads the tests set aside (the open flaky-test issues scripts/flaky-tests-watch.ts marked) once,
with the job's token, and writes them to flaky-tests-quarantine.json in the runner's temporary
folder, where the job's test steps read them (scripts/flaky-tests.ts). The test steps hold no
token and never ask GitHub themselves, so neither does a test they run. A read that fails writes
why, sets nothing aside, and fails nothing.
Writes the tests set aside, as CI's `changes` job read them once for the whole run (the open
flaky-test issues scripts/flaky-tests-watch.ts marked), to flaky-tests-quarantine.json in the
runner's temporary folder, where the job's test steps read them (scripts/flaky-tests.ts). It asks
GitHub nothing: the test steps hold no token, and neither does a test they run. An empty or
missing list sets nothing aside.
# The caller checks the repository out and sets up Bun first, and grants `issues: read`.
# The caller checks the repository out first.

inputs:
list:
description: The tests set aside, as JSON (`changes`'s `flaky_tests` output).
required: false
default: ""

runs:
using: composite
steps:
- name: The tests set aside
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: bun scripts/flaky-tests.ts quarantine "$RUNNER_TEMP/flaky-tests-quarantine.json"
LIST: ${{ inputs.list }}
run: |
if [ -n "$LIST" ]; then printf '%s\n' "$LIST"; else echo '{"tests":{}}'; fi \
> "$RUNNER_TEMP/flaky-tests-quarantine.json"
41 changes: 28 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ jobs:
# To read which jobs passed on the commits this one sits on, and to cancel this run at its
# first failure (.github/actions/stop-on-failure).
actions: write
# To read the tests set aside (the open flaky-test issues), once for the whole run.
issues: read
outputs:
# The tests set aside, as JSON, for every test job's flaky-tests-quarantine step.
flaky_tests: ${{ steps.flaky.outputs.list }}
static: ${{ steps.decide.outputs.static }}
api: ${{ steps.decide.outputs.api }}
mobile: ${{ steps.decide.outputs.mobile }}
Expand Down Expand Up @@ -131,6 +135,17 @@ jobs:
# main's own run of the same push.
WORKFLOW_NAME: ${{ github.workflow }}
run: bun scripts/ci-changes.ts ci
# The tests set aside, read here once for the run with one request, and handed to each test
# job, whose steps hold no token (scripts/flaky-tests.ts). A read that fails, a rate limit
# included, sets nothing aside with a warning and never fails this job.
- id: flaky
name: The tests set aside
env:
GH_TOKEN: ${{ github.token }}
run: |
list="$RUNNER_TEMP/flaky-tests-quarantine.json"
bun scripts/flaky-tests.ts quarantine "$list" || echo '{"tests":{},"error":"the read did not finish"}' > "$list"
echo "list=$(cat "$list")" >> "$GITHUB_OUTPUT"
# On a failure, cancels the run at once (.github/actions/stop-on-failure).
- if: failure()
uses: $/.github/actions/stop-on-failure
Expand Down Expand Up @@ -447,8 +462,6 @@ jobs:
contents: read
# To cancel this run at its first failure (.github/actions/stop-on-failure).
actions: write
# To read the tests set aside (open flaky-test issues, scripts/flaky-tests.ts).
issues: read
env:
PLAYWRIGHT_IMAGE: mcr.microsoft.com/playwright:v1.62.1-noble@sha256:dcc5531e97840b9b5e794f2814476b21571c5124a3fca2267d73041f56e7580e
steps:
Expand All @@ -459,9 +472,11 @@ jobs:
with:
bun-version: 1.4.3
- run: bun install --frozen-lockfile
# The tests set aside, read once with the job's token; the test steps hold none
# (.github/actions/flaky-tests-quarantine). As in every job that runs tests.
# The tests set aside, as `changes` read them for the run, written where the test steps read
# them; they hold no token (.github/actions/flaky-tests-quarantine). As in every test job.
- uses: $/.github/actions/flaky-tests-quarantine
with:
list: ${{ needs.changes.outputs.flaky_tests }}
# The app's real-browser tests: a running step's words
# under reduced motion, where onboarding's Back lands beside the Mac window's buttons, the name
# step's orb drawn whole under the step dashes, onboarding's reels playing each scene on their
Expand Down Expand Up @@ -717,8 +732,6 @@ jobs:
contents: read
# To cancel this run at its first failure (.github/actions/stop-on-failure).
actions: write
# To read the tests set aside (open flaky-test issues, scripts/flaky-tests.ts).
issues: read
env:
PLAYWRIGHT_IMAGE: mcr.microsoft.com/playwright:v1.62.1-noble@sha256:dcc5531e97840b9b5e794f2814476b21571c5124a3fca2267d73041f56e7580e
TEST_WORKERS: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository && '2' || '8' }}
Expand All @@ -736,6 +749,8 @@ jobs:
- run: bun install --frozen-lockfile
- run: bun run generate:app-config
- uses: $/.github/actions/flaky-tests-quarantine
with:
list: ${{ needs.changes.outputs.flaky_tests }}
- run: |
# One file per line, sorted: pull requests that each add a file then merge cleanly.
files=(
Expand Down Expand Up @@ -928,8 +943,6 @@ jobs:
contents: read
# To cancel this run at its first failure (.github/actions/stop-on-failure).
actions: write
# To read the tests set aside (open flaky-test issues, scripts/flaky-tests.ts).
issues: read
env:
PLAYWRIGHT_IMAGE: mcr.microsoft.com/playwright:v1.62.1-noble@sha256:dcc5531e97840b9b5e794f2814476b21571c5124a3fca2267d73041f56e7580e
steps:
Expand All @@ -943,6 +956,8 @@ jobs:
- run: bun install --frozen-lockfile
working-directory: desktop
- uses: $/.github/actions/flaky-tests-quarantine
with:
list: ${{ needs.changes.outputs.flaky_tests }}
# A list, as in the jobs above, so scripts/ci-changes.ts can tell this job covers the file and a
# change to it does not run it a second time in `tests (changed files)`. Paths from desktop/.
# Under scripts/flaky-tests.ts, as the lists above.
Expand Down Expand Up @@ -992,8 +1007,6 @@ jobs:
contents: read
# To cancel this run at its first failure (.github/actions/stop-on-failure).
actions: write
# To read the tests set aside (open flaky-test issues, scripts/flaky-tests.ts).
issues: read
strategy:
# Every shard runs to the end, so one red run names every failing test, not just the first
# shard's. On a pull request the first failure anywhere stops the whole run instead
Expand Down Expand Up @@ -1021,10 +1034,12 @@ jobs:
# pinned by the desktop lockfile rather than the root one.
- run: bun install --frozen-lockfile
working-directory: desktop
# The tests set aside, read once with the job's token (.github/actions/flaky-tests-quarantine).
# The tests set aside, as `changes` read them for the run (.github/actions/flaky-tests-quarantine).
# A `uses` step: the upstream upgrade runs this job's `run` steps without it, and the suite
# below, which they run, holds no token.
- uses: $/.github/actions/flaky-tests-quarantine
with:
list: ${{ needs.changes.outputs.flaky_tests }}
# This shard's tests, failing on a failed test or on a count it cannot read. The floor under the
# count is the suite's, so the `tests` job checks it on the sum of the shards. A failed test
# runs once more, and a test set aside does not fail the shard (scripts/flaky-tests.ts).
Expand Down Expand Up @@ -1102,8 +1117,6 @@ jobs:
contents: read
# To cancel this run at its first failure (.github/actions/stop-on-failure).
actions: write
# To read the tests set aside (open flaky-test issues, scripts/flaky-tests.ts).
issues: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -1118,6 +1131,8 @@ jobs:
- run: bun install --frozen-lockfile
working-directory: desktop
- uses: $/.github/actions/flaky-tests-quarantine
with:
list: ${{ needs.changes.outputs.flaky_tests }}
- name: Install Chromium
if: needs.changes.outputs.browser_tests != '[]' || needs.changes.outputs.desktop_browser_tests != '[]'
run: bunx playwright-core install --with-deps --no-shell chromium
Expand Down
48 changes: 31 additions & 17 deletions .github/workflows/flaky-tests.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
name: Flaky tests

# Every 20 minutes: reads the "Flaky tests" notes CI's test steps left on the runs that finished since
# it last looked (scripts/flaky-tests.ts), and keeps one `flaky-test` issue per flaky test
# After each run of CI from the merge queue or on main: reads the "Flaky tests" notes that one run's
# test steps left (scripts/flaky-tests.ts), and keeps one `flaky-test` issue per flaky test
# (scripts/flaky-tests-watch.ts). A test that failed and then passed on its retry opens its issue,
# with an owner and a review date, and is set aside while the issue is open: it still runs, and its
# failures do not fail CI. A test set aside that passes 60 runs in a row first time is released, and
# its issue closed. On a timer rather than after every run, and within a set number of requests: the
# repository's token is shared by every workflow. It reads runs and their notes through the API only;
# nothing here checks out or runs a pull request's code, and runs from forks are left alone.
# its issue closed.
#
# It reads only the run that woke it, in at most 25 requests (two when the run left no note), and
# stops when the token's hour runs low: the repository's token is shared by every workflow. A rate
# limit or an API error is a warning; this never fails. Pull requests' runs are left to the queue's:
# a pull request's own change may be what fails, and the queue tests the same tests on main.
# It reads runs and their notes through the API only; nothing here checks out or runs a pull
# request's code, and runs from forks are left alone.
on:
schedule:
- cron: "*/20 * * * *"
workflow_run:
workflows: [CI]
types: [completed]
workflow_dispatch:
inputs:
run:
description: The id of a run to read.
required: true
type: string
dry_run:
description: Say what would change, and change nothing.
type: boolean
Expand All @@ -21,20 +31,19 @@ on:
permissions:
contents: read

# One at a time, so two never write one issue at once.
concurrency:
group: flaky-tests
cancel-in-progress: false

jobs:
watch:
name: flaky tests
# A run of the merge queue or of main, or one asked for by hand; a pull request's needs nothing.
if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.event == 'merge_group' || github.event.workflow_run.event == 'push'
runs-on: ubuntu-24.04
timeout-minutes: 10
timeout-minutes: 5
# One at a time, so two never write one issue at once, and none piles up behind another.
concurrency:
group: flaky-tests
cancel-in-progress: false
permissions:
contents: read
# To list the runs that finished, and where this workflow last left off.
actions: read
# To read the notes the test steps left on their jobs.
checks: read
# To open, update, reopen and close the flaky-test issues.
Expand All @@ -43,19 +52,24 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
sparse-checkout: |
scripts/flaky-tests.ts
scripts/flaky-tests-watch.ts
sparse-checkout-cone-mode: false
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: 1.4.3
no-cache: true
- name: Flaky tests
env:
GH_TOKEN: ${{ github.token }}
WATCHED: CI
# The jobs that run tests: only their notes are read.
JOBS: ^(tests \(|app \(real browser)
RUN_ID: ${{ inputs.run }}
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run }}
run: |
set -euo pipefail
set -uo pipefail
args=()
if [ -n "$RUN_ID" ]; then args+=(--run "$RUN_ID"); fi
if [ "$DRY_RUN" = true ]; then args+=(--dry-run); fi
bun scripts/flaky-tests-watch.ts "${args[@]}"
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ jobs:
# CI's `release note` asks for it, to read a pull request's description. It runs on a pull
# request only, so on this push it is skipped and reads nothing.
pull-requests: read
# CI's test jobs ask for it, to read the tests set aside (open flaky-test issues,
# CI's `changes` asks for it, to read the tests set aside (open flaky-test issues,
# scripts/flaky-tests.ts).
issues: read

Expand Down
6 changes: 5 additions & 1 deletion .github/zizmor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ rules:
# nothing from the run, and leaves runs from forks alone (scripts/ci-watch.ts). Contributor CI
# needs it to look as soon as a run of CI or Desktop starts or finishes, rather than polling on a
# timer. It checks out only scripts/contributor-ci.ts from the default branch, never the run's
# code, downloads no artifact, and acts on runs through the API alone.
# code, downloads no artifact, and acts on runs through the API alone. Flaky tests needs it to read
# the notes one finished run of the merge queue or main left. It checks out only two scripts from
# the default branch, never the run's code, downloads no artifact, runs nothing from the run, and
# leaves runs from forks and pull requests alone (scripts/flaky-tests-watch.ts).
dangerous-triggers:
ignore:
- ci-watch.yml
- contributor-ci.yml
- flaky-tests.yml
Loading
Loading