Skip to content

Commit

Permalink
revert(api): revert re-trigger logic (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
clearloop committed Jun 12, 2024
1 parent 0925fe2 commit 1766369
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 27 deletions.
36 changes: 24 additions & 12 deletions dist/index.js

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

41 changes: 26 additions & 15 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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];
}

/**
Expand Down

0 comments on commit 1766369

Please sign in to comment.