@jsenv/github-release-package 1.3.0 → 1.3.1
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/{LICENSE → license} +0 -0
- package/package.json +6 -7
- package/readme.md +3 -0
- package/src/ensureGithubReleaseForPackage.js +11 -11
- package/README.md +0 -3
- package/src/internal/createGithubRelease.js +0 -49
- package/src/internal/getGithubRelease.js +0 -45
package/{LICENSE → license}
RENAMED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/github-release-package",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Create github release when package version changes.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/jsenv/
|
|
13
|
+
"url": "https://github.com/jsenv/workflow",
|
|
14
|
+
"directory": "packages/jsenv-github-release-package"
|
|
14
15
|
},
|
|
15
16
|
"engines": {
|
|
16
17
|
"node": ">=16.13.0"
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
"/main.js"
|
|
32
33
|
],
|
|
33
34
|
"scripts": {
|
|
34
|
-
"eslint": "
|
|
35
|
+
"eslint": "npx eslint . --ext=.js,.mjs",
|
|
35
36
|
"importmap": "node ./script/importmap/importmap.mjs",
|
|
36
37
|
"test": "node ./script/test/test.mjs",
|
|
37
38
|
"test-with-coverage": "npm run test -- --coverage",
|
|
@@ -40,16 +41,14 @@
|
|
|
40
41
|
"dependencies": {
|
|
41
42
|
"@jsenv/filesystem": "2.7.1",
|
|
42
43
|
"@jsenv/logger": "4.0.1",
|
|
43
|
-
"@jsenv/
|
|
44
|
+
"@jsenv/github-pull-request-impact": "1.6.6"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@jsenv/assert": "2.4.1",
|
|
47
48
|
"@jsenv/core": "25.3.0",
|
|
48
49
|
"@jsenv/eslint-config": "16.0.9",
|
|
49
50
|
"@jsenv/importmap-eslint-resolver": "5.2.5",
|
|
50
|
-
"@jsenv/importmap-node-module": "5.1.
|
|
51
|
-
"@jsenv/package-publish": "1.6.2",
|
|
52
|
-
"@jsenv/performance-impact": "2.2.1",
|
|
51
|
+
"@jsenv/importmap-node-module": "5.1.3",
|
|
53
52
|
"eslint": "8.7.0",
|
|
54
53
|
"eslint-plugin-import": "2.25.4",
|
|
55
54
|
"prettier": "2.5.1"
|
package/readme.md
ADDED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import * as githubRESTAPI from "@jsenv/github-pull-request-impact/src/internal/github_rest_api.js"
|
|
1
2
|
import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
|
|
2
3
|
import { createLogger } from "@jsenv/logger"
|
|
3
4
|
|
|
4
5
|
import { readProjectPackage } from "./internal/readProjectPackage.js"
|
|
5
|
-
import { getGithubRelease } from "./internal/getGithubRelease.js"
|
|
6
|
-
import { createGithubRelease } from "./internal/createGithubRelease.js"
|
|
7
6
|
|
|
8
7
|
export const ensureGithubReleaseForPackage = async ({
|
|
9
8
|
logLevel,
|
|
@@ -35,11 +34,10 @@ export const ensureGithubReleaseForPackage = async ({
|
|
|
35
34
|
|
|
36
35
|
logger.debug(`search release for ${packageVersion} on github`)
|
|
37
36
|
const githubReleaseName = `v${packageVersion}`
|
|
38
|
-
|
|
37
|
+
// https://developer.github.com/v3/git/refs/#get-a-single-reference
|
|
38
|
+
const existingRelease = await githubRESTAPI.GET({
|
|
39
|
+
url: `https://api.github.com/repos/${githubRepositoryOwner}/${githubRepositoryName}/git/ref/tags/${githubReleaseName}`,
|
|
39
40
|
githubToken,
|
|
40
|
-
githubRepositoryOwner,
|
|
41
|
-
githubRepositoryName,
|
|
42
|
-
githubReleaseName,
|
|
43
41
|
})
|
|
44
42
|
if (existingRelease) {
|
|
45
43
|
logger.info(
|
|
@@ -53,12 +51,14 @@ export const ensureGithubReleaseForPackage = async ({
|
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
logger.info(`creating release for ${packageVersion}`)
|
|
56
|
-
|
|
54
|
+
// https://developer.github.com/v3/git/tags/
|
|
55
|
+
await githubRESTAPI.POST({
|
|
56
|
+
url: `https://api.github.com/repos/${githubRepositoryOwner}/${githubRepositoryName}/git/refs`,
|
|
57
57
|
githubToken,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
body: {
|
|
59
|
+
ref: `refs/tags/${githubReleaseName}`,
|
|
60
|
+
sha: githubSha,
|
|
61
|
+
},
|
|
62
62
|
})
|
|
63
63
|
logger.info(
|
|
64
64
|
`release created at ${generateReleaseUrl({
|
package/README.md
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
# Github Release Package [](https://www.npmjs.com/package/@jsenv/github-release-package) [](https://github.com/jsenv/github-release-package/actions?workflow=main) [](https://codecov.io/gh/jsenv/github-release-package)
|
|
2
|
-
|
|
3
|
-
Create github release for package version updates.
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// https://developer.github.com/v3/git/tags/
|
|
2
|
-
|
|
3
|
-
import { fetchUrl } from "@jsenv/server"
|
|
4
|
-
|
|
5
|
-
export const createGithubRelease = async ({
|
|
6
|
-
githubToken,
|
|
7
|
-
githubRepositoryOwner,
|
|
8
|
-
githubRepositoryName,
|
|
9
|
-
githubSha,
|
|
10
|
-
githubReleaseName,
|
|
11
|
-
}) => {
|
|
12
|
-
const requestUrl = `https://api.github.com/repos/${githubRepositoryOwner}/${githubRepositoryName}/git/refs`
|
|
13
|
-
const body = JSON.stringify({
|
|
14
|
-
ref: `refs/tags/${githubReleaseName}`,
|
|
15
|
-
sha: githubSha,
|
|
16
|
-
})
|
|
17
|
-
const response = await fetchUrl(requestUrl, {
|
|
18
|
-
headers: {
|
|
19
|
-
"authorization": `token ${githubToken}`,
|
|
20
|
-
"content-length": Buffer.byteLength(body),
|
|
21
|
-
},
|
|
22
|
-
method: "POST",
|
|
23
|
-
body,
|
|
24
|
-
})
|
|
25
|
-
const responseStatus = response.status
|
|
26
|
-
if (responseStatus !== 201) {
|
|
27
|
-
throw new Error(
|
|
28
|
-
writeUnexpectedResponseStatus({
|
|
29
|
-
requestUrl,
|
|
30
|
-
responseStatus,
|
|
31
|
-
responseText: await response.text(),
|
|
32
|
-
}),
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
const responseJson = await response.json()
|
|
36
|
-
return responseJson
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const writeUnexpectedResponseStatus = ({
|
|
40
|
-
requestUrl,
|
|
41
|
-
responseStatus,
|
|
42
|
-
responseText,
|
|
43
|
-
}) => `github api response status should be 201.
|
|
44
|
-
--- request url ----
|
|
45
|
-
${requestUrl}
|
|
46
|
-
--- response status ---
|
|
47
|
-
${responseStatus}
|
|
48
|
-
--- response text ---
|
|
49
|
-
${responseText}`
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// https://developer.github.com/v3/git/refs/#get-a-single-reference
|
|
2
|
-
|
|
3
|
-
import { fetchUrl } from "@jsenv/server"
|
|
4
|
-
|
|
5
|
-
export const getGithubRelease = async ({
|
|
6
|
-
githubToken,
|
|
7
|
-
githubRepositoryOwner,
|
|
8
|
-
githubRepositoryName,
|
|
9
|
-
githubReleaseName,
|
|
10
|
-
}) => {
|
|
11
|
-
const requestUrl = `https://api.github.com/repos/${githubRepositoryOwner}/${githubRepositoryName}/git/ref/tags/${githubReleaseName}`
|
|
12
|
-
const response = await fetchUrl(requestUrl, {
|
|
13
|
-
headers: {
|
|
14
|
-
authorization: `token ${githubToken}`,
|
|
15
|
-
},
|
|
16
|
-
method: "GET",
|
|
17
|
-
})
|
|
18
|
-
const responseStatus = response.status
|
|
19
|
-
if (responseStatus === 404) {
|
|
20
|
-
return null
|
|
21
|
-
}
|
|
22
|
-
if (responseStatus !== 200) {
|
|
23
|
-
throw new Error(
|
|
24
|
-
writeUnexpectedResponseStatus({
|
|
25
|
-
requestUrl,
|
|
26
|
-
responseStatus,
|
|
27
|
-
responseText: await response.text(),
|
|
28
|
-
}),
|
|
29
|
-
)
|
|
30
|
-
}
|
|
31
|
-
const responseJson = await response.json()
|
|
32
|
-
return responseJson
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const writeUnexpectedResponseStatus = ({
|
|
36
|
-
requestUrl,
|
|
37
|
-
responseStatus,
|
|
38
|
-
responseText,
|
|
39
|
-
}) => `github api response status should be 200.
|
|
40
|
-
--- request url ----
|
|
41
|
-
${requestUrl}
|
|
42
|
-
--- response status ---
|
|
43
|
-
${responseStatus}
|
|
44
|
-
--- response text ---
|
|
45
|
-
${responseText}`
|