diff --git a/__tests__/input.test.ts b/__tests__/input.test.ts index 0b6f32d..47cc2ee 100644 --- a/__tests__/input.test.ts +++ b/__tests__/input.test.ts @@ -14,7 +14,7 @@ describe("input", () => { "INPUT_CONTINUE-AFTER-SECONDS": "10", "INPUT_POLL-INTERVAL-SECONDS": "5", "INPUT_SAME-BRANCH-ONLY": "false", - "INPUT_INITIAL-WAIT-SECONDS": "5" + "INPUT_INITIAL-WAIT-SECONDS": "5", }), { githubToken: "s3cr3t", @@ -27,7 +27,7 @@ describe("input", () => { abortAfterSeconds: undefined, pollIntervalSeconds: 5, sameBranchOnly: false, - initialWaitSeconds: 5 + initialWaitSeconds: 5, } ); }); @@ -43,7 +43,7 @@ describe("input", () => { "INPUT_ABORT-AFTER-SECONDS": "10", "INPUT_POLL-INTERVAL-SECONDS": "5", "INPUT_SAME-BRANCH-ONLY": "false", - "INPUT_INITIAL-WAIT-SECONDS": "0" + "INPUT_INITIAL-WAIT-SECONDS": "0", }), { githubToken: "s3cr3t", @@ -56,7 +56,7 @@ describe("input", () => { abortAfterSeconds: 10, pollIntervalSeconds: 5, sameBranchOnly: false, - initialWaitSeconds: 0 + initialWaitSeconds: 0, } ); }); @@ -70,7 +70,7 @@ describe("input", () => { GITHUB_WORKFLOW: "test", GITHUB_RUN_ID: "1", "INPUT_CONTINUE-AFTER-SECONDS": "10", - "INPUT_ABORT-AFTER-SECONDS": "2" + "INPUT_ABORT-AFTER-SECONDS": "2", }) ); }); @@ -86,7 +86,7 @@ describe("input", () => { "INPUT_CONTINUE-AFTER-SECONDS": "", "INPUT_POLL-INTERVAL-SECONDS": "", "INPUT_SAME-BRANCH-ONLY": "", - "INPUT_INITIAL-WAIT-SECONDS": "" + "INPUT_INITIAL-WAIT-SECONDS": "", }), { githubToken: "s3cr3t", @@ -99,7 +99,7 @@ describe("input", () => { abortAfterSeconds: undefined, pollIntervalSeconds: 60, sameBranchOnly: true, - initialWaitSeconds: 0 + initialWaitSeconds: 0, } ); }); @@ -112,7 +112,7 @@ describe("input", () => { GITHUB_REF: "refs/heads/foo", GITHUB_REPOSITORY: "softprops/turnstyle", GITHUB_WORKFLOW: "test", - GITHUB_RUN_ID: "1" + GITHUB_RUN_ID: "1", }), { githubToken: "s3cr3t", @@ -125,7 +125,7 @@ describe("input", () => { abortAfterSeconds: undefined, pollIntervalSeconds: 60, sameBranchOnly: true, - initialWaitSeconds: 0 + initialWaitSeconds: 0, } ); }); diff --git a/__tests__/wait.test.ts b/__tests__/wait.test.ts index 5757a26..e60c062 100644 --- a/__tests__/wait.test.ts +++ b/__tests__/wait.test.ts @@ -10,7 +10,7 @@ describe("wait", () => { let input: Input; const workflow: Workflow = { id: 123124, - name: "Test workflow" + name: "Test workflow", }; beforeEach(() => { @@ -25,7 +25,7 @@ describe("wait", () => { runId: 2, workflowName: workflow.name, sameBranchOnly: true, - initialWaitSeconds: 0 + initialWaitSeconds: 0, }; }); @@ -34,7 +34,7 @@ describe("wait", () => { const inProgressRun = { id: 1, status: "in_progress", - html_url: "" + html_url: "", }; const githubClient = { runs: async ( @@ -44,7 +44,7 @@ describe("wait", () => { workflowId: number ) => Promise.resolve([inProgressRun]), workflows: async (owner: string, repo: string) => - Promise.resolve([workflow]) + Promise.resolve([workflow]), }; const messages: Array = []; @@ -59,7 +59,7 @@ describe("wait", () => { assert.equal(await waiter.wait(), 1); assert.deepEqual(messages, [ "✋Awaiting run ...", - "🤙Exceeded wait seconds. Continuing..." + "🤙Exceeded wait seconds. Continuing...", ]); }); @@ -68,7 +68,7 @@ describe("wait", () => { const inProgressRun = { id: 1, status: "in_progress", - html_url: "" + html_url: "", }; const githubClient = { runs: async ( @@ -78,7 +78,7 @@ describe("wait", () => { workflowId: number ) => Promise.resolve([inProgressRun]), workflows: async (owner: string, repo: string) => - Promise.resolve([workflow]) + Promise.resolve([workflow]), }; const messages: Array = []; @@ -92,11 +92,11 @@ describe("wait", () => { ); await assert.rejects(waiter.wait(), { name: "Error", - message: "Aborted after waiting 1 seconds" + message: "Aborted after waiting 1 seconds", }); assert.deepEqual(messages, [ "✋Awaiting run ...", - "🛑Exceeded wait seconds. Aborting..." + "🛑Exceeded wait seconds. Aborting...", ]); }); @@ -104,7 +104,7 @@ describe("wait", () => { const run: Run = { id: 1, status: "in_progress", - html_url: "1" + html_url: "1", }; const mockedRunsFunc = jest @@ -114,7 +114,7 @@ describe("wait", () => { const githubClient = { runs: mockedRunsFunc, workflows: async (owner: string, repo: string) => - Promise.resolve([workflow]) + Promise.resolve([workflow]), }; const messages: Array = []; @@ -135,18 +135,18 @@ describe("wait", () => { { id: 1, status: "in_progress", - html_url: "1" + html_url: "1", }, { id: 2, status: "in_progress", - html_url: "2" + html_url: "2", }, { id: 3, status: "in_progress", - html_url: "3" - } + html_url: "3", + }, ]; // Give the current run an id that makes it the last in the queue. input.runId = inProgressRuns.length + 1; @@ -155,7 +155,7 @@ describe("wait", () => { inProgressRuns.push({ id: input.runId + 1, status: "in_progress", - html_url: input.runId + 1 + "" + html_url: input.runId + 1 + "", }); const mockedRunsFunc = jest.fn(); @@ -172,7 +172,7 @@ describe("wait", () => { runs: mockedRunsFunc, run: jest.fn(), workflows: async (owner: string, repo: string) => - Promise.resolve([workflow]) + Promise.resolve([workflow]), }; const messages: Array = []; @@ -199,13 +199,13 @@ describe("wait", () => { { id: 1, status: "in_progress", - html_url: "1" + html_url: "1", }, { id: 2, status: "queued", - html_url: "2" - } + html_url: "2", + }, ]; // Give the current run an id that makes it the last in the queue. input.runId = existingRuns.length + 1; @@ -214,7 +214,7 @@ describe("wait", () => { existingRuns.push({ id: input.runId + 1, status: "queued", - html_url: input.runId + 1 + "" + html_url: input.runId + 1 + "", }); const mockedRunsFunc = jest.fn(); @@ -231,7 +231,7 @@ describe("wait", () => { runs: mockedRunsFunc, run: jest.fn(), workflows: async (owner: string, repo: string) => - Promise.resolve([workflow]) + Promise.resolve([workflow]), }; const messages: Array = []; @@ -262,7 +262,7 @@ describe("wait", () => { const run: Run = { id: 1, status: "in_progress", - html_url: "1" + html_url: "1", }; const mockedRunsFunc = jest @@ -277,7 +277,7 @@ describe("wait", () => { const githubClient = { runs: mockedRunsFunc, workflows: async (owner: string, repo: string) => - Promise.resolve([workflow]) + Promise.resolve([workflow]), }; const messages: Array = []; @@ -292,7 +292,7 @@ describe("wait", () => { await waiter.wait(); assert.deepStrictEqual(messages, [ `🔎 Waiting for ${input.initialWaitSeconds} seconds before checking for runs again...`, - "✋Awaiting run 1 ..." + "✋Awaiting run 1 ...", ]); }); }); diff --git a/src/github.ts b/src/github.ts index 14ced26..0a03854 100644 --- a/src/github.ts +++ b/src/github.ts @@ -43,8 +43,8 @@ export class OctokitGitHub implements GitHub { onAbuseLimit: (retryAfter, options) => { // does not retry, only logs a warning debug(`Abuse detected for request ${options.method} ${options.url}`); - } - } + }, + }, }); } @@ -52,7 +52,7 @@ export class OctokitGitHub implements GitHub { this.octokit.paginate( this.octokit.actions.listRepoWorkflows.endpoint.merge({ owner, - repo + repo, }) ); @@ -65,7 +65,7 @@ export class OctokitGitHub implements GitHub { const options: Octokit.EndpointOptions = { owner, repo, - workflow_id + workflow_id, }; if (branch) { @@ -74,11 +74,11 @@ export class OctokitGitHub implements GitHub { const in_progress_options = { ...options, - status: "in_progress" + status: "in_progress", }; const queued_options = { ...options, - status: "queued" + status: "queued", }; const in_progress_runs = this.octokit.paginate( @@ -88,7 +88,7 @@ export class OctokitGitHub implements GitHub { this.octokit.actions.listWorkflowRuns.endpoint.merge(queued_options) ); - return Promise.all([in_progress_runs, queued_runs]).then(runs => + return Promise.all([in_progress_runs, queued_runs]).then((runs) => [].concat.apply>([], runs) ); }; diff --git a/src/input.ts b/src/input.ts index 331a701..bf55d29 100644 --- a/src/input.ts +++ b/src/input.ts @@ -50,6 +50,6 @@ export const parseInput = (env: Record): Input => { continueAfterSeconds, abortAfterSeconds, sameBranchOnly, - initialWaitSeconds + initialWaitSeconds, }; }; diff --git a/src/main.ts b/src/main.ts index e578891..d4ccc4f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,7 +10,7 @@ async function run() { const github = new OctokitGitHub(input.githubToken); const workflows = await github.workflows(input.owner, input.repo); const workflow_id = workflows.find( - workflow => workflow.name == input.workflowName + (workflow) => workflow.name == input.workflowName )?.id; if (workflow_id) { await new Waiter(workflow_id, github, input, info).wait(); diff --git a/src/wait.ts b/src/wait.ts index 86da802..5cde2ba 100644 --- a/src/wait.ts +++ b/src/wait.ts @@ -50,7 +50,7 @@ export class Waiter implements Wait { this.workflowId ); const previousRuns = runs - .filter(run => run.id < this.input.runId) + .filter((run) => run.id < this.input.runId) .sort((a, b) => b.id - a.id); if (!previousRuns || !previousRuns.length) { setOutput("force_continued", ""); @@ -61,7 +61,7 @@ export class Waiter implements Wait { this.info( `🔎 Waiting for ${this.input.initialWaitSeconds} seconds before checking for runs again...` ); - await new Promise(resolve => + await new Promise((resolve) => setTimeout(resolve, this.input.initialWaitSeconds * 1000) ); return this.wait((secondsSoFar || 0) + this.input.initialWaitSeconds); @@ -71,7 +71,7 @@ export class Waiter implements Wait { const previousRun = previousRuns[0]; this.info(`✋Awaiting run ${previousRun.html_url} ...`); - await new Promise(resolve => + await new Promise((resolve) => setTimeout(resolve, this.input.pollIntervalSeconds * 1000) ); return this.wait((secondsSoFar || 0) + this.input.pollIntervalSeconds);