Skip to content
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

test #4786

Closed
wants to merge 21 commits into from
60 changes: 40 additions & 20 deletions scripts/get_run_numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,50 @@ export async function script(
workflows = workflows.filter((w): boolean => w.name === "release");
const runNumbers: string[][] = await Promise.all(
workflows.map(async (w): Promise<string[]> => {
const listWorkflowRunsParams: RestEndpointMethodTypes["actions"]["listWorkflowRuns"]["parameters"] =
const listWorkflowRunsBaseParams: RestEndpointMethodTypes["actions"]["listWorkflowRuns"]["parameters"] =
{
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: w.id,
branch: HEAD_REF,
};
console.log("call actions.listWorkflowRuns:");
console.log(listWorkflowRunsParams);
let runs: PaginatingEndpoints["GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}/runs"]["response"]["data"]["workflow_runs"] =
await github.paginate(
github.rest.actions.listWorkflowRuns,
listWorkflowRunsParams,
);
runs = runs.filter(
(r): boolean =>
process.env.RUN_NUMBER === undefined ||
r.run_number < Number(process.env.RUN_NUMBER),
const listWorkflowRunsParamsList: RestEndpointMethodTypes["actions"]["listWorkflowRuns"]["parameters"][] =
[
{
...listWorkflowRunsBaseParams,
branch: HEAD_REF,
},
{
...listWorkflowRunsBaseParams,
event: "merge_group",
status: "completed",
},
];
const runsList = await Promise.all(
listWorkflowRunsParamsList.map(async (listWorkflowRunsParams) => {
console.log("call actions.listWorkflowRuns:");
console.log(listWorkflowRunsParams);
return await github.paginate(
github.rest.actions.listWorkflowRuns,
listWorkflowRunsParams,
);
}),
);
return runs.map((r): string => {
if (r.status !== "completed") {
return running;
}
const runs = runsList
.flat()
.filter(
(r): boolean =>
process.env.RUN_NUMBER === undefined ||
r.run_number < Number(process.env.RUN_NUMBER),
);
return runs
.filter((r) => r.event === "push" || r.status === "completed")
.map((r): string => {
if (r.status !== "completed") {
return running;
}

return `v${r.run_number}`;
});
return `v${r.run_number}`;
});
}),
);
result = runNumbers.flat().filter(Boolean);
Expand All @@ -63,7 +81,9 @@ export async function script(
result.shift();
}

await sleep(result, running, retryCount, i);
if (!(await sleep(result, running, retryCount, i))) {
break;
}
}

if (result.includes(running)) {
Expand Down
5 changes: 3 additions & 2 deletions scripts/sleep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ export async function sleep(
running: string,
retryCount: number,
i: number,
) {
): Promise<boolean> {
if (!result.includes(running) || i === retryCount - 1) {
return;
return false;
}

// 完了していないrunがあった場合はリトライ
Expand All @@ -14,4 +14,5 @@ export async function sleep(
const sleepSeconds = Math.random() * (Math.pow(2, i + 1) * 100);
console.log(`sleep ${sleepSeconds}s`);
await new Promise((resolve) => setTimeout(resolve, sleepSeconds * 1000));
return true;
}
Loading