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

Commit 9e5bfd5

Browse files
feat: exclude tag push
1 parent ce9a0c3 commit 9e5bfd5

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
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'

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);

0 commit comments

Comments
 (0)