Skip to content

Commit

Permalink
Handle new job status, Add retry for api requests (#98)
Browse files Browse the repository at this point in the history
New job status in GitHub Actions API are now handled by the action

@Octokit/plugin-retry is added to retry the API requests in case of failure

Closes #93
Closes #94
  • Loading branch information
yogeshlonkar authored May 1, 2024
1 parent 524f20f commit 7635a6a
Show file tree
Hide file tree
Showing 12 changed files with 989 additions and 610 deletions.
1,298 changes: 761 additions & 537 deletions dist/index.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions lib/github/jobs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import { getCurrentJobs } from "./jobs";
const listJobsForWorkflowRunAttempt = jest.fn();

jest.mock("@octokit/rest", () => ({
Octokit: jest.fn().mockImplementation(() => ({
actions: {
listJobsForWorkflowRunAttempt
}
}))
Octokit: {
plugin: () =>
jest.fn().mockImplementation(() => ({
actions: {
listJobsForWorkflowRunAttempt
}
}))
}
}));

beforeEach(() => {
Expand Down
5 changes: 4 additions & 1 deletion lib/github/jobs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { debug } from "@actions/core";
import { components } from "@octokit/openapi-types/types.d";
import { Octokit } from "@octokit/rest";
import { retry } from "@octokit/plugin-retry";

import { Context } from "./context";

const MyOctokit = Octokit.plugin(retry);

/**
* Jobs of perceptual run
*/
Expand All @@ -30,7 +33,7 @@ export async function getCurrentJobs(token: string): Promise<Jobs> {
// prettier-ignore
const { runId: run_id, runAttempt: attempt_number, repo: { owner, repo } } = new Context();
// prettier-ignore
const { actions: { listJobsForWorkflowRunAttempt } } = new Octokit({ auth: token });
const { actions: { listJobsForWorkflowRunAttempt } } = new MyOctokit({ auth: token });
debug(`fetching jobs for /repos/${owner}/${repo}/actions/runs/${run_id}/attempts/${attempt_number}/jobs`);
const { status, data } = await listJobsForWorkflowRunAttempt({
attempt_number,
Expand Down
204 changes: 150 additions & 54 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
"@actions/artifact": "^2.1.7",
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"@octokit/rest": "^20.0.2"
"@octokit/plugin-retry": "^6.0.1",
"@octokit/rest": "^20.1.0",
"@octokit/core": "^5.2.0"
},
"devDependencies": {
"@octokit/openapi-types": "^22.2.0",
Expand Down
5 changes: 5 additions & 0 deletions src/Dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ export class Dependency {
info(`job "${name}" in progress ⌛ current step "${stepName}"`);
return false;
case "queued":
case "requested":
info(`job "${name}" not started yet 👀`);
return false;
case "waiting":
case "pending":
info(`job "${name}" waiting for resources 🤔`);
return false;
default:
// this should never happen
throw new Error(`error: unknown status "${status}" of job "${name}"`);
Expand Down
Loading

0 comments on commit 7635a6a

Please sign in to comment.