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

release: v1.2.0 #7

Merged
merged 3 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion __tests__/utils/misc.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,48 @@
/* eslint-disable no-magic-numbers */
import { resolve } from 'path';
import { testEnv, getOctokit, generateContext } from '@technote-space/github-action-test-helper';
import { getRunId, getTargetBranch } from '../../src/utils/misc';
import { isExcludeContext, getRunId, getTargetBranch } from '../../src/utils/misc';

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

describe('isExcludeContext', () => {
testEnv(rootDir);

it('should true 1', () => {
expect(isExcludeContext(generateContext({event: 'push', ref: 'refs/tags/v1.2.3'}))).toBe(true);
});

it('should true 2', () => {
process.env.INPUT_EXCLUDE_MERGED = 'true';
expect(isExcludeContext(generateContext({event: 'push', ref: 'refs/heads/feature/change'}, {
payload: {
'head_commit': {
message: 'Merge pull request #260 from test',
},
},
}))).toBe(true);
});

it('should false 1', () => {
process.env.INPUT_EXCLUDE_TAG_PUSH = 'false';
expect(isExcludeContext(generateContext({event: 'push', ref: 'refs/tags/v1.2.3'}))).toBe(false);
});

it('should false 2', () => {
expect(isExcludeContext(generateContext({event: 'push', ref: 'refs/heads/feature/change'}))).toBe(false);
});

it('should false 3', () => {
expect(isExcludeContext(generateContext({event: 'push', ref: 'refs/heads/feature/change'}, {
payload: {
'head_commit': {
message: 'Merge pull request #260 from test',
},
},
}))).toBe(false);
});
});

describe('getRunId', () => {
testEnv(rootDir);

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ inputs:
description: Prefix to detect merge message.
required: false
default: 'Merge pull request'
EXCLUDE_TAG_PUSH:
description: Whether to exclude tag push.
required: false
default: 'true'

branding:
icon: 'x-circle'
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@technote-space/auto-cancel-redundant-job",
"version": "1.1.0",
"version": "1.2.0",
"description": "GitHub Actions to automatically cancel redundant jobs.",
"author": {
"name": "Technote",
Expand All @@ -27,12 +27,12 @@
"dependencies": {
"@actions/core": "^1.2.3",
"@actions/github": "^2.1.1",
"@technote-space/github-action-helper": "^1.3.0"
"@technote-space/github-action-helper": "^1.3.1"
},
"devDependencies": {
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@technote-space/github-action-test-helper": "^0.2.5",
"@technote-space/github-action-test-helper": "^0.2.6",
"@technote-space/release-github-actions-cli": "^1.5.0",
"@types/jest": "^25.1.4",
"@types/node": "^13.9.0",
Expand Down
7 changes: 6 additions & 1 deletion src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { ContextHelper, Utils } from '@technote-space/github-action-helper';

const getMergeMessagePrefix = (): RegExp => Utils.getPrefixRegExp(getInput('MERGE_MESSAGE_PREFIX'));
const isExcludeMerged = (): boolean => Utils.getBoolValue(getInput('EXCLUDE_MERGED'));
export const isExcludeContext = (context: Context): boolean => ContextHelper.isPush(context) && isExcludeMerged() && getMergeMessagePrefix().test(context.payload.head_commit.message);
const isExcludeTagPush = (): boolean => Utils.getBoolValue(getInput('EXCLUDE_TAG_PUSH'));
export const isExcludeContext = (context: Context): boolean =>
ContextHelper.isPush(context) && (
(isExcludeTagPush() && Utils.isTagRef(context)) ||
(isExcludeMerged() && getMergeMessagePrefix().test(context.payload.head_commit.message))
);
export const isNotExcludeRun = (run: Octokit.ActionsListWorkflowRunsResponseWorkflowRunsItem): boolean => !isExcludeMerged() || !getMergeMessagePrefix().test(run.head_commit.message);

export const getRunId = (): number => Number(process.env.GITHUB_RUN_ID);
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -611,20 +611,20 @@
"@actions/core" "^1.2.2"
"@actions/github" "^2.1.1"

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

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