Skip to content

Commit

Permalink
Merge eb1c3c4 into 619d137
Browse files Browse the repository at this point in the history
  • Loading branch information
CatChen authored Aug 28, 2022
2 parents 619d137 + eb1c3c4 commit e0fce3d
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 23 deletions.
31 changes: 31 additions & 0 deletions dist/getWorkflowRunJobs.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 53 additions & 7 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions lib/getWorkflowRunJobs.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions lib/getWorkflowRunJobs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 22 additions & 7 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/getCheckRuns.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Octokit } from "@octokit/core";
import { Api } from "@octokit/plugin-rest-endpoint-methods/dist-types/types";
import { components } from "@octokit/openapi-types/types";
import { context } from "@actions/github";

export async function getCheckRuns(
owner: string,
Expand Down
17 changes: 17 additions & 0 deletions src/getWorkflowRunJobs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Octokit } from "@octokit/core";
import { Api } from "@octokit/plugin-rest-endpoint-methods/dist-types/types";
import { components } from "@octokit/openapi-types/types";
import { context } from "@actions/github";

export async function getWorkflowRunJobs(
owner: string,
repo: string,
octokit: Octokit & Api
) {
const response = await octokit.rest.actions.listJobsForWorkflowRun({
owner,
repo,
run_id: context.runId,
});
return response.data.jobs as components["schemas"]["job"][];
}
34 changes: 26 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getPullRequest } from "./getPullRequest";
import { getPullRequestComments } from "./getPullRequestComments";
import { getPullRequestReviewRequests } from "./getPullRequestReviewRequests";
import { getPullRequestReviews } from "./getPullRequestReviews";
import { getWorkflowRunJobs } from "./getWorkflowRunJobs";
import { getCheckRuns } from "./getCheckRuns";
import { checkIfPullRequestMerged, mergePullRequest } from "./mergePullRequest";
import { sleep } from "./sleep";
Expand All @@ -27,9 +28,6 @@ const FORMATTER = new Intl.NumberFormat(LOCALE, {
});

async function run(): Promise<void> {
info(`Current Workflow: ${context.workflow}`);
info(`Current job: ${context.job}`);

const octokit = getOctokit();
const owner = context.repo.owner;
const repo = context.repo.repo;
Expand Down Expand Up @@ -163,9 +161,19 @@ async function run(): Promise<void> {
return;
}

const jobs = await getWorkflowRunJobs(owner, repo, octokit);
info(`Jobs: ${jobs.length}`);
for (const job of jobs) {
info(` Job id: ${job.id} (${job.html_url})`);
info(` Job name: ${job.name}`);
info(` Job run id/attempt: ${job.run_id}-${job.run_attempt}\n`);
}
const jobIds = jobs.map((job) => job.id);

const timeout = parseInt(getInput("timeout"), 10);
const interval = parseInt(getInput("checks-watch-interval"), 10);
let checksCompleted = false;
let externalId: string | undefined | null = undefined;
while (!checksCompleted) {
const checkRuns = await getCheckRuns(
owner,
Expand All @@ -175,16 +183,26 @@ async function run(): Promise<void> {
);
info(`Checks:`);
for (const checkRun of checkRuns) {
info(` Check id: ${checkRun.id} (${checkRun.html_url})`);
info(` Check name: ${checkRun.name}`);
info(
` ${checkRun.name}: ${
` Check status/conclusion: ${
checkRun.status === COMPLETED ? checkRun.conclusion : checkRun.status
}`
}\n`
);
}
if (externalId === undefined || externalId === null) {
externalId = checkRuns.find((checkRun) =>
jobIds.includes(checkRun.id)
)?.external_id;
}
const incompleteChecks = checkRuns.filter(
(checkRun) => checkRun.status !== COMPLETED
(checkRun) =>
!jobIds.includes(checkRun.id) &&
checkRun.external_id !== externalId &&
checkRun.status !== COMPLETED
);
checksCompleted = incompleteChecks.length <= 1;
checksCompleted = incompleteChecks.length === 0;
if (checksCompleted) {
const failedCheckes = checkRuns.filter(
(checkRun) =>
Expand All @@ -204,7 +222,7 @@ async function run(): Promise<void> {
const executionTime = Math.round(performance.now() / 1000);
if (executionTime <= timeout) {
info(`Execution time: ${FORMATTER.format(executionTime)}`);
info(`Sleeping: ${FORMATTER.format(interval)}`);
info(`Sleeping: ${FORMATTER.format(interval)}\n`);
await sleep(interval * 1000);
} else {
error(`Execution time: ${FORMATTER.format(executionTime)}`);
Expand Down

0 comments on commit e0fce3d

Please sign in to comment.