node-package-release-action 2.1.21 → 2.3.0-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.
@@ -1 +1 @@
1
- export declare function checkDiff(tag: string): Promise<boolean>;
1
+ export declare function checkDiff(tag: string, directory: string, diffTargets: string): Promise<boolean>;
package/dist/checkDiff.js CHANGED
@@ -5,9 +5,7 @@ const node_path_1 = require("node:path");
5
5
  const core_1 = require("@actions/core");
6
6
  const exec_1 = require("@actions/exec");
7
7
  const glob_1 = require("glob");
8
- async function checkDiff(tag) {
9
- const directory = (0, core_1.getInput)('directory');
10
- const diffTargets = (0, core_1.getInput)('diff-targets');
8
+ async function checkDiff(tag, directory, diffTargets) {
11
9
  const diffOutput = await (0, exec_1.getExecOutput)('git', [
12
10
  'diff',
13
11
  tag,
@@ -1,5 +1 @@
1
- import type { Octokit } from '@octokit/core';
2
- import type { Api } from '@octokit/plugin-rest-endpoint-methods/dist-types/types';
3
- export declare const GITHUB_ACTION_USER_NAME = "GitHub Action";
4
- export declare const GITHUB_ACTION_USER_EMAIL = "41898282+github-actions[bot]@users.noreply.github.com";
5
- export declare function configGit(octokit: Octokit & Api): Promise<void>;
1
+ export declare function configGit(): Promise<void>;
package/dist/configGit.js CHANGED
@@ -1,24 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GITHUB_ACTION_USER_EMAIL = exports.GITHUB_ACTION_USER_NAME = void 0;
4
3
  exports.configGit = configGit;
5
- const core_1 = require("@actions/core");
6
4
  const exec_1 = require("@actions/exec");
7
- exports.GITHUB_ACTION_USER_NAME = 'GitHub Action';
8
- exports.GITHUB_ACTION_USER_EMAIL = '41898282+github-actions[bot]@users.noreply.github.com';
9
- async function configGit(octokit) {
10
- await (0, exec_1.getExecOutput)('git', [
11
- 'config',
12
- '--global',
13
- 'user.name',
14
- exports.GITHUB_ACTION_USER_NAME,
15
- ]);
16
- await (0, exec_1.getExecOutput)('git', [
17
- 'config',
18
- '--global',
19
- 'user.email',
20
- exports.GITHUB_ACTION_USER_EMAIL,
21
- ]);
5
+ async function configGit() {
22
6
  await (0, exec_1.getExecOutput)('git', ['config', '--global', 'push.default', 'simple']);
23
7
  await (0, exec_1.getExecOutput)('git', [
24
8
  'config',
@@ -26,28 +10,4 @@ async function configGit(octokit) {
26
10
  'push.autoSetupRemote',
27
11
  'true',
28
12
  ]);
29
- const githubToken = (0, core_1.getInput)('github-token');
30
- (0, core_1.exportVariable)('GH_TOKEN', githubToken);
31
- await (0, exec_1.getExecOutput)('gh', ['auth', 'status']);
32
- await (0, exec_1.getExecOutput)('gh', ['auth', 'setup-git']);
33
- const { viewer: { login }, } = await octokit.graphql(`
34
- query {
35
- viewer {
36
- login
37
- }
38
- }
39
- `, {});
40
- const remoteOutput = await (0, exec_1.getExecOutput)('git', [
41
- 'remote',
42
- 'get-url',
43
- 'origin',
44
- ]);
45
- const remoteUrl = remoteOutput.stdout.trim();
46
- const remoteUrlWithToken = remoteUrl.replace(/https:\/\//, `https://${login}:${githubToken}@`);
47
- await (0, exec_1.getExecOutput)('git', [
48
- 'remote',
49
- 'set-url',
50
- 'origin',
51
- remoteUrlWithToken,
52
- ]);
53
13
  }
@@ -1,4 +1,4 @@
1
1
  import type { Octokit } from '@octokit/core';
2
- import type { components } from '@octokit/openapi-types/types.js';
3
2
  import type { Api } from '@octokit/plugin-rest-endpoint-methods/dist-types/types';
4
- export declare function createRelease(owner: string, repo: string, version: string, octokit: Octokit & Api): Promise<components['schemas']['release'] | undefined>;
3
+ import type { Release } from '@octokit/webhooks-types/schema';
4
+ export declare function createRelease(owner: string, repo: string, version: string, prerelease: boolean, dryRun: boolean, octokit: Octokit & Api): Promise<Release | undefined>;
@@ -2,8 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createRelease = createRelease;
4
4
  const core_1 = require("@actions/core");
5
- async function createRelease(owner, repo, version, octokit) {
6
- const dryRun = (0, core_1.getBooleanInput)('dry-run');
5
+ async function createRelease(owner, repo, version, prerelease, dryRun, octokit) {
7
6
  if (dryRun) {
8
7
  (0, core_1.notice)('Release creation is skipped in dry run');
9
8
  const response = await octokit.rest.repos.generateReleaseNotes({
@@ -22,7 +21,7 @@ async function createRelease(owner, repo, version, octokit) {
22
21
  tag_name: `v${version}`,
23
22
  name: `v${version}`,
24
23
  generate_release_notes: true,
25
- prerelease: (0, core_1.getBooleanInput)('prerelease'),
24
+ prerelease,
26
25
  });
27
26
  (0, core_1.notice)(`GitHub Release created: ${releasesResponse.data.html_url}`);
28
27
  return releasesResponse.data;
@@ -1,2 +1,2 @@
1
1
  export declare const DEFAULT_WORKING_DIRECTORY: string;
2
- export declare function getPackageVersion(): string | null;
2
+ export declare function getPackageVersion(directory: string): string | null;
@@ -7,8 +7,7 @@ const node_fs_1 = require("node:fs");
7
7
  const node_path_1 = require("node:path");
8
8
  const core_1 = require("@actions/core");
9
9
  exports.DEFAULT_WORKING_DIRECTORY = process.cwd();
10
- function getPackageVersion() {
11
- const directory = (0, core_1.getInput)('directory');
10
+ function getPackageVersion(directory) {
12
11
  const absoluteDirectory = (0, node_path_1.resolve)(exports.DEFAULT_WORKING_DIRECTORY, directory);
13
12
  const packageJsonPath = (0, node_path_1.resolve)(absoluteDirectory, 'package.json');
14
13
  if (!(0, node_fs_1.existsSync)(packageJsonPath)) {
package/dist/index.d.ts CHANGED
@@ -1,2 +1,12 @@
1
- import type { components } from '@octokit/openapi-types/types.js';
2
- export declare function nodePackageRelease(githubToken: string): Promise<components['schemas']['release'] | undefined>;
1
+ import type { Release } from '@octokit/webhooks-types/schema';
2
+ import { type ReleaseType } from 'semver';
3
+ export declare function nodePackageRelease({ githubToken, directory, releaseType, prerelease, updateShorthandRelease, skipIfNoDiff, diffTargets, dryRun, }: {
4
+ githubToken: string;
5
+ directory: string;
6
+ releaseType: ReleaseType;
7
+ prerelease: boolean;
8
+ updateShorthandRelease: boolean;
9
+ skipIfNoDiff: boolean;
10
+ diffTargets: string;
11
+ dryRun: boolean;
12
+ }): Promise<Release | undefined>;
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nodePackageRelease = nodePackageRelease;
4
4
  const core_1 = require("@actions/core");
5
5
  const github_1 = require("@actions/github");
6
+ const config_git_with_token_action_1 = require("config-git-with-token-action");
6
7
  const semver_1 = require("semver");
7
8
  const ReleaseType_1 = require("./ReleaseType");
8
9
  const checkDiff_1 = require("./checkDiff");
@@ -18,9 +19,10 @@ const pushBranch_1 = require("./pushBranch");
18
19
  const setVersion_1 = require("./setVersion");
19
20
  const updateTags_1 = require("./updateTags");
20
21
  const DEFAULT_VERSION = '0.1.0';
21
- async function nodePackageRelease(githubToken) {
22
+ async function nodePackageRelease({ githubToken, directory, releaseType, prerelease, updateShorthandRelease, skipIfNoDiff, diffTargets, dryRun, }) {
22
23
  const octokit = (0, getOctokit_1.getOctokit)(githubToken);
23
- await (0, configGit_1.configGit)(octokit);
24
+ await (0, config_git_with_token_action_1.configGitWithToken)({ githubToken });
25
+ await (0, configGit_1.configGit)();
24
26
  (0, core_1.startGroup)('Fetch every git tag');
25
27
  await (0, fetchEverything_1.fetchEverything)();
26
28
  (0, core_1.endGroup)();
@@ -29,7 +31,7 @@ async function nodePackageRelease(githubToken) {
29
31
  (0, core_1.notice)(`Last git tag: ${lastGitTag}`);
30
32
  (0, core_1.endGroup)();
31
33
  (0, core_1.startGroup)('Get package.json version');
32
- const packageVersion = (0, getPackageVersion_1.getPackageVersion)();
34
+ const packageVersion = (0, getPackageVersion_1.getPackageVersion)(directory);
33
35
  (0, core_1.notice)(`package.json version: ${packageVersion}`);
34
36
  (0, core_1.endGroup)();
35
37
  (0, core_1.startGroup)('Get latest release tag');
@@ -41,22 +43,17 @@ async function nodePackageRelease(githubToken) {
41
43
  const sortedVersions = (0, semver_1.rsort)(versions);
42
44
  const highestVersion = sortedVersions.length === 0 ? DEFAULT_VERSION : sortedVersions[0];
43
45
  (0, core_1.notice)(`Highest version: ${highestVersion}`);
44
- const releaseType = ReleaseType_1.RELEASE_TYPES.find((releaseType) => (0, core_1.getInput)('release-type').toLowerCase() === releaseType);
45
- if (releaseType === undefined) {
46
- (0, core_1.setFailed)(`Invalid release-type input: ${(0, core_1.getInput)('release-type')}`);
47
- return;
48
- }
49
46
  const releaseVersion = (0, semver_1.inc)(highestVersion, releaseType);
50
47
  if (releaseVersion === null) {
51
48
  (0, core_1.setFailed)('Failed to compute release version');
52
49
  return;
53
50
  }
54
51
  (0, core_1.notice)(`Release version: ${releaseVersion}`);
55
- if ((0, core_1.getBooleanInput)('skip-if-no-diff')) {
52
+ if (skipIfNoDiff) {
56
53
  const lastSameReleaseTypeVersion = await (0, findLastSameReleaseTypeVersion_1.findLastSameReleaseTypeVersion)(releaseVersion, releaseType);
57
54
  (0, core_1.notice)(`Last same release type version: ${lastSameReleaseTypeVersion}`);
58
55
  if (lastSameReleaseTypeVersion !== null) {
59
- const diff = await (0, checkDiff_1.checkDiff)(lastSameReleaseTypeVersion);
56
+ const diff = await (0, checkDiff_1.checkDiff)(lastSameReleaseTypeVersion, directory, diffTargets);
60
57
  if (!diff) {
61
58
  (0, core_1.notice)(`Skip due to lack of diff between HEAD..${lastSameReleaseTypeVersion}`);
62
59
  (0, core_1.setOutput)('skipped', true);
@@ -66,16 +63,29 @@ async function nodePackageRelease(githubToken) {
66
63
  (0, core_1.setOutput)('skipped', false);
67
64
  }
68
65
  (0, core_1.setOutput)('tag', `v${releaseVersion}`);
69
- await (0, setVersion_1.setVersion)(releaseVersion);
70
- await (0, pushBranch_1.pushBranch)();
71
- const release = await (0, createRelease_1.createRelease)(owner, repo, releaseVersion, octokit);
72
- if ((0, core_1.getBooleanInput)('update-shorthand-release')) {
73
- await (0, updateTags_1.updateTags)(releaseVersion);
66
+ await (0, setVersion_1.setVersion)(releaseVersion, directory);
67
+ await (0, pushBranch_1.pushBranch)(dryRun);
68
+ const release = await (0, createRelease_1.createRelease)(owner, repo, releaseVersion, prerelease, dryRun, octokit);
69
+ if (updateShorthandRelease) {
70
+ await (0, updateTags_1.updateTags)(releaseVersion, dryRun);
74
71
  }
75
72
  return release;
76
73
  }
77
74
  async function run() {
78
- const githubToken = (0, core_1.getInput)('github-token');
79
- await nodePackageRelease(githubToken);
75
+ const releaseType = ReleaseType_1.RELEASE_TYPES.find((releaseType) => (0, core_1.getInput)('release-type').toLowerCase() === releaseType);
76
+ if (releaseType === undefined) {
77
+ (0, core_1.setFailed)(`Invalid release-type input: ${(0, core_1.getInput)('release-type')}`);
78
+ return;
79
+ }
80
+ await nodePackageRelease({
81
+ githubToken: (0, core_1.getInput)('github-token'),
82
+ directory: (0, core_1.getInput)('directory'),
83
+ releaseType,
84
+ prerelease: (0, core_1.getBooleanInput)('prerelease'),
85
+ updateShorthandRelease: (0, core_1.getBooleanInput)('update-shorthand-release'),
86
+ skipIfNoDiff: (0, core_1.getBooleanInput)('skip-if-no-diff'),
87
+ diffTargets: (0, core_1.getInput)('diff-targets'),
88
+ dryRun: (0, core_1.getBooleanInput)('dry-run'),
89
+ });
80
90
  }
81
91
  run().catch((error) => (0, core_1.setFailed)(error));
@@ -1 +1 @@
1
- export declare function pushBranch(): Promise<void>;
1
+ export declare function pushBranch(dryRun: boolean): Promise<void>;
@@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pushBranch = pushBranch;
4
4
  const core_1 = require("@actions/core");
5
5
  const exec_1 = require("@actions/exec");
6
- async function pushBranch() {
7
- const dryRun = (0, core_1.getBooleanInput)('dry-run');
6
+ async function pushBranch(dryRun) {
8
7
  const gitBranchOutput = await (0, exec_1.getExecOutput)('git', [
9
8
  'branch',
10
9
  '--show-current',
@@ -1,2 +1,2 @@
1
1
  export declare const DEFAULT_WORKING_DIRECTORY: string;
2
- export declare function setVersion(version: string): Promise<void>;
2
+ export declare function setVersion(version: string, directory: string): Promise<void>;
@@ -7,8 +7,7 @@ const node_path_1 = require("node:path");
7
7
  const core_1 = require("@actions/core");
8
8
  const exec_1 = require("@actions/exec");
9
9
  exports.DEFAULT_WORKING_DIRECTORY = process.cwd();
10
- async function setVersion(version) {
11
- const directory = (0, core_1.getInput)('directory');
10
+ async function setVersion(version, directory) {
12
11
  const absoluteDirectory = (0, node_path_1.resolve)(exports.DEFAULT_WORKING_DIRECTORY, directory);
13
12
  const packageJsonPath = (0, node_path_1.resolve)(absoluteDirectory, 'package.json');
14
13
  if ((0, node_fs_1.existsSync)(packageJsonPath)) {
@@ -1 +1 @@
1
- export declare function updateTags(version: string): Promise<void>;
1
+ export declare function updateTags(version: string, dryRun: boolean): Promise<void>;
@@ -4,9 +4,8 @@ exports.updateTags = updateTags;
4
4
  const core_1 = require("@actions/core");
5
5
  const exec_1 = require("@actions/exec");
6
6
  const semver_1 = require("semver");
7
- async function updateTags(version) {
7
+ async function updateTags(version, dryRun) {
8
8
  const semver = (0, semver_1.parse)(version);
9
- const dryRun = (0, core_1.getBooleanInput)('dry-run');
10
9
  if (semver === null) {
11
10
  throw new Error(`Failed to parse the version as semver: ${version}`);
12
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-package-release-action",
3
- "version": "2.1.21",
3
+ "version": "2.3.0-0",
4
4
  "description": "A template to create custom GitHub Action with TypeScript/JavaScript.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.js",
@@ -30,7 +30,6 @@
30
30
  "@eslint/eslintrc": "^3.0.2",
31
31
  "@eslint/js": "^9.1.1",
32
32
  "@octokit/graphql-schema": "^15.1.2",
33
- "@octokit/webhooks-definitions": "^3.67.3",
34
33
  "@serverless-guru/prettier-plugin-import-order": "^0.4.1",
35
34
  "@types/glob": "^8.0.0",
36
35
  "@types/node": "^22.0.0",
@@ -55,6 +54,8 @@
55
54
  "@actions/github": "^6.0.0",
56
55
  "@octokit/plugin-retry": "^7.1.1",
57
56
  "@octokit/plugin-throttling": "^9.3.0",
57
+ "@octokit/webhooks-types": "^7.6.1",
58
+ "config-git-with-token-action": "^2.0.0",
58
59
  "glob": "^11.0.0",
59
60
  "semver": "^7.3.8"
60
61
  },