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

Commit 945d786

Browse files
Merge pull request #7 from technote-space/release/next-v1.1.0
release: v1.2.0
2 parents ce9a0c3 + 8685cb8 commit 945d786

File tree

5 files changed

+60
-13
lines changed

5 files changed

+60
-13
lines changed

__tests__/utils/misc.test.ts

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,48 @@
11
/* eslint-disable no-magic-numbers */
22
import { resolve } from 'path';
33
import { testEnv, getOctokit, generateContext } from '@technote-space/github-action-test-helper';
4-
import { getRunId, getTargetBranch } from '../../src/utils/misc';
4+
import { isExcludeContext, getRunId, getTargetBranch } from '../../src/utils/misc';
55

66
const rootDir = resolve(__dirname, '../..');
77

8+
describe('isExcludeContext', () => {
9+
testEnv(rootDir);
10+
11+
it('should true 1', () => {
12+
expect(isExcludeContext(generateContext({event: 'push', ref: 'refs/tags/v1.2.3'}))).toBe(true);
13+
});
14+
15+
it('should true 2', () => {
16+
process.env.INPUT_EXCLUDE_MERGED = 'true';
17+
expect(isExcludeContext(generateContext({event: 'push', ref: 'refs/heads/feature/change'}, {
18+
payload: {
19+
'head_commit': {
20+
message: 'Merge pull request #260 from test',
21+
},
22+
},
23+
}))).toBe(true);
24+
});
25+
26+
it('should false 1', () => {
27+
process.env.INPUT_EXCLUDE_TAG_PUSH = 'false';
28+
expect(isExcludeContext(generateContext({event: 'push', ref: 'refs/tags/v1.2.3'}))).toBe(false);
29+
});
30+
31+
it('should false 2', () => {
32+
expect(isExcludeContext(generateContext({event: 'push', ref: 'refs/heads/feature/change'}))).toBe(false);
33+
});
34+
35+
it('should false 3', () => {
36+
expect(isExcludeContext(generateContext({event: 'push', ref: 'refs/heads/feature/change'}, {
37+
payload: {
38+
'head_commit': {
39+
message: 'Merge pull request #260 from test',
40+
},
41+
},
42+
}))).toBe(false);
43+
});
44+
});
45+
846
describe('getRunId', () => {
947
testEnv(rootDir);
1048

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ inputs:
1717
description: Prefix to detect merge message.
1818
required: false
1919
default: 'Merge pull request'
20+
EXCLUDE_TAG_PUSH:
21+
description: Whether to exclude tag push.
22+
required: false
23+
default: 'true'
2024

2125
branding:
2226
icon: 'x-circle'

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@technote-space/auto-cancel-redundant-job",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "GitHub Actions to automatically cancel redundant jobs.",
55
"author": {
66
"name": "Technote",
@@ -27,12 +27,12 @@
2727
"dependencies": {
2828
"@actions/core": "^1.2.3",
2929
"@actions/github": "^2.1.1",
30-
"@technote-space/github-action-helper": "^1.3.0"
30+
"@technote-space/github-action-helper": "^1.3.1"
3131
},
3232
"devDependencies": {
3333
"@commitlint/cli": "^8.3.5",
3434
"@commitlint/config-conventional": "^8.3.4",
35-
"@technote-space/github-action-test-helper": "^0.2.5",
35+
"@technote-space/github-action-test-helper": "^0.2.6",
3636
"@technote-space/release-github-actions-cli": "^1.5.0",
3737
"@types/jest": "^25.1.4",
3838
"@types/node": "^13.9.0",

src/utils/misc.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import { ContextHelper, Utils } from '@technote-space/github-action-helper';
55

66
const getMergeMessagePrefix = (): RegExp => Utils.getPrefixRegExp(getInput('MERGE_MESSAGE_PREFIX'));
77
const isExcludeMerged = (): boolean => Utils.getBoolValue(getInput('EXCLUDE_MERGED'));
8-
export const isExcludeContext = (context: Context): boolean => ContextHelper.isPush(context) && isExcludeMerged() && getMergeMessagePrefix().test(context.payload.head_commit.message);
8+
const isExcludeTagPush = (): boolean => Utils.getBoolValue(getInput('EXCLUDE_TAG_PUSH'));
9+
export const isExcludeContext = (context: Context): boolean =>
10+
ContextHelper.isPush(context) && (
11+
(isExcludeTagPush() && Utils.isTagRef(context)) ||
12+
(isExcludeMerged() && getMergeMessagePrefix().test(context.payload.head_commit.message))
13+
);
914
export const isNotExcludeRun = (run: Octokit.ActionsListWorkflowRunsResponseWorkflowRunsItem): boolean => !isExcludeMerged() || !getMergeMessagePrefix().test(run.head_commit.message);
1015

1116
export const getRunId = (): number => Number(process.env.GITHUB_RUN_ID);

yarn.lock

+8-8
Original file line numberDiff line numberDiff line change
@@ -611,20 +611,20 @@
611611
"@actions/core" "^1.2.2"
612612
"@actions/github" "^2.1.1"
613613

614-
"@technote-space/github-action-helper@^1.2.2", "@technote-space/github-action-helper@^1.3.0":
615-
version "1.3.0"
616-
resolved "https://registry.yarnpkg.com/@technote-space/github-action-helper/-/github-action-helper-1.3.0.tgz#91aeab6c7c7da4d9a43ca6591a167f05e2cc8417"
617-
integrity sha512-iaMo6w09UwjpYQReCXKta8MjKnuQBGYQ+yf590DHkIoQgSVNNE+EeLDeeG3f4UEAJ27p1HpYpExnnPN/3bNOZA==
614+
"@technote-space/github-action-helper@^1.2.2", "@technote-space/github-action-helper@^1.3.1":
615+
version "1.3.1"
616+
resolved "https://registry.yarnpkg.com/@technote-space/github-action-helper/-/github-action-helper-1.3.1.tgz#c4a9e33ec85fb9493f96ee09660191a3d7e52d29"
617+
integrity sha512-G6CAmXLmAnRZge8qsSY7oa+isNE6L+AtaJc+MfVsa9WLn0AbHPrySsLuMw2BXT26afQ7o1NITr+JymM5lQgQwQ==
618618
dependencies:
619619
"@actions/core" "^1.2.3"
620620
"@actions/github" "^2.1.1"
621621
shell-escape "^0.2.0"
622622
sprintf-js "^1.1.2"
623623

624-
"@technote-space/github-action-test-helper@^0.2.5":
625-
version "0.2.5"
626-
resolved "https://registry.yarnpkg.com/@technote-space/github-action-test-helper/-/github-action-test-helper-0.2.5.tgz#86529a9c9478eb19dfcdcef02da1760df029c5cc"
627-
integrity sha512-AU0WBHoBNMrSX0vKnCBeNQ2+sdOGHEs2O8IqYVocITsqe3tCwpcYRaubulXfP6tpgW+0SOtMyjgvL9DEyDDFhA==
624+
"@technote-space/github-action-test-helper@^0.2.6":
625+
version "0.2.6"
626+
resolved "https://registry.yarnpkg.com/@technote-space/github-action-test-helper/-/github-action-test-helper-0.2.6.tgz#2b98508b9ab5932b3e974c479d2c489ae1da2c44"
627+
integrity sha512-P5L/Xkgl44NmHf6+iugLFfLH5j0ShbZrIK7jeJq6gqlc6+J8PK5B9ogachy1DZSBrMHQV16cpt4ZiZOcy1nvmQ==
628628
dependencies:
629629
"@actions/github" "^2.1.1"
630630
js-yaml "^3.13.1"

0 commit comments

Comments
 (0)