豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 7f4f1a9

Browse files
committed
test: add a retry for the merge queue
1 parent b2bafcf commit 7f4f1a9

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

.github/workflows/run-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ jobs:
5959

6060
- name: Run tests
6161
shell: bash
62-
run: npm run test:no-build
62+
# Try tests if they fail in the merge queue.
63+
run: npm run test:no-build -- ${{ github.event_name == 'merge_group' && '--retry' || '' }}
6364

6465
# Gating job for branch protection.
6566
test-success:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"docs:generate": "node --experimental-strip-types scripts/generate-docs.ts",
1717
"start": "npm run build && node build/src/index.js",
1818
"start-debug": "DEBUG=mcp:* DEBUG_COLORS=false npm run build && node build/src/index.js",
19-
"test": "npm run build && npm run test:no-build",
19+
"test": "npm run build && node scripts/test.mjs",
2020
"test:no-build": "node scripts/test.mjs",
2121
"test:only": "npm run build && node scripts/test.mjs --test-only",
2222
"test:update-snapshots": "npm run build && node scripts/test.mjs --test-update-snapshots",

scripts/test.mjs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ const flags = args.filter(arg => arg.startsWith('-'));
1717

1818
const files = [];
1919

20+
let shouldRetry = false;
21+
const retryIndex = flags.indexOf('--retry');
22+
if (retryIndex !== -1) {
23+
shouldRetry = true;
24+
flags.splice(retryIndex, 1);
25+
}
26+
2027
if (userArgs.length > 0) {
2128
for (const arg of userArgs) {
2229
// Map .ts files to build/ .js files
@@ -50,10 +57,31 @@ const nodeArgs = [
5057
...files,
5158
];
5259

53-
const child = spawn('node', nodeArgs, {
54-
stdio: 'inherit',
55-
});
60+
async function runTests(attempt) {
61+
if (attempt > 1) {
62+
console.log(`\nRun attempt ${attempt}...\n`);
63+
}
64+
return new Promise(resolve => {
65+
const child = spawn('node', nodeArgs, {
66+
stdio: 'inherit',
67+
});
68+
69+
child.on('close', code => {
70+
resolve(code);
71+
});
72+
});
73+
}
74+
75+
(async () => {
76+
const maxAttempts = shouldRetry ? 3 : 1;
77+
let exitCode = 1;
78+
79+
for (let i = 1; i <= maxAttempts; i++) {
80+
exitCode = await runTests(i);
81+
if (exitCode === 0) {
82+
break;
83+
}
84+
}
5685

57-
child.on('close', code => {
58-
process.exit(code ?? 1);
59-
});
86+
process.exit(exitCode ?? 1);
87+
})();

0 commit comments

Comments
 (0)