npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@technote-space/github-action-helper

v5.3.17

Published

Helper for GitHub Action.

Downloads

323

Readme

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:[email protected]/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