Skip to content

Commit

Permalink
feat(api): support re-running checks (#35)
Browse files Browse the repository at this point in the history
* feat(api): support re-running checks

* feat(utils): returns url with job id

* feat(api): append the source job name in summary

* ci(linter): remove super linter

* feat(api): fail dispatch job on failure

* chore(api): rename workflow to run

* chore(api): update docs
  • Loading branch information
clearloop authored May 31, 2024
1 parent b3b3512 commit ab9d925
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 58 deletions.
42 changes: 0 additions & 42 deletions .github/workflows/linter.yml

This file was deleted.

28 changes: 20 additions & 8 deletions dist/index.js

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

27 changes: 19 additions & 8 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 } from '@/utils';
import { wait, sourceHtml } from '@/utils';

/**
* API wrapper for the fork action and related usages.
Expand Down Expand Up @@ -118,6 +118,13 @@ export default class Api {
_jobs.filter(job => job?.status === 'completed').length === jobs.length
) {
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);
}

return;
} else {
await wait(10000);
Expand Down Expand Up @@ -145,7 +152,7 @@ export default class Api {
status: 'in_progress',
output: {
title: name,
summary: `Forked from ${run.html_url}`
summary: `Forked from ${run.html_url}\nRe-run the \`${github.context.job}\` job in ${sourceHtml()} to re-trigger this check.`
},
head_sha
});
Expand Down Expand Up @@ -267,7 +274,15 @@ export default class Api {
);
});

return runs[0];
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;
}

/**
Expand Down Expand Up @@ -299,11 +314,7 @@ export default class Api {
repo: this.repo,
check_run_id,
status,
conclusion,
output: {
title: job.name,
summary: `Forked from ${job.html_url}`
}
conclusion
});

return data;
Expand Down
5 changes: 5 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,8 @@ function deriveInputs(): IInputsAndJobs {
jobs
};
}

export function sourceHtml(): string {
const context = github.context;
return `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
}

0 comments on commit ab9d925

Please sign in to comment.