Repository navigation
ci(review): switch online hk1 and hk2 runners between review and CI twice daily #11855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8d134b6
ci(review): size the review runner pool by time of day and skip uncha…
2b9d053
ci(review): cut the runner schedule to three variables and split out …
a657ddb
ci(review): no deployment record per schedule tick; fix the fallback …
a139230
ci(review): default the review pool to 17:00-05:00 and none by day
99a7b4b
ci(review): read the schedule only from repository variables
25abcc9
ci(review): default the schedule to 17:00-05:00 in the workflow
52e6ad4
fix(ci): fix review schedule lint and clarify equal-hour behavior
yiliang114 f4f8c1d
ci(review): switch the entire runner pool twice daily
yiliang114 7885757
fix(ci): skip offline runners during pool switches
yiliang114 61bc697
fix(ci): quote runner schedule input values
yiliang114 d102332
fix(ci): include hk1 in scheduled runner switches
yiliang114 45f8b30
fix(ci): add the pool label before removing the others
yiliang114 e282a89
fix(ci): preserve autofix capacity during review pool switches
yiliang114 e53c97a
fix(ci): correct the pool-switch comment and pin the never-started guard
yiliang114 27fa25c
test(ci): verify runner label switch failure ordering
yiliang114 702a9b4
fix(ci): post an accurate body when review-pr never got a runner
yiliang114 3a8a8a6
fix(ci): drop the af-099 design record its code deletion orphaned
yiliang114 9a58f67
fix(ci): fence the schedule job to main and pin the guards it relies on
yiliang114 d45b5d9
refactor(ci): round-2 review follow-ups
yiliang114 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| // Switch all online hk1/hk2 runners between review and CI, twice a day. | ||
| // Offline runners are skipped; their labels stay unchanged. | ||
| // Running jobs finish normally; labels only control which job starts next. | ||
|
|
||
| import { execFile as execFileCallback } from 'node:child_process'; | ||
| import { appendFileSync } from 'node:fs'; | ||
| import { promisify } from 'node:util'; | ||
|
|
||
| const execFile = promisify(execFileCallback); | ||
| const MANAGED_LABELS = ['ecs-review', 'ecs-qwen', 'ecs-agent']; | ||
|
yiliang114 marked this conversation as resolved.
Resolved
|
||
|
|
||
| export function planLabels(runners, mode) { | ||
| if (!['review', 'ci'].includes(mode)) { | ||
| throw new Error('mode must be review or ci'); | ||
| } | ||
| const target = mode === 'review' ? 'ecs-review' : 'ecs-qwen'; | ||
|
yiliang114 marked this conversation as resolved.
Resolved
|
||
| return runners | ||
| .filter( | ||
| (r) => r.status === 'online' && /^ecs-qwen-hk[12]-\d+$/.test(r.name), | ||
| ) | ||
| .flatMap((r) => { | ||
| const labels = r.labels.map((l) => l.name); | ||
| const remove = labels.filter( | ||
| (l) => MANAGED_LABELS.includes(l) && l !== target, | ||
| ); | ||
| const add = labels.includes(target) ? [] : [target]; | ||
| return add.length || remove.length | ||
| ? [{ id: r.id, name: r.name, add, remove }] | ||
| : []; | ||
| }); | ||
| } | ||
|
|
||
| async function gh(args) { | ||
| const { stdout } = await execFile('gh', args, { | ||
| env: { ...process.env, GH_TOKEN: process.env.RUNNER_ADMIN_TOKEN }, | ||
| maxBuffer: 16 * 1024 * 1024, | ||
| }); | ||
| return stdout; | ||
| } | ||
|
|
||
| async function main() { | ||
| const [repo, mode] = process.argv.slice(2); | ||
| if (!/^[\w.-]+\/[\w.-]+$/.test(repo ?? '')) { | ||
| throw new Error( | ||
| 'usage: review-runner-schedule.mjs <owner/repo> <review|ci>', | ||
| ); | ||
| } | ||
| planLabels([], mode); | ||
| if (!process.env.RUNNER_ADMIN_TOKEN) { | ||
| throw new Error( | ||
| 'RUNNER_ADMIN_TOKEN is empty (needs Administration: write)', | ||
| ); | ||
| } | ||
| const pages = JSON.parse( | ||
| await gh([ | ||
| 'api', | ||
| '--paginate', | ||
| '--slurp', | ||
| `repos/${repo}/actions/runners?per_page=100`, | ||
| ]), | ||
| ); | ||
| const runners = pages.flatMap((page) => page.runners); | ||
| if (!runners.some((r) => /^ecs-qwen-hk[12]-\d+$/.test(r.name))) { | ||
| throw new Error('no ecs-qwen-hk1-<n> or ecs-qwen-hk2-<n> runner found'); | ||
|
yiliang114 marked this conversation as resolved.
Resolved
|
||
| } | ||
| const actions = planLabels(runners, mode); | ||
| const results = await Promise.all( | ||
| actions.map(async ({ id, name, add, remove }) => { | ||
| try { | ||
| // Add before removing, so a failure can only leave the host in both | ||
| // pools. The reverse order lets a failed POST strand the host with | ||
|
yiliang114 marked this conversation as resolved.
Resolved
|
||
| // no pool label at all — no job in either pool can match it until | ||
| // the next successful switch, which can be 12 hours away. | ||
| if (add.length) { | ||
| await gh([ | ||
| 'api', | ||
| '--method', | ||
| 'POST', | ||
|
yiliang114 marked this conversation as resolved.
Resolved
|
||
| `repos/${repo}/actions/runners/${id}/labels`, | ||
| ...add.flatMap((l) => ['-f', `labels[]=${l}`]), | ||
| ]); | ||
| } | ||
| for (const label of remove) { | ||
| await gh([ | ||
| 'api', | ||
| '--method', | ||
| 'DELETE', | ||
| `repos/${repo}/actions/runners/${id}/labels/${label}`, | ||
| ]); | ||
| } | ||
| return { | ||
| message: `- ${name}: ${[...remove.map((l) => `−${l}`), ...add.map((l) => `+${l}`)].join(' ')}`, | ||
| }; | ||
| } catch (error) { | ||
| return { | ||
| failed: true, | ||
| message: `- ${name}: failed — ${error.message}`, | ||
| }; | ||
| } | ||
| }), | ||
| ); | ||
| const summary = [ | ||
| `### hk1/hk2 runner pool: ${mode}`, | ||
| `- ${actions.length} runners to switch`, | ||
| ...results.map((r) => r.message), | ||
| ].join('\n'); | ||
| console.log(summary); | ||
| if (process.env.GITHUB_STEP_SUMMARY) { | ||
| appendFileSync(process.env.GITHUB_STEP_SUMMARY, `${summary}\n`); | ||
| } | ||
| const failures = results.filter((r) => r.failed).length; | ||
| if (failures) throw new Error(`${failures} runner label change(s) failed`); | ||
| } | ||
|
|
||
| if (process.argv[1]?.endsWith('review-runner-schedule.mjs')) { | ||
|
yiliang114 marked this conversation as resolved.
Resolved
|
||
| main().catch((error) => { | ||
| console.error(`::error::${error.message}`); | ||
| process.exitCode = 1; | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import assert from 'node:assert/strict'; | ||
| import { readFileSync } from 'node:fs'; | ||
| import { describe, it } from 'node:test'; | ||
| import { planLabels } from './review-runner-schedule.mjs'; | ||
|
|
||
| const runner = (id, labels, extra = {}) => ({ | ||
| id, | ||
| name: `ecs-qwen-hk2-${id}`, | ||
| labels: labels.map((name) => ({ name })), | ||
| status: 'online', | ||
| ...extra, | ||
| }); | ||
|
|
||
| describe('review runner schedule', () => { | ||
| it('switches online hk1 and hk2 runners, including busy runners', () => { | ||
| const runners = Array.from({ length: 32 }, (_, i) => | ||
| runner(i + 1, ['ecs-qwen', 'ecs-agent', 'diagnostic'], { | ||
| name: `ecs-qwen-hk${(i % 2) + 1}-${i + 1}`, | ||
| busy: i % 2 === 0, | ||
| status: i < 2 ? 'offline' : 'online', | ||
| }), | ||
| ); | ||
| const actions = planLabels(runners, 'review'); | ||
| const onlineRunners = runners.filter(({ status }) => status === 'online'); | ||
| assert.equal(actions.length, 30); | ||
| for (const [i, action] of actions.entries()) { | ||
| assert.deepEqual(action, { | ||
| id: onlineRunners[i].id, | ||
| name: onlineRunners[i].name, | ||
| add: ['ecs-review'], | ||
| remove: ['ecs-qwen', 'ecs-agent'], | ||
| }); | ||
| } | ||
| assert.deepEqual( | ||
| actions.map(({ id }) => id), | ||
| onlineRunners.map(({ id }) => id), | ||
| ); | ||
| }); | ||
|
|
||
| it('returns every online review runner to CI and leaves unrelated runners alone', () => { | ||
| assert.deepEqual( | ||
| planLabels( | ||
| [ | ||
| runner(1, ['ecs-review', 'diagnostic']), | ||
| runner(2, ['ecs-agent'], { name: 'ecs-qwen-hk1-2' }), | ||
| runner(3, ['ecs-review'], { name: 'ecs-qwen-hk2-3-extra' }), | ||
| runner(4, ['ecs-review'], { status: 'offline' }), | ||
| runner(5, ['ecs-review'], { name: 'ecs-qwen-hk3-5' }), | ||
| ], | ||
| 'ci', | ||
| ), | ||
| [ | ||
| { | ||
| id: 1, | ||
| name: 'ecs-qwen-hk2-1', | ||
| add: ['ecs-qwen'], | ||
| remove: ['ecs-review'], | ||
| }, | ||
| { | ||
| id: 2, | ||
| name: 'ecs-qwen-hk1-2', | ||
| add: ['ecs-qwen'], | ||
| remove: ['ecs-agent'], | ||
| }, | ||
| ], | ||
| ); | ||
| }); | ||
|
|
||
| it('is idempotent and rejects invalid modes', () => { | ||
| assert.deepEqual( | ||
| planLabels([runner(1, ['ecs-review', 'diagnostic'])], 'review'), | ||
| [], | ||
| ); | ||
| assert.deepEqual(planLabels([runner(1, ['ecs-qwen'])], 'ci'), []); | ||
| assert.throws(() => planLabels([], 'invalid'), /mode must be review or ci/); | ||
| }); | ||
|
|
||
| it('wires two daily UTC switches and manual pool selection', () => { | ||
| const schedule = readFileSync( | ||
| new URL('../workflows/qwen-review-runner-schedule.yml', import.meta.url), | ||
| 'utf8', | ||
| ); | ||
| assert.deepEqual( | ||
| [...schedule.matchAll(/cron: '([^']+)'/g)].map((m) => m[1]), | ||
| ['0 9 * * *', '0 21 * * *'], | ||
| ); | ||
| assert.ok( | ||
| schedule.includes( | ||
| "github.event_name == 'workflow_dispatch' && inputs.pool", | ||
| ), | ||
| ); | ||
| assert.ok( | ||
| schedule.includes( | ||
| "github.event.schedule == '0 9 * * *' && 'review' || 'ci'", | ||
| ), | ||
| ); | ||
| assert.ok(schedule.includes('"$GITHUB_REPOSITORY" "$POOL"')); | ||
| assert.ok(schedule.includes('secrets.RUNNER_ADMIN_PAT')); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| name: 'Qwen Review Runner Schedule' | ||
|
|
||
| # Switch every online hk1/hk2 runner at 17:00 / 05:00 Asia/Shanghai. | ||
| # GitHub cron uses UTC. Manual runs can select either pool explicitly. | ||
| # Running jobs finish; only the labels for the next job change. | ||
| # | ||
| # RUNNER_ADMIN_PAT needs runner-label write access: repo scope for a | ||
| # classic PAT, or repository Administration: write for a fine-grained PAT. | ||
| # Store it in the environment below, restricted to `main`. | ||
| # To pause the schedule, disable this workflow. | ||
|
yiliang114 marked this conversation as resolved.
Resolved
|
||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 9 * * *' # 17:00 Asia/Shanghai: enable reviews | ||
| - cron: '0 21 * * *' # 05:00 Asia/Shanghai: return to CI | ||
| workflow_dispatch: | ||
| inputs: | ||
| pool: | ||
| description: 'Pool for all online hk1/hk2 runners' | ||
| type: 'choice' | ||
| required: true | ||
| default: 'ci' | ||
| options: | ||
| - 'review' | ||
| - 'ci' | ||
|
|
||
| permissions: | ||
| contents: 'read' | ||
|
|
||
| concurrency: | ||
| group: 'qwen-review-runner-schedule' | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| converge: | ||
| if: "${{ github.repository == 'QwenLM/qwen-code' }}" | ||
| runs-on: 'ubuntu-latest' | ||
| timeout-minutes: 10 | ||
| # deployment: false — the job needs the environment's secret, not a | ||
| # deployment record for a label switch. | ||
| environment: | ||
| name: 'qwen-review-runner-schedule' | ||
| deployment: false | ||
|
yiliang114 marked this conversation as resolved.
Resolved
|
||
| steps: | ||
| - name: 'Checkout the schedule script' | ||
| uses: 'actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10' # v6.0.3 | ||
| with: | ||
| persist-credentials: false | ||
| sparse-checkout: '.github/scripts/review-runner-schedule.mjs' | ||
| sparse-checkout-cone-mode: false | ||
|
|
||
| - name: 'Switch runner pool' | ||
| env: | ||
| RUNNER_ADMIN_TOKEN: '${{ secrets.RUNNER_ADMIN_PAT }}' | ||
| POOL: "${{ github.event_name == 'workflow_dispatch' && inputs.pool || (github.event.schedule == '0 9 * * *' && 'review' || 'ci') }}" | ||
|
yiliang114 marked this conversation as resolved.
Resolved
|
||
| run: 'node .github/scripts/review-runner-schedule.mjs "$GITHUB_REPOSITORY" "$POOL"' | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.