@jsenv/github-release-package 1.2.0 → 1.3.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/{license → LICENSE} +0 -0
- package/README.md +3 -0
- package/{index.js → main.js} +0 -0
- package/package.json +29 -43
- package/src/ensureGithubReleaseForPackage.js +64 -64
- package/src/internal/createGithubRelease.js +0 -3
- package/src/internal/getGithubRelease.js +0 -4
- package/src/internal/readProjectPackage.js +1 -3
- package/dist/commonjs/main.cjs +0 -1415
- package/dist/commonjs/main.cjs.map +0 -1
- package/readme.md +0 -26
- package/src/internal/wrapAsyncFunction.js +0 -21
package/{license → LICENSE}
RENAMED
|
File without changes
|
package/README.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
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.
|
package/{index.js → main.js}
RENAMED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/github-release-package",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Create github release when package version changes.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "dmail",
|
|
8
|
+
"email": "dmaillard06@gmail.com",
|
|
9
|
+
"url": "https://twitter.com/damienmaillard"
|
|
10
|
+
},
|
|
6
11
|
"repository": {
|
|
7
12
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/jsenv/
|
|
13
|
+
"url": "https://github.com/jsenv/github-release-package"
|
|
9
14
|
},
|
|
10
15
|
"engines": {
|
|
11
|
-
"node": ">=
|
|
16
|
+
"node": ">=16.13.0"
|
|
12
17
|
},
|
|
13
18
|
"publishConfig": {
|
|
14
19
|
"access": "public",
|
|
@@ -17,55 +22,36 @@
|
|
|
17
22
|
"type": "module",
|
|
18
23
|
"exports": {
|
|
19
24
|
".": {
|
|
20
|
-
"import": "./
|
|
21
|
-
"require": "./dist/commonjs/main.cjs"
|
|
25
|
+
"import": "./main.js"
|
|
22
26
|
}
|
|
23
27
|
},
|
|
24
|
-
"main": "
|
|
28
|
+
"main": "./main.js",
|
|
25
29
|
"files": [
|
|
26
|
-
"/dist/",
|
|
27
30
|
"/src/",
|
|
28
|
-
"/
|
|
31
|
+
"/main.js"
|
|
29
32
|
],
|
|
30
33
|
"scripts": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"prettier
|
|
36
|
-
"prettier-check": "npm run prettier-format -- --dry-run",
|
|
37
|
-
"upload-coverage": "node ./script/upload-coverage/upload-coverage.js",
|
|
38
|
-
"generate-commonjs-bundle": "node ./script/generate-commonjs-bundle/generate-commonjs-bundle.js",
|
|
39
|
-
"generate-import-map": "node ./script/generate-import-map/generate-import-map.js",
|
|
40
|
-
"install-git-hooks": "node ./script/install-git-hooks/install-git-hooks.js",
|
|
41
|
-
"dist": "npm run clean && npm run generate-commonjs-bundle",
|
|
42
|
-
"clean": "rimraf dist && rimraf coverage",
|
|
43
|
-
"reinstall": "npm run clean && rimraf node_modules && npm install",
|
|
44
|
-
"prepublishOnly": "node ./script/transform-package/remove-postinstall.js && npm run dist",
|
|
45
|
-
"postpublish": "node ./script/transform-package/restore-postinstall.js",
|
|
46
|
-
"git-hook-pre-commit": "npm run prettier-format-stage"
|
|
34
|
+
"eslint": "node ./node_modules/eslint/bin/eslint.js . --ext=.js,.mjs",
|
|
35
|
+
"importmap": "node ./script/importmap/importmap.mjs",
|
|
36
|
+
"test": "node ./script/test/test.mjs",
|
|
37
|
+
"test-with-coverage": "npm run test -- --coverage",
|
|
38
|
+
"prettier": "prettier --write ."
|
|
47
39
|
},
|
|
48
40
|
"dependencies": {
|
|
49
|
-
"@jsenv/
|
|
50
|
-
"@jsenv/logger": "
|
|
51
|
-
"@jsenv/server": "
|
|
52
|
-
"@jsenv/util": "3.4.1",
|
|
53
|
-
"node-fetch": "2.6.0"
|
|
41
|
+
"@jsenv/filesystem": "2.7.1",
|
|
42
|
+
"@jsenv/logger": "4.0.1",
|
|
43
|
+
"@jsenv/server": "12.4.0"
|
|
54
44
|
},
|
|
55
45
|
"devDependencies": {
|
|
56
|
-
"@jsenv/assert": "
|
|
57
|
-
"@jsenv/
|
|
58
|
-
"@jsenv/
|
|
59
|
-
"@jsenv/eslint-
|
|
60
|
-
"@jsenv/
|
|
61
|
-
"@jsenv/
|
|
62
|
-
"@jsenv/
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"babel-eslint": "11.0.0-beta.0",
|
|
67
|
-
"eslint": "6.8.0",
|
|
68
|
-
"prettier": "1.19.1",
|
|
69
|
-
"rimraf": "3.0.1"
|
|
46
|
+
"@jsenv/assert": "2.4.1",
|
|
47
|
+
"@jsenv/core": "25.3.0",
|
|
48
|
+
"@jsenv/eslint-config": "16.0.9",
|
|
49
|
+
"@jsenv/importmap-eslint-resolver": "5.2.5",
|
|
50
|
+
"@jsenv/importmap-node-module": "5.1.0",
|
|
51
|
+
"@jsenv/package-publish": "1.6.2",
|
|
52
|
+
"@jsenv/performance-impact": "2.2.1",
|
|
53
|
+
"eslint": "8.7.0",
|
|
54
|
+
"eslint-plugin-import": "2.25.4",
|
|
55
|
+
"prettier": "2.5.1"
|
|
70
56
|
}
|
|
71
57
|
}
|
|
@@ -1,108 +1,108 @@
|
|
|
1
|
+
import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
|
|
1
2
|
import { createLogger } from "@jsenv/logger"
|
|
2
|
-
|
|
3
|
-
import { createCancellationTokenForProcessSIGINT } from "@jsenv/cancellation"
|
|
4
|
-
import { wrapAsyncFunction } from "./internal/wrapAsyncFunction.js"
|
|
3
|
+
|
|
5
4
|
import { readProjectPackage } from "./internal/readProjectPackage.js"
|
|
6
5
|
import { getGithubRelease } from "./internal/getGithubRelease.js"
|
|
7
6
|
import { createGithubRelease } from "./internal/createGithubRelease.js"
|
|
8
7
|
|
|
9
8
|
export const ensureGithubReleaseForPackage = async ({
|
|
10
|
-
cancellationToken = createCancellationTokenForProcessSIGINT(),
|
|
11
9
|
logLevel,
|
|
12
10
|
projectDirectoryUrl,
|
|
13
|
-
updateProcessExitCode,
|
|
14
11
|
}) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
const logger = createLogger({ logLevel })
|
|
13
|
+
logger.debug(
|
|
14
|
+
`autoReleaseOnGithub(${JSON.stringify(
|
|
15
|
+
{ projectDirectoryUrl, logLevel },
|
|
16
|
+
null,
|
|
17
|
+
" ",
|
|
18
|
+
)})`,
|
|
19
|
+
)
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
const {
|
|
24
|
+
githubToken,
|
|
25
|
+
githubRepositoryOwner,
|
|
26
|
+
githubRepositoryName,
|
|
27
|
+
githubSha,
|
|
28
|
+
} = getOptionsFromGithubAction()
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
logger.debug(`reading project package.json`)
|
|
31
|
+
const { packageVersion } = await getOptionsFromProjectPackage({
|
|
32
|
+
projectDirectoryUrl,
|
|
33
|
+
})
|
|
34
|
+
logger.debug(`${packageVersion} found in package.json`)
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
logger.debug(`search release for ${packageVersion} on github`)
|
|
37
|
+
const githubReleaseName = `v${packageVersion}`
|
|
38
|
+
const existingRelease = await getGithubRelease({
|
|
39
|
+
githubToken,
|
|
40
|
+
githubRepositoryOwner,
|
|
41
|
+
githubRepositoryName,
|
|
42
|
+
githubReleaseName,
|
|
43
|
+
})
|
|
44
|
+
if (existingRelease) {
|
|
45
|
+
logger.info(
|
|
46
|
+
`${packageVersion} already released at ${generateReleaseUrl({
|
|
40
47
|
githubRepositoryOwner,
|
|
41
48
|
githubRepositoryName,
|
|
42
49
|
githubReleaseName,
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
`${packageVersion} already released at ${generateReleaseUrl({
|
|
48
|
-
githubRepositoryOwner,
|
|
49
|
-
githubRepositoryName,
|
|
50
|
-
githubReleaseName,
|
|
51
|
-
})}`,
|
|
52
|
-
)
|
|
53
|
-
return
|
|
54
|
-
}
|
|
50
|
+
})}`,
|
|
51
|
+
)
|
|
52
|
+
return
|
|
53
|
+
}
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
)
|
|
71
|
-
},
|
|
72
|
-
{ updateProcessExitCode },
|
|
55
|
+
logger.info(`creating release for ${packageVersion}`)
|
|
56
|
+
await createGithubRelease({
|
|
57
|
+
githubToken,
|
|
58
|
+
githubRepositoryOwner,
|
|
59
|
+
githubRepositoryName,
|
|
60
|
+
githubSha,
|
|
61
|
+
githubReleaseName,
|
|
62
|
+
})
|
|
63
|
+
logger.info(
|
|
64
|
+
`release created at ${generateReleaseUrl({
|
|
65
|
+
githubRepositoryOwner,
|
|
66
|
+
githubRepositoryName,
|
|
67
|
+
githubReleaseName,
|
|
68
|
+
})}`,
|
|
73
69
|
)
|
|
74
70
|
}
|
|
75
71
|
|
|
76
|
-
const generateReleaseUrl = ({
|
|
72
|
+
const generateReleaseUrl = ({
|
|
73
|
+
githubRepositoryOwner,
|
|
74
|
+
githubRepositoryName,
|
|
75
|
+
githubReleaseName,
|
|
76
|
+
}) => {
|
|
77
77
|
return `https://github.com/${githubRepositoryOwner}/${githubRepositoryName}/releases/tag/${githubReleaseName}`
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
const getOptionsFromGithubAction = () => {
|
|
81
81
|
const eventName = process.env.GITHUB_EVENT_NAME
|
|
82
82
|
if (!eventName) {
|
|
83
|
-
throw new Error(
|
|
83
|
+
throw new Error(
|
|
84
|
+
`missing process.env.GITHUB_EVENT_NAME, we are not in a github action`,
|
|
85
|
+
)
|
|
84
86
|
}
|
|
85
87
|
if (eventName !== "push") {
|
|
86
|
-
throw new Error(
|
|
88
|
+
throw new Error(
|
|
89
|
+
`getOptionsFromGithubAction must be called only in a push action`,
|
|
90
|
+
)
|
|
87
91
|
}
|
|
88
|
-
|
|
89
92
|
const githubRepository = process.env.GITHUB_REPOSITORY
|
|
90
93
|
if (!githubRepository) {
|
|
91
94
|
throw new Error(`missing process.env.GITHUB_REPOSITORY`)
|
|
92
95
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
const [githubRepositoryOwner, githubRepositoryName] =
|
|
97
|
+
githubRepository.split("/")
|
|
96
98
|
const githubToken = process.env.GITHUB_TOKEN
|
|
97
99
|
if (!githubToken) {
|
|
98
100
|
throw new Error(`missing process.env.GITHUB_TOKEN`)
|
|
99
101
|
}
|
|
100
|
-
|
|
101
102
|
const githubSha = process.env.GITHUB_SHA
|
|
102
103
|
if (!githubSha) {
|
|
103
104
|
throw new Error(`missing process.env.GITHUB_SHA`)
|
|
104
105
|
}
|
|
105
|
-
|
|
106
106
|
return {
|
|
107
107
|
githubRepositoryOwner,
|
|
108
108
|
githubRepositoryName,
|
|
@@ -22,9 +22,7 @@ export const createGithubRelease = async ({
|
|
|
22
22
|
method: "POST",
|
|
23
23
|
body,
|
|
24
24
|
})
|
|
25
|
-
|
|
26
25
|
const responseStatus = response.status
|
|
27
|
-
|
|
28
26
|
if (responseStatus !== 201) {
|
|
29
27
|
throw new Error(
|
|
30
28
|
writeUnexpectedResponseStatus({
|
|
@@ -34,7 +32,6 @@ export const createGithubRelease = async ({
|
|
|
34
32
|
}),
|
|
35
33
|
)
|
|
36
34
|
}
|
|
37
|
-
|
|
38
35
|
const responseJson = await response.json()
|
|
39
36
|
return responseJson
|
|
40
37
|
}
|
|
@@ -15,13 +15,10 @@ export const getGithubRelease = async ({
|
|
|
15
15
|
},
|
|
16
16
|
method: "GET",
|
|
17
17
|
})
|
|
18
|
-
|
|
19
18
|
const responseStatus = response.status
|
|
20
|
-
|
|
21
19
|
if (responseStatus === 404) {
|
|
22
20
|
return null
|
|
23
21
|
}
|
|
24
|
-
|
|
25
22
|
if (responseStatus !== 200) {
|
|
26
23
|
throw new Error(
|
|
27
24
|
writeUnexpectedResponseStatus({
|
|
@@ -31,7 +28,6 @@ export const getGithubRelease = async ({
|
|
|
31
28
|
}),
|
|
32
29
|
)
|
|
33
30
|
}
|
|
34
|
-
|
|
35
31
|
const responseJson = await response.json()
|
|
36
32
|
return responseJson
|
|
37
33
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { resolveUrl, urlToFileSystemPath, readFile } from "@jsenv/
|
|
1
|
+
import { resolveUrl, urlToFileSystemPath, readFile } from "@jsenv/filesystem"
|
|
2
2
|
|
|
3
3
|
export const readProjectPackage = async ({ projectDirectoryUrl }) => {
|
|
4
4
|
const packageFileUrl = resolveUrl("./package.json", projectDirectoryUrl)
|
|
5
|
-
|
|
6
5
|
let packageInProject
|
|
7
6
|
try {
|
|
8
7
|
const packageString = await readFile(packageFileUrl)
|
|
@@ -28,6 +27,5 @@ ${urlToFileSystemPath(packageFileUrl)}`,
|
|
|
28
27
|
}
|
|
29
28
|
throw e
|
|
30
29
|
}
|
|
31
|
-
|
|
32
30
|
return packageInProject
|
|
33
31
|
}
|