5.3.17 • Published 12 months ago

@technote-space/github-action-helper v5.3.17

Weekly downloads
962
License
MIT
Repository
github
Last release
12 months ago

GitHub Action Helper

npm version CI Status codecov CodeFactor License: MIT

Read this in other languages: English, 日本語.

GitHub Actions 用のヘルパー

Table of Contents

使用方法

  1. インストール

    1. npm
      npm i @technote-space/github-action-helper
    2. yarn
      yarn add @technote-space/github-action-helper
  2. 使用

import { Command, ApiHelper, GitHelper, Utils, ContextHelper } from '@technote-space/github-action-helper';

Command

import { Command } from '@technote-space/github-action-helper';
import { Logger } from '@technote-space/github-action-log-helper';

const logger = new Logger();
const command = new Command(logger);
async function run() {
    logger.startProcess('Simple use');
    await command.execAsync({command: 'ls'});
    logger.log();
    logger.startProcess('Options');
    await command.execAsync({command: 'ls', altCommand: 'alt', quiet: true, suppressError: true, suppressOutput: true});
    logger.endProcess();

    // ::group::Simple use
    // [command]ls
    //   >> README.md
    //   >> src
    // 
    // ::endgroup::
    // ::group::Options
    // [command]alt
    // ::endgroup::
}

run().catch(error => console.error(error));

ApiHelper

import { ApiHelper } from '@technote-space/github-action-helper';
import { Logger } from '@technote-space/github-action-log-helper';
import { context } from '@actions/github';
import { GitHub } from '@actions/github' ;
import { getInput } from '@actions/core';
import path from 'path';

const helper = new ApiHelper(new Logger());
async function run() {
    await helper.commit(path.resolve(__dirname, '..'), 'feat: commit message', ['README.md', 'package.json'], new GitHub(getInput('GITHUB_TOKEN', {required: true})), context);
}

run().catch(error => console.error(error));

GitHelper

import { GitHelper } from '@technote-space/github-action-helper';
import { Logger } from '@technote-space/github-action-log-helper';
import { context } from '@actions/github';
import path from 'path';
const workDir = path.resolve(__dirname, '..');

const helper = new GitHelper(new Logger());
async function run() {
    await helper.getCurrentBranchName(workDir);
    await helper.clone(workDir, 'test-branch', context);
    await helper.checkout(workDir, context);
    await helper.gitInit(workDir, 'test-branch');
    await helper.config(workDir, 'name', 'email');
    await helper.runCommand(workDir, ['command1', 'command2']);
    await helper.getDiff(workDir);
    await helper.checkDiff(workDir);
    await helper.commit(workDir, 'commit message');
    await helper.fetchTags(workDir, context);
    await helper.deleteTag(workDir, 'delete-tag', context);
    await helper.copyTag(workDir, 'new-tag', 'from-tag', context);
    await helper.addLocalTag(workDir, 'add-tag');
    await helper.push(workDir, 'test-tag', context);
}

run().catch(error => console.error(error));

Utils

import { Utils } from '@technote-space/github-action-helper';
import { context } from '@actions/github';

const {
	isCloned,
	isValidSemanticVersioning,
	normalizeVersion,
	isBranch,
	isRemoteBranch,
	isPrRef,
	getPrMergeRef,
	getPrHeadRef,
	getRefForUpdate,
	getBranch,
	getAccessToken,
	getActor,
	escapeRegExp,
	getRegExp,
	getPrefixRegExp,
	getSuffixRegExp,
	getBoolValue,
	uniqueArray,
	getWorkspace,
	split,
	getArrayInput,
	sleep,
	useNpm,
	replaceAll,
	generateNewPatchVersion,
	generateNewMinorVersion,
	generateNewMajorVersion,
	arrayChunk,
} = Utils;

console.log(isCloned('workDir'));  // e.g. true
console.log(isValidSemanticVersioning('v1.2.3'));  // e.g. true
console.log(normalizeVersion('v1.2-alpha'));  // e.g. 1.2.0-alpha
console.log(normalizeVersion('v1.2-alpha', {onlyCore: true}));  // e.g. 1.2.0
console.log(isBranch('refs/heads/feature/change'));  // e.g. true
console.log(isRemoteBranch('refs/remotes/origin/feature/test'));  // e.g. true
console.log(isPrRef('refs/pull/123/merge'));  // e.g. true
console.log(getPrMergeRef('refs/pull/123/head'));  // e.g. refs/pull/123/merge
console.log(getPrHeadRef('refs/pull/123/merge'));  // e.g. refs/pull/123/head
console.log(getRefForUpdate(context));  // e.g. 'heads%2Fmaster'
console.log(getBranch(context));  // e.g. 'master'
console.log(getAccessToken(true/* required? */));  // e.g. 'token'
console.log(getActor());  // e.g. 'octocat'
console.log(escapeRegExp('.*+?^${}()|[]\\')); // '\\.\\*\\+\\?\\^\\$\\{\\}\\(\\)\\|\\[\\]\\\\'
console.log(getRegExp(' test ').test('abc test xyz'));  // e.g. true
console.log(getPrefixRegExp('feature/').test('feature/test'));  // e.g. true
console.log(getSuffixRegExp('.php').test('test.php'));  // e.g. true
console.log(getBoolValue('0'));  // false
console.log(getBoolValue('false'));  // false
console.log(uniqueArray([1, 2, 2, 3, 4, 3]));  // [1, 2, 3, 4]
console.log(getWorkspace());  // e.g. /home/runner/work/RepoOwner/RepoName
console.log(split('test1\ntest2'));  // e.g. ['test1', 'test2']
console.log(split(''));  // e.g. []
console.log(getArrayInput('TEST'));  // e.g. ['test1', 'test2']
console.log(useNpm('dir')); // e.g. true
console.log(replaceAll('test1-test2-test3', 'test', 'abc')); // e.g. abc1-abc2-abc3
console.log(generateNewPatchVersion('v1.2.3')); // v1.2.4
console.log(generateNewMinorVersion('v1.2.3')); // v1.3.0
console.log(generateNewMajorVersion('v1.2.3')); // v2.0.0
console.log(arrayChunk([1, 2, 3, 4, 5, 6, 7], 3)); // [[1, 2, 3], [4, 5, 6], [7]]
async function run () {
    await sleep(1000);
}
run().catch(error => console.error(error));

ContextHelper

import { ContextHelper } from '@technote-space/github-action-helper';
import { Logger } from '@technote-space/github-action-log-helper';
import { context } from '@actions/github';

const {
	isRelease,
	isPush,
	isPr,
	isIssue,
	isCron,
	getTagName,
	getSender,
	getRepository,
	getGitUrl,
	showActionInfo,
} = ContextHelper;

console.log(isRelease(context));  // e.g. true
console.log(isPush(context));  // e.g. true
console.log(isPr(context));  // e.g. true
console.log(isIssue(context));  // e.g. true
console.log(isCron(context));  // e.g. true
console.log(getGitUrl());  // e.g. https://octocat:token@github.com/RepoOwner/RepoName.git
console.log(getRepository(context));  // e.g. 'RepoOwner/RepoName'
console.log(getTagName(context));  // e.g. 'v1.2.3'
console.log(getSender(context));  // e.g. 'octocat'
showActionInfo('root dir', new Logger(), context);

依存

@technote-space/github-action-log-helper

Author

GitHub (Technote)
Blog

5.3.17

12 months ago

5.3.16

12 months ago

5.3.15

12 months ago

5.3.14

12 months ago

5.3.13

1 year ago

5.3.12

1 year ago

5.3.11

1 year ago

5.3.9

2 years ago

5.3.10

1 year ago

5.3.8

2 years ago

5.3.7

2 years ago

5.3.6

2 years ago

5.3.5

2 years ago

5.3.4

2 years ago

5.3.3

2 years ago

5.3.2

2 years ago

5.3.1

2 years ago

5.3.0

2 years ago

5.2.28

2 years ago

5.2.27

2 years ago

5.2.26

2 years ago

5.2.25

2 years ago

5.2.24

2 years ago

5.2.23

2 years ago

5.2.22

3 years ago

5.2.21

3 years ago

5.2.20

3 years ago

5.2.19

3 years ago

5.2.18

3 years ago

5.2.17

3 years ago

5.2.16

3 years ago

5.2.15

3 years ago

5.2.14

3 years ago

5.2.13

3 years ago

5.2.12

3 years ago

5.2.11

3 years ago

5.2.10

3 years ago

5.2.9

3 years ago

5.2.8

3 years ago

5.2.7

3 years ago

5.2.6

3 years ago

5.2.5

3 years ago

5.2.4

3 years ago

5.2.3

3 years ago

5.2.2

3 years ago

5.2.1

3 years ago

5.2.0

3 years ago

5.1.1

3 years ago

5.1.0

3 years ago

5.0.0

3 years ago

4.4.11

3 years ago

4.4.10

3 years ago

4.4.9

3 years ago

4.4.8

3 years ago

4.4.7

3 years ago

4.4.6

3 years ago

4.4.5

3 years ago

4.4.3

3 years ago

4.4.2

3 years ago

4.4.4

3 years ago

4.4.1

3 years ago

4.4.0

3 years ago

4.3.2

3 years ago

4.3.1

3 years ago

4.3.0

3 years ago

4.2.7

3 years ago

4.2.6

3 years ago

4.2.5

3 years ago

4.2.3

3 years ago

4.2.4

3 years ago

4.2.2

3 years ago

4.2.1

3 years ago

4.2.0

3 years ago

4.1.0

3 years ago

4.0.6

4 years ago

4.0.5

4 years ago

4.0.4

4 years ago

4.0.3

4 years ago

4.0.2

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.5.0

4 years ago

3.4.0

4 years ago

3.3.1

4 years ago

3.3.0

4 years ago

3.2.0

4 years ago

3.1.2

4 years ago

3.1.1

4 years ago

3.1.0

4 years ago

3.0.4

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.0.11

4 years ago

2.0.10

4 years ago

2.0.9

4 years ago

2.0.8

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.2

4 years ago

1.1.0

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

0.8.7

4 years ago

0.8.5

4 years ago

0.8.6

4 years ago

0.8.4

4 years ago

0.8.3

4 years ago

0.8.2

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.7.7

4 years ago

0.7.6

4 years ago

0.7.5

4 years ago

0.7.4

4 years ago

0.7.3

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.29

4 years ago

0.6.28

4 years ago

0.6.26

4 years ago

0.6.25

4 years ago

0.6.23

4 years ago

0.6.22

4 years ago

0.6.24

4 years ago

0.6.21

4 years ago

0.6.20

4 years ago

0.6.19

4 years ago

0.6.18

4 years ago

0.6.17

4 years ago

0.6.10

4 years ago

0.6.12

4 years ago

0.6.11

4 years ago

0.6.14

4 years ago

0.6.13

4 years ago

0.6.16

4 years ago

0.6.15

4 years ago

0.6.7

4 years ago

0.6.9

4 years ago

0.6.8

4 years ago

0.6.6

4 years ago

0.6.5

4 years ago

0.6.4

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.3

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.29

4 years ago

0.2.28

4 years ago

0.2.27

4 years ago

0.2.26

5 years ago

0.2.25

5 years ago

0.2.24

5 years ago

0.2.23

5 years ago

0.2.22

5 years ago

0.2.21

5 years ago

0.2.20

5 years ago

0.2.19

5 years ago

0.2.18

5 years ago

0.2.17

5 years ago

0.2.16

5 years ago

0.2.15

5 years ago

0.2.14

5 years ago

0.2.13

5 years ago

0.2.12

5 years ago

0.2.11

5 years ago

0.2.10

5 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.19

5 years ago

0.1.18

5 years ago

0.1.17

5 years ago

0.1.16

5 years ago

0.1.15

5 years ago

0.1.14

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago