{"id":15684052,"url":"https://github.com/technote-space/github-action-helper","last_synced_at":"2025-05-07T15:07:11.405Z","repository":{"id":35124758,"uuid":"209694637","full_name":"technote-space/github-action-helper","owner":"technote-space","description":"Helper for GitHub Actions","archived":false,"fork":false,"pushed_at":"2023-12-30T11:24:54.000Z","size":4021,"stargazers_count":10,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-10T17:35:27.936Z","etag":null,"topics":["github-actions"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/technote-space.png","metadata":{"files":{"readme":"README.ja.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":"https://paypal.me/technote0space"}},"created_at":"2019-09-20T03:09:54.000Z","updated_at":"2023-10-09T05:06:08.000Z","dependencies_parsed_at":"2023-10-15T11:41:26.103Z","dependency_job_id":"1c598c28-2bf6-4dd9-bce3-35ec41e83984","html_url":"https://github.com/technote-space/github-action-helper","commit_stats":null,"previous_names":[],"tags_count":250,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technote-space%2Fgithub-action-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technote-space%2Fgithub-action-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technote-space%2Fgithub-action-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technote-space%2Fgithub-action-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/technote-space","download_url":"https://codeload.github.com/technote-space/github-action-helper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221209868,"owners_count":16777280,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["github-actions"],"created_at":"2024-10-03T17:10:18.356Z","updated_at":"2024-10-23T16:21:48.411Z","avatar_url":"https://github.com/technote-space.png","language":"TypeScript","funding_links":["https://paypal.me/technote0space"],"categories":[],"sub_categories":[],"readme":"# GitHub Action Helper\n\n[![npm version](https://badge.fury.io/js/%40technote-space%2Fgithub-action-helper.svg)](https://badge.fury.io/js/%40technote-space%2Fgithub-action-helper)\n[![CI Status](https://github.com/technote-space/github-action-helper/workflows/CI/badge.svg)](https://github.com/technote-space/github-action-helper/actions)\n[![codecov](https://codecov.io/gh/technote-space/github-action-helper/branch/master/graph/badge.svg)](https://codecov.io/gh/technote-space/github-action-helper)\n[![CodeFactor](https://www.codefactor.io/repository/github/technote-space/github-action-helper/badge)](https://www.codefactor.io/repository/github/technote-space/github-action-helper)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/technote-space/github-action-helper/blob/master/LICENSE)\n\n*Read this in other languages: [English](README.md), [日本語](README.ja.md).*\n\nGitHub Actions 用のヘルパー\n\n## Table of Contents\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\u003cdetails\u003e\n\u003csummary\u003eDetails\u003c/summary\u003e\n\n- [使用方法](#%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95)\n  - [Command](#command)\n  - [ApiHelper](#apihelper)\n  - [GitHelper](#githelper)\n  - [Utils](#utils)\n  - [ContextHelper](#contexthelper)\n  - [依存](#%E4%BE%9D%E5%AD%98)\n- [Author](#author)\n\n\u003c/details\u003e\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## 使用方法\n1. インストール  \n   1. npm  \n      `npm i @technote-space/github-action-helper`\n   1. yarn  \n      `yarn add @technote-space/github-action-helper`\n   \n1. 使用\n```typescript\nimport { Command, ApiHelper, GitHelper, Utils, ContextHelper } from '@technote-space/github-action-helper';\n```\n\n### Command\n```typescript\nimport { Command } from '@technote-space/github-action-helper';\nimport { Logger } from '@technote-space/github-action-log-helper';\n\nconst logger = new Logger();\nconst command = new Command(logger);\nasync function run() {\n    logger.startProcess('Simple use');\n    await command.execAsync({command: 'ls'});\n    logger.log();\n    logger.startProcess('Options');\n    await command.execAsync({command: 'ls', altCommand: 'alt', quiet: true, suppressError: true, suppressOutput: true});\n    logger.endProcess();\n\n    // ::group::Simple use\n    // [command]ls\n    //   \u003e\u003e README.md\n    //   \u003e\u003e src\n    // \n    // ::endgroup::\n    // ::group::Options\n    // [command]alt\n    // ::endgroup::\n}\n\nrun().catch(error =\u003e console.error(error));\n```\n\n### ApiHelper\n```typescript\nimport { ApiHelper } from '@technote-space/github-action-helper';\nimport { Logger } from '@technote-space/github-action-log-helper';\nimport { context } from '@actions/github';\nimport { GitHub } from '@actions/github' ;\nimport { getInput } from '@actions/core';\nimport path from 'path';\n\nconst helper = new ApiHelper(new Logger());\nasync function run() {\n    await helper.commit(path.resolve(__dirname, '..'), 'feat: commit message', ['README.md', 'package.json'], new GitHub(getInput('GITHUB_TOKEN', {required: true})), context);\n}\n\nrun().catch(error =\u003e console.error(error));\n```\n\n### GitHelper\n```typescript\nimport { GitHelper } from '@technote-space/github-action-helper';\nimport { Logger } from '@technote-space/github-action-log-helper';\nimport { context } from '@actions/github';\nimport path from 'path';\nconst workDir = path.resolve(__dirname, '..');\n\nconst helper = new GitHelper(new Logger());\nasync function run() {\n    await helper.getCurrentBranchName(workDir);\n    await helper.clone(workDir, 'test-branch', context);\n    await helper.checkout(workDir, context);\n    await helper.gitInit(workDir, 'test-branch');\n    await helper.config(workDir, 'name', 'email');\n    await helper.runCommand(workDir, ['command1', 'command2']);\n    await helper.getDiff(workDir);\n    await helper.checkDiff(workDir);\n    await helper.commit(workDir, 'commit message');\n    await helper.fetchTags(workDir, context);\n    await helper.deleteTag(workDir, 'delete-tag', context);\n    await helper.copyTag(workDir, 'new-tag', 'from-tag', context);\n    await helper.addLocalTag(workDir, 'add-tag');\n    await helper.push(workDir, 'test-tag', context);\n}\n\nrun().catch(error =\u003e console.error(error));\n```\n\n### Utils\n```typescript\nimport { Utils } from '@technote-space/github-action-helper';\nimport { context } from '@actions/github';\n\nconst {\n\tisCloned,\n\tisValidSemanticVersioning,\n\tnormalizeVersion,\n\tisBranch,\n\tisRemoteBranch,\n\tisPrRef,\n\tgetPrMergeRef,\n\tgetPrHeadRef,\n\tgetRefForUpdate,\n\tgetBranch,\n\tgetAccessToken,\n\tgetActor,\n\tescapeRegExp,\n\tgetRegExp,\n\tgetPrefixRegExp,\n\tgetSuffixRegExp,\n\tgetBoolValue,\n\tuniqueArray,\n\tgetWorkspace,\n\tsplit,\n\tgetArrayInput,\n\tsleep,\n\tuseNpm,\n\treplaceAll,\n\tgenerateNewPatchVersion,\n\tgenerateNewMinorVersion,\n\tgenerateNewMajorVersion,\n\tarrayChunk,\n} = Utils;\n\nconsole.log(isCloned('workDir'));  // e.g. true\nconsole.log(isValidSemanticVersioning('v1.2.3'));  // e.g. true\nconsole.log(normalizeVersion('v1.2-alpha'));  // e.g. 1.2.0-alpha\nconsole.log(normalizeVersion('v1.2-alpha', {onlyCore: true}));  // e.g. 1.2.0\nconsole.log(isBranch('refs/heads/feature/change'));  // e.g. true\nconsole.log(isRemoteBranch('refs/remotes/origin/feature/test'));  // e.g. true\nconsole.log(isPrRef('refs/pull/123/merge'));  // e.g. true\nconsole.log(getPrMergeRef('refs/pull/123/head'));  // e.g. refs/pull/123/merge\nconsole.log(getPrHeadRef('refs/pull/123/merge'));  // e.g. refs/pull/123/head\nconsole.log(getRefForUpdate(context));  // e.g. 'heads%2Fmaster'\nconsole.log(getBranch(context));  // e.g. 'master'\nconsole.log(getAccessToken(true/* required? */));  // e.g. 'token'\nconsole.log(getActor());  // e.g. 'octocat'\nconsole.log(escapeRegExp('.*+?^${}()|[]\\\\')); // '\\\\.\\\\*\\\\+\\\\?\\\\^\\\\$\\\\{\\\\}\\\\(\\\\)\\\\|\\\\[\\\\]\\\\\\\\'\nconsole.log(getRegExp(' test ').test('abc test xyz'));  // e.g. true\nconsole.log(getPrefixRegExp('feature/').test('feature/test'));  // e.g. true\nconsole.log(getSuffixRegExp('.php').test('test.php'));  // e.g. true\nconsole.log(getBoolValue('0'));  // false\nconsole.log(getBoolValue('false'));  // false\nconsole.log(uniqueArray([1, 2, 2, 3, 4, 3]));  // [1, 2, 3, 4]\nconsole.log(getWorkspace());  // e.g. /home/runner/work/RepoOwner/RepoName\nconsole.log(split('test1\\ntest2'));  // e.g. ['test1', 'test2']\nconsole.log(split(''));  // e.g. []\nconsole.log(getArrayInput('TEST'));  // e.g. ['test1', 'test2']\nconsole.log(useNpm('dir')); // e.g. true\nconsole.log(replaceAll('test1-test2-test3', 'test', 'abc')); // e.g. abc1-abc2-abc3\nconsole.log(generateNewPatchVersion('v1.2.3')); // v1.2.4\nconsole.log(generateNewMinorVersion('v1.2.3')); // v1.3.0\nconsole.log(generateNewMajorVersion('v1.2.3')); // v2.0.0\nconsole.log(arrayChunk([1, 2, 3, 4, 5, 6, 7], 3)); // [[1, 2, 3], [4, 5, 6], [7]]\nasync function run () {\n    await sleep(1000);\n}\nrun().catch(error =\u003e console.error(error));\n```\n\n### ContextHelper\n```typescript\nimport { ContextHelper } from '@technote-space/github-action-helper';\nimport { Logger } from '@technote-space/github-action-log-helper';\nimport { context } from '@actions/github';\n\nconst {\n\tisRelease,\n\tisPush,\n\tisPr,\n\tisIssue,\n\tisCron,\n\tgetTagName,\n\tgetSender,\n\tgetRepository,\n\tgetGitUrl,\n\tshowActionInfo,\n} = ContextHelper;\n\nconsole.log(isRelease(context));  // e.g. true\nconsole.log(isPush(context));  // e.g. true\nconsole.log(isPr(context));  // e.g. true\nconsole.log(isIssue(context));  // e.g. true\nconsole.log(isCron(context));  // e.g. true\nconsole.log(getGitUrl());  // e.g. https://octocat:token@github.com/RepoOwner/RepoName.git\nconsole.log(getRepository(context));  // e.g. 'RepoOwner/RepoName'\nconsole.log(getTagName(context));  // e.g. 'v1.2.3'\nconsole.log(getSender(context));  // e.g. 'octocat'\nshowActionInfo('root dir', new Logger(), context);\n```\n\n### 依存\n[@technote-space/github-action-log-helper](https://github.com/technote-space/github-action-log-helper)\n\n## Author\n[GitHub (Technote)](https://github.com/technote-space)  \n[Blog](https://technote.space)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechnote-space%2Fgithub-action-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechnote-space%2Fgithub-action-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechnote-space%2Fgithub-action-helper/lists"}