Skip to content
This repository was archived by the owner on May 15, 2021. It is now read-only.

Commit f26bd35

Browse files
Merge pull request #75 from technote-space/release/next-v1.7.3
release: v1.7.4
2 parents 1c92f95 + d7399dc commit f26bd35

File tree

7 files changed

+679
-616
lines changed

7 files changed

+679
-616
lines changed

Diff for: __tests__/process.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ describe('execute', () => {
4242

4343
stdoutCalledWith(mockStdout, [
4444
'> This is not target context.',
45+
'',
4546
'::set-output name=ids::',
4647
]);
4748
});
@@ -99,6 +100,7 @@ describe('execute', () => {
99100
'',
100101
'::group::Cancelling...',
101102
'> total: 0',
103+
'',
102104
'::set-output name=ids::',
103105
'::endgroup::',
104106
]);
@@ -203,6 +205,7 @@ describe('execute', () => {
203205
'cancel: 30433643',
204206
'cancel: 30433644',
205207
'> total: 3',
208+
'',
206209
'::set-output name=ids::30433642,30433643,30433644',
207210
'::endgroup::',
208211
]);
@@ -298,6 +301,7 @@ describe('execute', () => {
298301
'::group::Cancelling...',
299302
'cancel: 30433644',
300303
'> total: 1',
304+
'',
301305
'::set-output name=ids::30433644',
302306
'::endgroup::',
303307
]);
@@ -418,6 +422,7 @@ describe('execute', () => {
418422
'cancel: 30433644',
419423
'cancel: 30433645',
420424
'> total: 4',
425+
'',
421426
'::set-output name=ids::30433642,30433643,30433644,30433645',
422427
'::endgroup::',
423428
]);
@@ -530,6 +535,7 @@ describe('execute', () => {
530535
'cancel: 30433644',
531536
'::error::request to https://api.github.com/repos/hello/world/actions/runs/30433644/cancel failed, reason: Cannot cancel a workflow run that is completed.',
532537
'> total: 3',
538+
'',
533539
'::set-output name=ids::30433642,30433643,30433644',
534540
'::endgroup::',
535541
]);

Diff for: __tests__/utils/misc.test.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/* eslint-disable no-magic-numbers */
2+
import type {components} from '@octokit/openapi-types';
23
import {resolve} from 'path';
34
import {testEnv, generateContext} from '@technote-space/github-action-test-helper';
4-
import {isExcludeContext, isConsiderReRun, getIntervalMs, getTargetRunId, getTargetBranch} from '../../src/utils/misc';
5+
import {isExcludeContext, isNotExcludeRun, isConsiderReRun, getIntervalMs, getTargetRunId, getTargetBranch} from '../../src/utils/misc';
56

7+
type ActionsListWorkflowRunsResponseData = components['schemas']['workflow-run'];
68
const rootDir = resolve(__dirname, '../..');
79

810
describe('isExcludeContext', () => {
@@ -43,6 +45,29 @@ describe('isExcludeContext', () => {
4345
});
4446
});
4547

48+
describe('isNotExcludeRun', () => {
49+
testEnv(rootDir);
50+
51+
it('should return true 1', () => {
52+
process.env.INPUT_EXCLUDE_MERGED = 'false';
53+
expect(isNotExcludeRun({} as ActionsListWorkflowRunsResponseData)).toBe(true);
54+
});
55+
56+
it('should return true 2', () => {
57+
process.env.INPUT_EXCLUDE_MERGED = 'true';
58+
process.env.INPUT_MERGE_MESSAGE_PREFIX = 'test';
59+
expect(isNotExcludeRun({} as ActionsListWorkflowRunsResponseData)).toBe(true);
60+
expect(isNotExcludeRun({'head_commit': {message: ''}} as ActionsListWorkflowRunsResponseData)).toBe(true);
61+
expect(isNotExcludeRun({'head_commit': {message: 'aaa'}} as ActionsListWorkflowRunsResponseData)).toBe(true);
62+
});
63+
64+
it('should return false', () => {
65+
process.env.INPUT_EXCLUDE_MERGED = 'true';
66+
process.env.INPUT_MERGE_MESSAGE_PREFIX = 'test';
67+
expect(isNotExcludeRun({'head_commit': {message: 'test aaa'}} as ActionsListWorkflowRunsResponseData)).toBe(false);
68+
});
69+
});
70+
4671
describe('isConsiderReRun', () => {
4772
testEnv(rootDir);
4873

Diff for: package.json

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@technote-space/auto-cancel-redundant-workflow",
3-
"version": "1.7.3",
3+
"version": "1.7.4",
44
"description": "GitHub Actions to automatically cancel redundant workflow.",
55
"keywords": [
66
"github",
@@ -31,39 +31,39 @@
3131
"lint:fix": "eslint --fix 'src/**/*.ts' '__tests__/**/*.ts'",
3232
"release": "yarn release-ga --test",
3333
"test": "yarn lint && yarn cover",
34-
"update": "npx npm-check-updates -u && yarn install && yarn upgrade && yarn audit",
34+
"update": "npm_config_yes=true npx npm-check-updates -u --timeout 100000 && yarn install && yarn upgrade && yarn audit",
3535
"postinstall": "[ -n \"$CI\" ] || [ ! -f node_modules/.bin/husky ] || husky install",
3636
"prepublishOnly": "[ -n \"$CI\" ] || [ ! -f node_modules/.bin/pinst ] || pinst --disable",
3737
"postpublish": "[ -n \"$CI\" ] || [ ! -f node_modules/.bin/pinst ] || pinst --enable"
3838
},
3939
"dependencies": {
40-
"@actions/core": "^1.2.6",
40+
"@actions/core": "^1.2.7",
4141
"@actions/github": "^4.0.0",
42-
"@octokit/openapi-types": "^5.1.1",
43-
"@octokit/plugin-paginate-rest": "^2.10.0",
44-
"@octokit/plugin-rest-endpoint-methods": "^4.12.2",
45-
"@octokit/types": "^6.10.1",
46-
"@technote-space/github-action-helper": "^5.2.2",
47-
"@technote-space/github-action-log-helper": "^0.1.19"
42+
"@octokit/openapi-types": "^6.2.1",
43+
"@octokit/plugin-paginate-rest": "^2.13.3",
44+
"@octokit/plugin-rest-endpoint-methods": "^5.1.1",
45+
"@octokit/types": "^6.14.1",
46+
"@technote-space/github-action-helper": "^5.2.6",
47+
"@technote-space/github-action-log-helper": "^0.1.24"
4848
},
4949
"devDependencies": {
50-
"@commitlint/cli": "^12.0.0",
51-
"@commitlint/config-conventional": "^12.0.0",
52-
"@technote-space/github-action-test-helper": "^0.7.2",
53-
"@technote-space/release-github-actions-cli": "^1.8.4",
54-
"@types/jest": "^26.0.20",
55-
"@types/node": "^14.14.31",
56-
"@typescript-eslint/eslint-plugin": "^4.15.2",
57-
"@typescript-eslint/parser": "^4.15.2",
58-
"eslint": "^7.20.0",
59-
"husky": "^5.1.1",
50+
"@commitlint/cli": "^12.1.1",
51+
"@commitlint/config-conventional": "^12.1.1",
52+
"@technote-space/github-action-test-helper": "^0.7.9",
53+
"@technote-space/release-github-actions-cli": "^1.8.5",
54+
"@types/jest": "^26.0.23",
55+
"@types/node": "^15.0.1",
56+
"@typescript-eslint/eslint-plugin": "^4.22.0",
57+
"@typescript-eslint/parser": "^4.22.0",
58+
"eslint": "^7.25.0",
59+
"husky": "^6.0.0",
6060
"jest": "^26.6.3",
6161
"jest-circus": "^26.6.3",
6262
"lint-staged": "^10.5.4",
63-
"nock": "^13.0.8",
63+
"nock": "^13.0.11",
6464
"pinst": "^2.1.6",
65-
"ts-jest": "^26.5.2",
66-
"typescript": "^4.2.2"
65+
"ts-jest": "^26.5.5",
66+
"typescript": "^4.2.4"
6767
},
6868
"publishConfig": {
6969
"access": "public"

Diff for: src/process.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {Context} from '@actions/github/lib/context';
2-
import {Octokit} from '@technote-space/github-action-helper/dist/types';
3-
import {Logger} from '@technote-space/github-action-log-helper';
1+
import type {Context} from '@actions/github/lib/context';
2+
import type {Octokit} from '@technote-space/github-action-helper/dist/types';
3+
import type {Logger} from '@technote-space/github-action-log-helper';
44
import {setOutput} from '@actions/core';
55
import {Utils} from '@technote-space/github-action-helper';
66
import {getTargetRunId, isExcludeContext, isConsiderReRun, getIntervalMs, getFilteredRun} from './utils/misc';

Diff for: src/utils/misc.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import type {components} from '@octokit/openapi-types';
2+
import type {Context} from '@actions/github/lib/context';
13
import {getInput} from '@actions/core';
2-
import {Context} from '@actions/github/lib/context';
34
import {ContextHelper, Utils} from '@technote-space/github-action-helper';
4-
import {components} from '@octokit/openapi-types';
55
import {SHOW_PROPERTIES} from '../constant';
66

77
type ActionsListWorkflowRunsResponseData = components['schemas']['workflow-run'];
@@ -25,7 +25,7 @@ export const isExcludeContext = (context: Context): boolean =>
2525
(isExcludeTagPush() && Utils.isTagRef(context)) ||
2626
(isExcludeMerged() && getMergeMessagePrefix().test(context.payload.head_commit.message))
2727
);
28-
export const isNotExcludeRun = (run: ActionsListWorkflowRunsResponseData): boolean => !isExcludeMerged() || !getMergeMessagePrefix().test(run.head_commit.message);
28+
export const isNotExcludeRun = (run: ActionsListWorkflowRunsResponseData): boolean => !isExcludeMerged() || !getMergeMessagePrefix().test(run.head_commit?.message ?? '');
2929
export const getTargetRunId = (context: Context): number => parseNumber(getInput('TARGET_RUN_ID'), context.runId);
3030
export const getTargetBranch = async(context: Context): Promise<string | undefined> => {
3131
if (context.payload.pull_request) {

Diff for: src/utils/workflow.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import {Context} from '@actions/github/lib/context';
2-
import {Octokit} from '@technote-space/github-action-helper/dist/types';
3-
import {Logger} from '@technote-space/github-action-log-helper';
1+
import type {OctokitResponse} from '@octokit/types';
2+
import type {PaginateInterface} from '@octokit/plugin-paginate-rest';
3+
import type {Octokit} from '@technote-space/github-action-helper/dist/types';
4+
import type {Context} from '@actions/github/lib/context';
5+
import type {Logger} from '@technote-space/github-action-log-helper';
6+
import type {components} from '@octokit/openapi-types';
47
import {Utils} from '@technote-space/github-action-helper';
5-
import {PaginateInterface} from '@octokit/plugin-paginate-rest';
6-
import {RestEndpointMethods} from '@octokit/plugin-rest-endpoint-methods/dist-types/generated/method-types';
7-
import {components} from '@octokit/openapi-types';
88
import {getTargetBranch, isNotExcludeRun} from './misc';
99

1010
type ActionsGetWorkflowRunResponseData = components['schemas']['workflow-run'];
@@ -55,7 +55,7 @@ export const getWorkflowRuns = async(workflowId: number, logger: Logger, octokit
5555
}
5656

5757
return (await (octokit.paginate as PaginateInterface)(
58-
(octokit as RestEndpointMethods).actions.listWorkflowRuns,
58+
octokit.actions.listWorkflowRuns,
5959
// eslint-disable-next-line no-warning-comments
6060
// TODO: remove ts-ignore after fixed types (https://github.com/octokit/types.ts/issues/122)
6161
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -64,7 +64,7 @@ export const getWorkflowRuns = async(workflowId: number, logger: Logger, octokit
6464
)).map(run => run as ActionsListWorkflowRunsResponseData).filter(run => run.event === context.eventName).filter(isNotExcludeRun);
6565
};
6666

67-
export const cancelWorkflowRun = async(runId: number, octokit: Octokit, context: Context): Promise<void> => (octokit as RestEndpointMethods).actions.cancelWorkflowRun({
67+
export const cancelWorkflowRun = async(runId: number, octokit: Octokit, context: Context): Promise<OctokitResponse<{ [key: string]: unknown; }>> => octokit.actions.cancelWorkflowRun({
6868
...context.repo,
6969
'run_id': runId,
7070
});

0 commit comments

Comments
 (0)