这对我有用:
https://api.github.com/repos/ethereum/EIPs/commits/<ref>/statuses 出于某种原因只能看到我的第 3 方 CI 检查的状态。因此,即使其他测试失败,它也只会考虑 CI 测试。
所以我使用这个属性每 30 秒检查一次,如果出现错误则中止;这是代码:
// HACK (alita): check the CI status and only continue if the CI is successful
const checkCIStatus = async () => {
const Github = getOctokit(GITHUB_TOKEN);
const pr = await requirePr()
const status = await Github.repos.getCombinedStatusForRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: pr.head.ref
}).then(res => res.data.state)
console.log(`status is '${status}'...`)
if (status === "failure") {
setFailed("CI checks failed; bot can only merge if CI checks pass")
throw "CI checks failed; bot can only merge if CI checks pass"
}
return status === "success";
}
export const pauseInterval = (checker, next, timeout) => async () => {
const status = await checker();
if (!status) {
setTimeout(pauseInterval(checker, next, timeout), timeout);
} else {
return next()
}
}
// only runs the bot if the CI statuses pass; checks every 30 seconds
export const main = pauseInterval(checkCIStatus, _main, CHECK_STATUS_INTERVAL)
成功的输出
status is 'pending'...
status is 'pending'...
status is 'pending'...
status is 'pending'...
status is 'pending'...
status is 'pending'...
status is 'pending'...
status is 'pending'...
status is 'pending'...
status is 'pending'...
status is 'pending'...
status is 'success'...
<normal action outputs>
检查失败的输出
status is 'pending'...
status is 'pending'...
(node:1603) UnhandledPromiseRejectionWarning: CI checks failed; bot can only merge if CI checks pass
status is 'failure'...
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1603) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1603) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
这显然只有在自定义操作中才真正可行,但您可能可以创建一个简单的操作/js 文件,该文件可以执行相同的行为并在给定操作之前被视为一个操作。如果你有这个,并且在成功或错误时失败/成功,那么你可以有条件地在 Github yaml 脚本中调用你的操作。