@jsenv/github-release-package 1.5.1 → 1.5.3
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/github-release-package",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.3",
|
|
4
4
|
"description": "Create github release when package version changes.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "https://github.com/jsenv/workflow",
|
|
14
|
-
"directory": "packages/
|
|
14
|
+
"directory": "packages/github-release-package"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">=16.13.0"
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"test": "node ./scripts/test.mjs"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@jsenv/filesystem": "4.
|
|
37
|
-
"@jsenv/log": "3.
|
|
38
|
-
"@jsenv/github-pull-request-impact": "1.7.
|
|
36
|
+
"@jsenv/filesystem": "4.3.2",
|
|
37
|
+
"@jsenv/log": "3.4.1",
|
|
38
|
+
"@jsenv/github-pull-request-impact": "1.7.3"
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
|
|
2
|
-
import { createLogger } from "@jsenv/log"
|
|
3
|
-
import * as githubRESTAPI from "@jsenv/github-pull-request-impact/src/internal/github_rest_api.js"
|
|
1
|
+
import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem";
|
|
2
|
+
import { createLogger } from "@jsenv/log";
|
|
3
|
+
import * as githubRESTAPI from "@jsenv/github-pull-request-impact/src/internal/github_rest_api.js";
|
|
4
4
|
|
|
5
|
-
import { readProjectPackage } from "./internal/readProjectPackage.js"
|
|
5
|
+
import { readProjectPackage } from "./internal/readProjectPackage.js";
|
|
6
6
|
|
|
7
7
|
export const ensureGithubReleaseForPackage = async ({
|
|
8
8
|
logLevel,
|
|
9
9
|
rootDirectoryUrl,
|
|
10
10
|
}) => {
|
|
11
|
-
const logger = createLogger({ logLevel })
|
|
11
|
+
const logger = createLogger({ logLevel });
|
|
12
12
|
logger.debug(
|
|
13
13
|
`autoReleaseOnGithub(${JSON.stringify(
|
|
14
14
|
{ rootDirectoryUrl, logLevel },
|
|
15
15
|
null,
|
|
16
16
|
" ",
|
|
17
17
|
)})`,
|
|
18
|
-
)
|
|
18
|
+
);
|
|
19
19
|
|
|
20
|
-
rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
|
|
20
|
+
rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl);
|
|
21
21
|
|
|
22
22
|
const {
|
|
23
23
|
githubToken,
|
|
24
24
|
githubRepositoryOwner,
|
|
25
25
|
githubRepositoryName,
|
|
26
26
|
githubSha,
|
|
27
|
-
} = getOptionsFromGithubAction()
|
|
27
|
+
} = getOptionsFromGithubAction();
|
|
28
28
|
|
|
29
|
-
logger.debug(`reading project package.json`)
|
|
30
|
-
const projectPackage = readProjectPackage({ rootDirectoryUrl })
|
|
31
|
-
const packageVersion = projectPackage.version
|
|
32
|
-
logger.debug(`${packageVersion} found in package.json`)
|
|
29
|
+
logger.debug(`reading project package.json`);
|
|
30
|
+
const projectPackage = readProjectPackage({ rootDirectoryUrl });
|
|
31
|
+
const packageVersion = projectPackage.version;
|
|
32
|
+
logger.debug(`${packageVersion} found in package.json`);
|
|
33
33
|
if (
|
|
34
34
|
packageVersion.includes("alpha") ||
|
|
35
35
|
packageVersion.includes("beta") ||
|
|
@@ -37,17 +37,17 @@ export const ensureGithubReleaseForPackage = async ({
|
|
|
37
37
|
) {
|
|
38
38
|
logger.info(
|
|
39
39
|
`skip because package version ("${packageVersion}") is a prerelease`,
|
|
40
|
-
)
|
|
41
|
-
return
|
|
40
|
+
);
|
|
41
|
+
return;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
logger.debug(`search release for ${packageVersion} on github`)
|
|
45
|
-
const githubReleaseName = `v${packageVersion}
|
|
44
|
+
logger.debug(`search release for ${packageVersion} on github`);
|
|
45
|
+
const githubReleaseName = `v${packageVersion}`;
|
|
46
46
|
// https://developer.github.com/v3/git/refs/#get-a-single-reference
|
|
47
47
|
const existingRelease = await githubRESTAPI.GET({
|
|
48
48
|
url: `https://api.github.com/repos/${githubRepositoryOwner}/${githubRepositoryName}/git/ref/tags/${githubReleaseName}`,
|
|
49
49
|
githubToken,
|
|
50
|
-
})
|
|
50
|
+
});
|
|
51
51
|
if (existingRelease) {
|
|
52
52
|
logger.info(
|
|
53
53
|
`${packageVersion} already released at ${generateReleaseUrl({
|
|
@@ -55,11 +55,11 @@ export const ensureGithubReleaseForPackage = async ({
|
|
|
55
55
|
githubRepositoryName,
|
|
56
56
|
githubReleaseName,
|
|
57
57
|
})}`,
|
|
58
|
-
)
|
|
59
|
-
return
|
|
58
|
+
);
|
|
59
|
+
return;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
logger.info(`creating release for ${packageVersion}`)
|
|
62
|
+
logger.info(`creating release for ${packageVersion}`);
|
|
63
63
|
// https://developer.github.com/v3/git/tags/
|
|
64
64
|
await githubRESTAPI.POST({
|
|
65
65
|
url: `https://api.github.com/repos/${githubRepositoryOwner}/${githubRepositoryName}/git/refs`,
|
|
@@ -68,54 +68,54 @@ export const ensureGithubReleaseForPackage = async ({
|
|
|
68
68
|
ref: `refs/tags/${githubReleaseName}`,
|
|
69
69
|
sha: githubSha,
|
|
70
70
|
},
|
|
71
|
-
})
|
|
71
|
+
});
|
|
72
72
|
logger.info(
|
|
73
73
|
`release created at ${generateReleaseUrl({
|
|
74
74
|
githubRepositoryOwner,
|
|
75
75
|
githubRepositoryName,
|
|
76
76
|
githubReleaseName,
|
|
77
77
|
})}`,
|
|
78
|
-
)
|
|
79
|
-
}
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
80
|
|
|
81
81
|
const generateReleaseUrl = ({
|
|
82
82
|
githubRepositoryOwner,
|
|
83
83
|
githubRepositoryName,
|
|
84
84
|
githubReleaseName,
|
|
85
85
|
}) => {
|
|
86
|
-
return `https://github.com/${githubRepositoryOwner}/${githubRepositoryName}/releases/tag/${githubReleaseName}
|
|
87
|
-
}
|
|
86
|
+
return `https://github.com/${githubRepositoryOwner}/${githubRepositoryName}/releases/tag/${githubReleaseName}`;
|
|
87
|
+
};
|
|
88
88
|
|
|
89
89
|
const getOptionsFromGithubAction = () => {
|
|
90
|
-
const eventName = process.env.GITHUB_EVENT_NAME
|
|
90
|
+
const eventName = process.env.GITHUB_EVENT_NAME;
|
|
91
91
|
if (!eventName) {
|
|
92
92
|
throw new Error(
|
|
93
93
|
`missing process.env.GITHUB_EVENT_NAME, we are not in a github action`,
|
|
94
|
-
)
|
|
94
|
+
);
|
|
95
95
|
}
|
|
96
96
|
if (eventName !== "push") {
|
|
97
97
|
throw new Error(
|
|
98
98
|
`getOptionsFromGithubAction must be called only in a push action`,
|
|
99
|
-
)
|
|
99
|
+
);
|
|
100
100
|
}
|
|
101
|
-
const githubRepository = process.env.GITHUB_REPOSITORY
|
|
101
|
+
const githubRepository = process.env.GITHUB_REPOSITORY;
|
|
102
102
|
if (!githubRepository) {
|
|
103
|
-
throw new Error(`missing process.env.GITHUB_REPOSITORY`)
|
|
103
|
+
throw new Error(`missing process.env.GITHUB_REPOSITORY`);
|
|
104
104
|
}
|
|
105
105
|
const [githubRepositoryOwner, githubRepositoryName] =
|
|
106
|
-
githubRepository.split("/")
|
|
107
|
-
const githubToken = process.env.GITHUB_TOKEN
|
|
106
|
+
githubRepository.split("/");
|
|
107
|
+
const githubToken = process.env.GITHUB_TOKEN;
|
|
108
108
|
if (!githubToken) {
|
|
109
|
-
throw new Error(`missing process.env.GITHUB_TOKEN`)
|
|
109
|
+
throw new Error(`missing process.env.GITHUB_TOKEN`);
|
|
110
110
|
}
|
|
111
|
-
const githubSha = process.env.GITHUB_SHA
|
|
111
|
+
const githubSha = process.env.GITHUB_SHA;
|
|
112
112
|
if (!githubSha) {
|
|
113
|
-
throw new Error(`missing process.env.GITHUB_SHA`)
|
|
113
|
+
throw new Error(`missing process.env.GITHUB_SHA`);
|
|
114
114
|
}
|
|
115
115
|
return {
|
|
116
116
|
githubRepositoryOwner,
|
|
117
117
|
githubRepositoryName,
|
|
118
118
|
githubToken,
|
|
119
119
|
githubSha,
|
|
120
|
-
}
|
|
121
|
-
}
|
|
120
|
+
};
|
|
121
|
+
};
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { fileURLToPath } from "node:url"
|
|
2
|
-
import { readFileSync } from "node:fs"
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
3
|
|
|
4
4
|
export const readProjectPackage = ({ rootDirectoryUrl }) => {
|
|
5
|
-
const packageFileUrlObject = new URL("./package.json", rootDirectoryUrl)
|
|
6
|
-
let packageInProject
|
|
5
|
+
const packageFileUrlObject = new URL("./package.json", rootDirectoryUrl);
|
|
6
|
+
let packageInProject;
|
|
7
7
|
try {
|
|
8
|
-
const packageString = String(readFileSync(packageFileUrlObject))
|
|
8
|
+
const packageString = String(readFileSync(packageFileUrlObject));
|
|
9
9
|
try {
|
|
10
|
-
packageInProject = JSON.parse(packageString)
|
|
10
|
+
packageInProject = JSON.parse(packageString);
|
|
11
11
|
} catch (e) {
|
|
12
12
|
if (e.name === "SyntaxError") {
|
|
13
13
|
throw new Error(`syntax error while parsing project package.json
|
|
14
14
|
--- syntax error stack ---
|
|
15
15
|
${e.stack}
|
|
16
16
|
--- package.json path ---
|
|
17
|
-
${fileURLToPath(packageFileUrlObject)}`)
|
|
17
|
+
${fileURLToPath(packageFileUrlObject)}`);
|
|
18
18
|
}
|
|
19
|
-
throw e
|
|
19
|
+
throw e;
|
|
20
20
|
}
|
|
21
21
|
} catch (e) {
|
|
22
22
|
if (e.code === "ENOENT") {
|
|
@@ -24,9 +24,9 @@ ${fileURLToPath(packageFileUrlObject)}`)
|
|
|
24
24
|
`cannot find project package.json
|
|
25
25
|
--- package.json path ---
|
|
26
26
|
${fileURLToPath(packageFileUrlObject)}`,
|
|
27
|
-
)
|
|
27
|
+
);
|
|
28
28
|
}
|
|
29
|
-
throw e
|
|
29
|
+
throw e;
|
|
30
30
|
}
|
|
31
|
-
return packageInProject
|
|
32
|
-
}
|
|
31
|
+
return packageInProject;
|
|
32
|
+
};
|
package/src/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ensureGithubReleaseForPackage } from "./ensureGithubReleaseForPackage.js"
|
|
1
|
+
export { ensureGithubReleaseForPackage } from "./ensureGithubReleaseForPackage.js";
|