|
| 1 | +# Regenerate scripts/test-shard-timings.json from main's full-battery runs, |
| 2 | +# weekly, and open the pull request (objectui#12208, ruling 6121816480, letter |
| 3 | +# B: "the timing file refreshed from `main`'s full-suite runs on a schedule"). |
| 4 | +# |
| 5 | +# ## What the file is, and why it has a clock |
| 6 | +# |
| 7 | +# `scripts/test-shard-timings.json` is the per-file duration dataset both |
| 8 | +# `ci.yml` test matrices are split by (`scripts/test-shard-sequencer.mjs`, |
| 9 | +# wired as the root vitest config's `sequence.sequencer`). It goes stale in one |
| 10 | +# direction only: files are added and suites get slower while the committed |
| 11 | +# numbers stay put. A new file is weighed at the dataset's median, so a stale |
| 12 | +# dataset degrades to spreading files by count -- the old hash split's shape, |
| 13 | +# and visible in the aggregators' headroom readings -- but the drift is silent |
| 14 | +# unless something refreshes it. A timer is what refreshes it. |
| 15 | +# |
| 16 | +# ## Why a committed file and a pull request, not an artifact the shards fetch |
| 17 | +# |
| 18 | +# Every leg of a matrix computes the whole partition on its own and keeps its |
| 19 | +# bin, so every leg of one run must read the SAME weights. A committed file |
| 20 | +# guarantees that by construction: the legs share a checkout. Legs that each |
| 21 | +# fetched "the newest timings artifact" at their own start could straddle a |
| 22 | +# refresh, and two legs on different weights run some files twice and others |
| 23 | +# never, with every leg green. The committed file also makes a partition move a |
| 24 | +# reviewed, reproducible event -- `pnpm test --shard=3/12` on a laptop runs the |
| 25 | +# same files CI's leg 3 ran -- and the dataset is in the root config's import |
| 26 | +# closure, so the pull request that moves it runs the full suite on the new |
| 27 | +# split before it lands (`scripts/select-affected-tests.mjs`). |
| 28 | +# |
| 29 | +# ## What this workflow is not allowed to do |
| 30 | +# |
| 31 | +# ⛔ It never hand-edits a timing: every byte it commits came out of |
| 32 | +# `scripts/test-file-timings.mjs merge`. |
| 33 | +# ⛔ It never touches `ci.yml`: not the matrix widths, not a `timeout-minutes`. |
| 34 | +# The width a run's measured total implies is printed by the `Test` and |
| 35 | +# `Test (coverage)` aggregators on every run; moving a width is a reviewed |
| 36 | +# edit, not this workflow's. |
| 37 | +# ⛔ It never opens a pull request for a byte-identical file. |
| 38 | +# |
| 39 | +# ## The cost it carries, stated |
| 40 | +# |
| 41 | +# The pull request is opened with this run's `GITHUB_TOKEN`, and GitHub starts |
| 42 | +# no workflow run for an event that token raised -- the release pull request's |
| 43 | +# limitation, which objectui#5397's ruling chose to keep rather than add a |
| 44 | +# personal access token. So the refresh pull request arrives with no CI; the |
| 45 | +# seat or person who lands it pushes to its branch once (a merge of `main` is |
| 46 | +# enough), and that push runs the full suite on the new split. The branch is |
| 47 | +# this workflow's own and is overwritten by each refresh, the same posture |
| 48 | +# `changeset-release.yml` takes with its version branch. |
| 49 | +# |
| 50 | +# ## Which runs it reads |
| 51 | +# |
| 52 | +# `scripts/test-file-timings.mjs select`: the newest completed `CI` runs on |
| 53 | +# `main` from the full battery's events (`push` and the hourly `schedule`, |
| 54 | +# objectui#12214) whose twelve `Test (shard N/12)` legs all reported success |
| 55 | +# and whose twelve `test-file-timings-N` artifacts are all present; at most |
| 56 | +# six, and a file keeps the median of the runs that ran it. When no run |
| 57 | +# qualifies -- before the first full battery has uploaded, or after a week of |
| 58 | +# red -- it prints NOT MEASURED, writes nothing and exits green, because |
| 59 | +# nothing failed; a NOT MEASURED that persists is the finding. |
| 60 | +# |
| 61 | +# ## The pull-request leg |
| 62 | +# |
| 63 | +# A pull request that edits this workflow or the scripts it runs executes it |
| 64 | +# all -- the selection, the downloads, the regeneration -- and stops before |
| 65 | +# the two acts that leave the runner: the push and the pull request. |
| 66 | + |
| 67 | +name: Test Shard Timings Refresh |
| 68 | + |
| 69 | +on: |
| 70 | + schedule: |
| 71 | + # Monday 06:47 UTC: after a weekend of hourly full-battery runs, and on a |
| 72 | + # minute no other workflow here is scheduled on. |
| 73 | + - cron: '47 6 * * 1' |
| 74 | + workflow_dispatch: |
| 75 | + pull_request: |
| 76 | + paths: |
| 77 | + - '.github/workflows/test-shard-timings-refresh.yml' |
| 78 | + - 'scripts/test-file-timings.mjs' |
| 79 | + - 'scripts/test-shard-partition.mjs' |
| 80 | + |
| 81 | +# Read-only at the top level; the one job widens to exactly what it writes. |
| 82 | +permissions: |
| 83 | + contents: read |
| 84 | + |
| 85 | +# One refresh per ref at a time: the newer inputs are the better ones, so an |
| 86 | +# in-flight run yields. Scoped by ref so two pull requests' dry runs do not |
| 87 | +# cancel each other. |
| 88 | +concurrency: |
| 89 | + group: test-shard-timings-refresh-${{ github.ref }} |
| 90 | + cancel-in-progress: true |
| 91 | + |
| 92 | +jobs: |
| 93 | + refresh: |
| 94 | + name: Regenerate the per-file test timings |
| 95 | + runs-on: ubuntu-latest |
| 96 | + timeout-minutes: 15 |
| 97 | + permissions: |
| 98 | + contents: write # push this workflow's own branch |
| 99 | + pull-requests: write # open the refresh pull request |
| 100 | + actions: read # list runs, read their jobs, download their timing artifacts |
| 101 | + |
| 102 | + steps: |
| 103 | + - name: Checkout code |
| 104 | + uses: actions/checkout@v7 |
| 105 | + |
| 106 | + # The selector and the generator are node builtins only: no pnpm, no |
| 107 | + # install. |
| 108 | + - name: Setup Node.js |
| 109 | + uses: actions/setup-node@v7 |
| 110 | + with: |
| 111 | + node-version: '22.x' |
| 112 | + |
| 113 | + # Exit 3 is NOT MEASURED, not a failure: nothing was eligible, nothing is |
| 114 | + # written, and the job says so and stays green. Any other non-zero exit |
| 115 | + # is red. `|| status=$?` because this step runs under `bash -e`. |
| 116 | + - name: Choose the runs to measure from |
| 117 | + id: select |
| 118 | + env: |
| 119 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 120 | + run: | |
| 121 | + status=0 |
| 122 | + node scripts/test-file-timings.mjs select --shards 12 --limit 6 > "$RUNNER_TEMP/runs.json" || status=$? |
| 123 | + echo "status=$status" >> "$GITHUB_OUTPUT" |
| 124 | + if [ "$status" -eq 3 ]; then |
| 125 | + echo "::warning title=Test shard timings::NOT MEASURED: no completed full-battery run on main has all twelve test shards green and all twelve timing artifacts. scripts/test-shard-timings.json is untouched." |
| 126 | + exit 0 |
| 127 | + fi |
| 128 | + if [ "$status" -ne 0 ]; then |
| 129 | + exit "$status" |
| 130 | + fi |
| 131 | + cat "$RUNNER_TEMP/runs.json" |
| 132 | +
|
| 133 | + - name: Download each run's per-file timings |
| 134 | + if: steps.select.outputs.status == '0' |
| 135 | + env: |
| 136 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 137 | + run: | |
| 138 | + mkdir -p "$RUNNER_TEMP/timings" |
| 139 | + node -e 'for (const r of JSON.parse(require("fs").readFileSync(process.argv[1], "utf8"))) console.log(r.id)' "$RUNNER_TEMP/runs.json" > "$RUNNER_TEMP/run-ids.txt" |
| 140 | + while read -r id; do |
| 141 | + gh run download "$id" --repo "$GITHUB_REPOSITORY" --pattern 'test-file-timings-*' --dir "$RUNNER_TEMP/timings/$id" |
| 142 | + done < "$RUNNER_TEMP/run-ids.txt" |
| 143 | +
|
| 144 | + - name: Regenerate the dataset |
| 145 | + if: steps.select.outputs.status == '0' |
| 146 | + run: | |
| 147 | + node scripts/test-file-timings.mjs merge --runs-file "$RUNNER_TEMP/runs.json" \ |
| 148 | + --out scripts/test-shard-timings.json --summary "$RUNNER_TEMP/summary.md" "$RUNNER_TEMP"/timings/* |
| 149 | + git diff --stat -- scripts/test-shard-timings.json |
| 150 | + cat "$RUNNER_TEMP/summary.md" >> "$GITHUB_STEP_SUMMARY" |
| 151 | +
|
| 152 | + - name: Open or update the refresh pull request |
| 153 | + if: steps.select.outputs.status == '0' && github.event_name != 'pull_request' |
| 154 | + env: |
| 155 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 156 | + BRANCH: ci/test-shard-timings-refresh |
| 157 | + run: | |
| 158 | + if git diff --quiet -- scripts/test-shard-timings.json; then |
| 159 | + echo "The regenerated dataset is byte-identical to the committed one: no pull request." |
| 160 | + exit 0 |
| 161 | + fi |
| 162 | + git config user.name 'github-actions[bot]' |
| 163 | + git config user.email '41898282+github-actions[bot]@users.noreply.github.com' |
| 164 | + git switch -c "$BRANCH" |
| 165 | + git add scripts/test-shard-timings.json |
| 166 | + git commit -m 'chore(test): refresh the per-file test timings (objectui#12208)' |
| 167 | + git push --force origin "$BRANCH" |
| 168 | + { |
| 169 | + echo 'The weekly refresh of `scripts/test-shard-timings.json`, the per-file durations both `ci.yml` test matrices are split by (objectui#12208). Generated by `scripts/test-file-timings.mjs merge` from the runs below; never hand-edited.' |
| 170 | + echo |
| 171 | + cat "$RUNNER_TEMP/summary.md" |
| 172 | + echo |
| 173 | + echo '**This pull request has no CI of its own yet.** It was opened with the Actions token, and GitHub starts no workflow for an event that token raised. Push to its branch once (a merge of `main` is enough): the dataset is in the root vitest config import closure, so that push runs the full suite on the new split.' |
| 174 | + } > "$RUNNER_TEMP/body.md" |
| 175 | + open=$(gh pr list --repo "$GITHUB_REPOSITORY" --head "$BRANCH" --state open --json number --jq '.[0].number // empty') |
| 176 | + if [ -n "$open" ]; then |
| 177 | + gh pr edit "$open" --repo "$GITHUB_REPOSITORY" --body-file "$RUNNER_TEMP/body.md" |
| 178 | + echo "Updated the open refresh pull request #$open." |
| 179 | + else |
| 180 | + gh pr create --repo "$GITHUB_REPOSITORY" --base main --head "$BRANCH" \ |
| 181 | + --title 'chore(test): refresh the per-file test timings (objectui#12208)' --body-file "$RUNNER_TEMP/body.md" |
| 182 | + fi |
0 commit comments