Skip to content

Commit

Permalink
feat: add post step when action run was cancelled
Browse files Browse the repository at this point in the history
In post step, we will send cancel request to TF to cancel pending Test run.
  • Loading branch information
jamacku committed Feb 20, 2024
1 parent 12b68ed commit dccd2d6
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 85 deletions.
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,5 @@ outputs:
runs:
using: node20
main: dist/index.js
post-if: cancelled()
post: dist/index.js
193 changes: 118 additions & 75 deletions dist/index.js

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

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

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions dist/main.js

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

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

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

2 changes: 2 additions & 0 deletions dist/post.d.ts

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

16 changes: 16 additions & 0 deletions dist/post.js

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

1 change: 1 addition & 0 deletions dist/post.js.map

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

13 changes: 9 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import { getBooleanInput, getInput, setFailed } from '@actions/core';
import { getBooleanInput, getInput, getState, setFailed } from '@actions/core';
import { context } from '@actions/github';

import '@total-typescript/ts-reset';

import action from './action';
import { TFError } from './error';
import { getOctokit } from './octokit';
import post from './post';
import { PullRequest } from './pull-request';

let pr: PullRequest | undefined = undefined;

// All the code should be inside this try block
try {
const octokit = getOctokit(getInput('github_token', { required: true }));

pr = await PullRequest.initialize(context.issue.number, octokit);

// Call the action function from action.ts
// all the code should be inside this try block
await action(pr);
if (!getState('isPost')) {
// Call the action function from action.ts
await action(pr);
} else {
await post();
}
} catch (error) {
let message: string;

Expand Down
21 changes: 21 additions & 0 deletions src/post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { getInput } from '@actions/core';
import TestingFarmAPI from 'testing-farm';

async function post(): Promise<void> {
const tfInstance = getInput('api_url');
const tfRequestId = process.env['OUTPUT_REQUEST_ID'];

const api = new TestingFarmAPI(tfInstance);

if (!tfRequestId) {
throw new Error('POST: Missing Testing Farm request id');
}

const request = {
api_key: getInput('api_key', { required: true }),
};

await api.cancelRequest(tfRequestId, request, false);
}

export default post;

0 comments on commit dccd2d6

Please sign in to comment.