From 17663692a5555a9b85fc77d1a37b478239ce3272 Mon Sep 17 00:00:00 2001 From: clearloop Date: Wed, 12 Jun 2024 03:56:57 +0800 Subject: [PATCH] revert(api): revert re-trigger logic (#39) --- dist/index.js | 36 ++++++++++++++++++++++++------------ src/api.ts | 41 ++++++++++++++++++++++++++--------------- 2 files changed, 50 insertions(+), 27 deletions(-) diff --git a/dist/index.js b/dist/index.js index b90b09f..42b381e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -28976,6 +28976,20 @@ class Api { // If the workflow has already been dispatched, create // checks from the exist one. let run = await this.latestRun(workflow_id, head_sha); + if (run) { + // NOTE: + // + // The sorting of workflow runs may have problem, + // revert this logic atm. (issue #40) + // + // if (run.status !== 'completed') { + // core.info(`The check is running in progress: ${run.html_url}`); + // process.exit(0); + // } + // + // // Unset the run if it has got failed. + // if (run.conclusion === 'failure') run = undefined; + } if (!run) run = await this.dispatch(ref, workflow_id, inputs, head_sha); // Create checks from the specifed jobs. @@ -29017,8 +29031,9 @@ class Api { core.info('All jobs completed .'); const failed = _jobs.filter(job => job.conclusion === 'failure'); if (failed.length > 0) { - core.error(`Job ${failed[0].name} Failed`); - process.exit(1); + core.warning(`Job ${failed[0].name} Failed`); + // TODO: exit with errors (issue #40) + process.exit(0); } return; } @@ -29043,12 +29058,15 @@ class Api { status: 'in_progress', output: { title: name, - summary: `Forked from ${run.html_url}\nRe-run the \`${github.context.job}\` job in ${(0, utils_1.sourceHtml)()} to re-trigger this check.` + summary: `Forked from ${run.html_url}` + // TODO: + // + // summary: `Forked from ${run.html_url}\nRe-run the \`${github.context.job}\` job in ${sourceHtml()} to re-trigger this check.` }, head_sha }); core.debug(`Created check ${data}.`); - core.info(`Created check ${data.name} at ${data.html_url}.`); + core.info(`Created check ${data.name} at ${data.html_url}`); return data; } /** @@ -29074,7 +29092,7 @@ class Api { process.exit(1); } core.debug(`Latest run: ${JSON.stringify(run, null, 2)}.`); - core.info(`Dispatched workflow ${run.html_url}.`); + core.info(`Dispatched workflow ${run.html_url} .`); return run; } /** @@ -29142,13 +29160,7 @@ class Api { const runs = workflow_runs.sort((a, b) => { return (new Date(b.created_at).getTime() - new Date(a.created_at).getTime()); }); - const run = runs[0]; - // Here we re-trigger a new workflow if the previous one - // is completed and failure. - if (run.status === 'completed' && run.conclusion === 'failure') { - return undefined; - } - return run; + return runs[0]; } /** * Update a check run from jobs. diff --git a/src/api.ts b/src/api.ts index 9cf5687..36ac22b 100644 --- a/src/api.ts +++ b/src/api.ts @@ -15,7 +15,7 @@ import { WorkflowInputs, WorkflowRun } from '@/types'; -import { wait, sourceHtml } from '@/utils'; +import { wait } from '@/utils'; /** * API wrapper for the fork action and related usages. @@ -62,6 +62,21 @@ export default class Api { // If the workflow has already been dispatched, create // checks from the exist one. let run = await this.latestRun(workflow_id, head_sha); + if (run) { + // NOTE: + // + // The sorting of workflow runs may have problem, + // revert this logic atm. (issue #40) + // + // if (run.status !== 'completed') { + // core.info(`The check is running in progress: ${run.html_url}`); + // process.exit(0); + // } + // + // // Unset the run if it has got failed. + // if (run.conclusion === 'failure') run = undefined; + } + if (!run) run = await this.dispatch(ref, workflow_id, inputs, head_sha); // Create checks from the specifed jobs. @@ -121,8 +136,9 @@ export default class Api { const failed = _jobs.filter(job => job.conclusion === 'failure'); if (failed.length > 0) { - core.error(`Job ${failed[0].name} Failed`); - process.exit(1); + core.warning(`Job ${failed[0].name} Failed`); + // TODO: exit with errors (issue #40) + process.exit(0); } return; @@ -152,13 +168,16 @@ export default class Api { status: 'in_progress', output: { title: name, - summary: `Forked from ${run.html_url}\nRe-run the \`${github.context.job}\` job in ${sourceHtml()} to re-trigger this check.` + summary: `Forked from ${run.html_url}` + // TODO: + // + // summary: `Forked from ${run.html_url}\nRe-run the \`${github.context.job}\` job in ${sourceHtml()} to re-trigger this check.` }, head_sha }); core.debug(`Created check ${data}.`); - core.info(`Created check ${data.name} at ${data.html_url}.`); + core.info(`Created check ${data.name} at ${data.html_url}`); return data; } @@ -192,7 +211,7 @@ export default class Api { } core.debug(`Latest run: ${JSON.stringify(run, null, 2)}.`); - core.info(`Dispatched workflow ${run.html_url}.`); + core.info(`Dispatched workflow ${run.html_url} .`); return run; } @@ -274,15 +293,7 @@ export default class Api { ); }); - const run = runs[0]; - - // Here we re-trigger a new workflow if the previous one - // is completed and failure. - if (run.status === 'completed' && run.conclusion === 'failure') { - return undefined; - } - - return run; + return runs[0]; } /**