typescript-github-action-template 0.1.18 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,11 @@
1
- # typescript-github-action-template
1
+ # Typescript GitHub Action Template
2
2
 
3
3
  A template to create custom GitHub Action with TypeScript/JavaScript.
4
+
5
+ ## Secrets
6
+
7
+ The following secrets need to be set up before you can use workflows already defined in this template:
8
+
9
+ - **`CHECK_GIT_STATUS_BOT_APP_ID`** and **`CHECK_GIT_STATUS_BOT_APP_PRIVATE_KEY`**: Used by the [`Build` workflow](https://github.com/CatChen/typescript-github-action-template/blob/main/.github/workflows/build.yml). If you don't want to set up a bot you can remove the `actions/create-github-app-token` step and remove all references to `steps.get-github-app-token.outputs.token`.
10
+ - **`ACCEPT_TO_SHIP_BOT_APP_ID`** and **`ACCEPT_TO_SHIP_BOT_APP_PRIVATE_KEY`**: Used by the [`Ship` workflow](https://github.com/CatChen/typescript-github-action-template/blob/main/.github/workflows/ship.yml). If you don't want to set up a bot you can remove the two `actions/create-github-app-token` steps and remove all references to `steps.get-github-app-token.outputs.token`.
11
+ - **`NPM_TOKEN`**: Used by the [`Release` workflow](https://github.com/CatChen/typescript-github-action-template/blob/main/.github/workflows/release.yml). This is necessary for publishing the NPM package to NPM. If you don't want to publish to NPM you can remove the `publish` job.
@@ -0,0 +1,6 @@
1
+ import { type Octokit } from '@octokit/core/dist-types/index.js';
2
+ import { type PaginateInterface } from '@octokit/plugin-paginate-rest';
3
+ import { type Api } from '@octokit/plugin-rest-endpoint-methods/dist-types/types.js';
4
+ export declare function getOctokit(githubToken: string): Octokit & Api & {
5
+ paginate: PaginateInterface;
6
+ };
@@ -0,0 +1,39 @@
1
+ import { GitHub, getOctokitOptions } from '@actions/github/lib/utils.js';
2
+ import { retry } from '@octokit/plugin-retry';
3
+ import { throttling } from '@octokit/plugin-throttling';
4
+ export function getOctokit(githubToken) {
5
+ const Octokit = GitHub.plugin(throttling, retry);
6
+ const octokit = new Octokit(getOctokitOptions(githubToken, {
7
+ throttle: {
8
+ onRateLimit: (retryAfter, options, _, retryCount) => {
9
+ if (retryCount === 0) {
10
+ octokit.log.warn(`Request quota exhausted for request ${options.method} ${options.url}`);
11
+ octokit.log.info(`Retrying after ${retryAfter} seconds!`);
12
+ return true;
13
+ }
14
+ else {
15
+ octokit.log.error(`Request quota exhausted for request ${options.method} ${options.url}`);
16
+ }
17
+ },
18
+ onSecondaryRateLimit: (retryAfter, options, _, retryCount) => {
19
+ if (retryCount === 0) {
20
+ octokit.log.warn(`Abuse detected for request ${options.method} ${options.url}`);
21
+ octokit.log.info(`Retrying after ${retryAfter} seconds!`);
22
+ return true;
23
+ }
24
+ else {
25
+ octokit.log.warn(`Abuse detected for request ${options.method} ${options.url}`);
26
+ }
27
+ },
28
+ },
29
+ retry: {
30
+ doNotRetry: ['429'],
31
+ },
32
+ }));
33
+ octokit.graphql = octokit.graphql.defaults({
34
+ headers: {
35
+ 'X-GitHub-Next-Global-ID': 1,
36
+ },
37
+ });
38
+ return octokit;
39
+ }
@@ -0,0 +1 @@
1
+ export declare function getLogin(githubToken: string): Promise<string>;
package/dist/index.js ADDED
@@ -0,0 +1,45 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { error, getInput, getState, notice, saveState, setFailed, } from '@actions/core';
11
+ import { getOctokit } from './getOctokit.js';
12
+ export function getLogin(githubToken) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ const octokit = getOctokit(githubToken);
15
+ const { viewer: { login }, } = yield octokit.graphql(`
16
+ query {
17
+ viewer {
18
+ login
19
+ }
20
+ }
21
+ `, {});
22
+ return login;
23
+ });
24
+ }
25
+ function run() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const githubToken = getInput('github-token');
28
+ const login = yield getLogin(githubToken);
29
+ saveState('login', login);
30
+ notice(`Hello, ${login}!`);
31
+ error('Please implement this Action.');
32
+ });
33
+ }
34
+ function cleanup() {
35
+ const login = getState('login');
36
+ notice(`Goodbye, ${login}!`);
37
+ error('Please implemented or removed Action cleanup.');
38
+ }
39
+ if (!getState('isPost')) {
40
+ saveState('isPost', 'true');
41
+ run().catch((error) => setFailed(error));
42
+ }
43
+ else {
44
+ cleanup();
45
+ }
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "typescript-github-action-template",
3
- "version": "0.1.18",
3
+ "version": "0.2.0",
4
4
  "description": "A template to create custom GitHub Action with TypeScript/JavaScript.",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.js",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.js",
7
7
  "type": "module",
8
8
  "scripts": {
9
- "build": "rm -rf lib && yarn tsc",
10
- "package": "rm -rf dist && yarn ncc build src/index.ts --external eslint --source-map --license licenses.txt",
9
+ "build": "rm -rf dist && yarn tsc",
10
+ "bundle": "rm -rf bundle && yarn ncc build src/index.ts --external eslint --source-map --license licenses.txt --out bundle",
11
11
  "test": "echo \"Error: no test specified\" && exit 1",
12
12
  "lint": "eslint -c eslint.config.js",
13
- "postinstall": "is-ci || husky install",
14
- "preversion": "rm -rf lib && rm -rf dist && yarn && yarn build && yarn package"
13
+ "_postinstall": "is-ci || husky install",
14
+ "prepublishOnly": "pinst --disable && yarn build",
15
+ "postpublish": "pinst --enable",
16
+ "preversion": "yarn && yarn build && yarn bundle"
15
17
  },
16
18
  "repository": {
17
19
  "type": "git",
@@ -27,7 +29,7 @@
27
29
  "devDependencies": {
28
30
  "@eslint/eslintrc": "^3.0.2",
29
31
  "@eslint/js": "^9.2.0",
30
- "@trivago/prettier-plugin-sort-imports": "^4.0.0",
32
+ "@serverless-guru/prettier-plugin-import-order": "^0.4.2",
31
33
  "@types/node": "^20.1.0",
32
34
  "@typescript-eslint/eslint-plugin": "^7.0.1",
33
35
  "@typescript-eslint/parser": "^7.0.1",
@@ -38,13 +40,16 @@
38
40
  "husky": "^9.0.5",
39
41
  "is-ci": "^3.0.1",
40
42
  "lint-staged": "^15.0.2",
43
+ "pinst": "^3.0.0",
41
44
  "prettier": "^3.0.2",
42
45
  "typescript": "^5.0.2",
43
46
  "typescript-eslint": "^7.8.0"
44
47
  },
45
48
  "dependencies": {
46
49
  "@actions/core": "^1.10.0",
47
- "@actions/github": "^6.0.0"
50
+ "@actions/github": "^6.0.0",
51
+ "@octokit/plugin-retry": "^7.1.1",
52
+ "@octokit/plugin-throttling": "^9.3.0"
48
53
  },
49
54
  "lint-staged": {
50
55
  "*.(ts,js)": "yarn lint --fix",
package/.prettierrc.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "arrowParens": "always",
3
- "bracketSpacing": true,
4
- "bracketSameLine": false,
5
- "semi": true,
6
- "singleQuote": true,
7
- "tabWidth": 2,
8
- "trailingComma": "all",
9
- "importOrder": [
10
- "^node:(.*)$",
11
- "^@action/core/(.*)$",
12
- "^@action/github/(.*)$",
13
- "^@action/exec/(.*)$",
14
- "^@action/glob/(.*)$",
15
- "^@action/(.*)$",
16
- "<THIRD_PARTY_MODULES>",
17
- "^[./]"
18
- ],
19
- "importOrderSeparation": true,
20
- "importOrderSortSpecifiers": true
21
- }
@@ -1,11 +0,0 @@
1
- {
2
- "yaml.schemas": {
3
- "https://json.schemastore.org/github-action.json": "action.yml",
4
- "https://json.schemastore.org/github-funding.json": ".github/FUNDING.yml",
5
- "https://json.schemastore.org/github-workflow.json": ".github/workflows/*.yml",
6
- "https://json.schemastore.org/package.json": "package.json",
7
- "https://json.schemastore.org/tsconfig.json": "tsconfig.json",
8
- "https://json.schemastore.org/eslintrc.json": ".eslintrc.json",
9
- "https://json.schemastore.org/prettierrc.json": ".prettierrc.json"
10
- }
11
- }
package/eslint.config.js DELETED
@@ -1,45 +0,0 @@
1
- import js from '@eslint/js';
2
- import { FlatCompat } from '@eslint/eslintrc';
3
- import path from 'path';
4
- import { fileURLToPath } from 'url';
5
- import ts from 'typescript-eslint';
6
-
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = path.dirname(__filename);
9
-
10
- const compat = new FlatCompat({
11
- baseDirectory: __dirname,
12
- resolvePluginsRelativeTo: __dirname,
13
- recommendedConfig: js.configs.recommended,
14
- });
15
-
16
- export default ts.config(
17
- ...compat.config({
18
- env: {
19
- browser: true,
20
- es2022: true,
21
- node: true,
22
- },
23
- extends: ['eslint:recommended', 'plugin:prettier/recommended'],
24
- parser: '@typescript-eslint/parser',
25
- parserOptions: {
26
- project: './tsconfig.json',
27
- ecmaVersion: 'latest',
28
- sourceType: 'module',
29
- },
30
- root: true,
31
- rules: {},
32
- ignorePatterns: [
33
- 'node_modules/**/*',
34
- 'lib/**/*',
35
- 'dist/**/*',
36
- 'eslint.config.js',
37
- ],
38
- overrides: [
39
- {
40
- files: ['*.ts'],
41
- },
42
- ],
43
- }),
44
- ...ts.configs.recommendedTypeChecked,
45
- );
package/lib/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/lib/index.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@actions/core");
4
- const github_1 = require("@actions/github");
5
- function run() {
6
- if (!(0, core_1.getState)('isPost')) {
7
- (0, core_1.saveState)('isPost', 'true');
8
- }
9
- (0, core_1.info)(`This is the Action context: ${JSON.stringify(github_1.context)}`);
10
- (0, core_1.error)('Action needs to be implemented.');
11
- }
12
- function cleanup() {
13
- (0, core_1.error)('Post action needs to be implemented or removed.');
14
- }
15
- if (!(0, core_1.getState)('isPost')) {
16
- run();
17
- }
18
- else {
19
- cleanup();
20
- }