@jsenv/github-release-package 1.2.2 → 1.3.2
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/{index.js → main.js} +0 -0
- package/package.json +28 -38
- package/readme.md +1 -24
- package/src/ensureGithubReleaseForPackage.js +64 -68
- package/src/internal/readProjectPackage.js +1 -3
- package/dist/commonjs/main.cjs +0 -1531
- package/dist/commonjs/main.cjs.map +0 -1
- package/src/internal/createGithubRelease.js +0 -52
- package/src/internal/getGithubRelease.js +0 -49
package/{index.js → main.js}
RENAMED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/github-release-package",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.2",
|
|
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/workflow",
|
|
14
|
+
"directory": "packages/jsenv-github-release-package"
|
|
9
15
|
},
|
|
10
16
|
"engines": {
|
|
11
|
-
"node": ">=
|
|
17
|
+
"node": ">=16.13.0"
|
|
12
18
|
},
|
|
13
19
|
"publishConfig": {
|
|
14
20
|
"access": "public",
|
|
@@ -17,50 +23,34 @@
|
|
|
17
23
|
"type": "module",
|
|
18
24
|
"exports": {
|
|
19
25
|
".": {
|
|
20
|
-
"import": "./
|
|
21
|
-
"require": "./dist/commonjs/main.cjs"
|
|
26
|
+
"import": "./main.js"
|
|
22
27
|
}
|
|
23
28
|
},
|
|
24
|
-
"main": "
|
|
29
|
+
"main": "./main.js",
|
|
25
30
|
"files": [
|
|
26
|
-
"/dist/",
|
|
27
31
|
"/src/",
|
|
28
|
-
"/
|
|
32
|
+
"/main.js"
|
|
29
33
|
],
|
|
30
34
|
"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 generate-commonjs-bundle",
|
|
42
|
-
"prepublishOnly": "node ./script/transform-package/remove-postinstall.js && npm run dist",
|
|
43
|
-
"postpublish": "node ./script/transform-package/restore-postinstall.js",
|
|
44
|
-
"git-hook-pre-commit": "npm run prettier-format-stage"
|
|
35
|
+
"eslint": "npx eslint . --ext=.js,.mjs",
|
|
36
|
+
"importmap": "node ./script/importmap/importmap.mjs",
|
|
37
|
+
"test": "node ./script/test/test.mjs",
|
|
38
|
+
"test-with-coverage": "npm run test -- --coverage",
|
|
39
|
+
"prettier": "prettier --write ."
|
|
45
40
|
},
|
|
46
41
|
"dependencies": {
|
|
47
|
-
"@jsenv/
|
|
48
|
-
"@jsenv/
|
|
49
|
-
"@jsenv/
|
|
42
|
+
"@jsenv/filesystem": "2.7.1",
|
|
43
|
+
"@jsenv/logger": "4.0.1",
|
|
44
|
+
"@jsenv/github-pull-request-impact": "1.6.7"
|
|
50
45
|
},
|
|
51
46
|
"devDependencies": {
|
|
52
|
-
"@jsenv/assert": "2.
|
|
53
|
-
"@jsenv/
|
|
54
|
-
"@jsenv/
|
|
55
|
-
"@jsenv/eslint-
|
|
56
|
-
"@jsenv/
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"@jsenv/prettier-config": "1.2.0",
|
|
61
|
-
"@jsenv/prettier-check-project": "5.5.0",
|
|
62
|
-
"babel-eslint": "11.0.0-beta.0",
|
|
63
|
-
"eslint": "6.8.0",
|
|
64
|
-
"prettier": "1.19.1"
|
|
47
|
+
"@jsenv/assert": "2.4.1",
|
|
48
|
+
"@jsenv/core": "25.3.0",
|
|
49
|
+
"@jsenv/eslint-config": "16.0.9",
|
|
50
|
+
"@jsenv/importmap-eslint-resolver": "5.2.5",
|
|
51
|
+
"@jsenv/importmap-node-module": "5.1.3",
|
|
52
|
+
"eslint": "8.7.0",
|
|
53
|
+
"eslint-plugin-import": "2.25.4",
|
|
54
|
+
"prettier": "2.5.1"
|
|
65
55
|
}
|
|
66
56
|
}
|
package/readme.md
CHANGED
|
@@ -1,26 +1,3 @@
|
|
|
1
|
-
# github-release-package
|
|
1
|
+
# Github Release Package [](https://www.npmjs.com/package/@jsenv/github-release-package)
|
|
2
2
|
|
|
3
3
|
Create github release for package version updates.
|
|
4
|
-
|
|
5
|
-
[](https://github.com/jsenv/jsenv-github-release-package/packages)
|
|
6
|
-
[](https://www.npmjs.com/package/@jsenv/github-release-package)
|
|
7
|
-
[](https://github.com/jsenv/jsenv-github-release-package/actions?workflow=ci)
|
|
8
|
-
[](https://codecov.io/gh/jsenv/jsenv-github-release-package)
|
|
9
|
-
|
|
10
|
-
# Table of contents
|
|
11
|
-
|
|
12
|
-
- [Presentation](#Presentation)
|
|
13
|
-
- [Usage](#Usage)
|
|
14
|
-
- [Installation](#installation)
|
|
15
|
-
|
|
16
|
-
# Presentation
|
|
17
|
-
|
|
18
|
-
TODO
|
|
19
|
-
|
|
20
|
-
# Usage
|
|
21
|
-
|
|
22
|
-
TODO
|
|
23
|
-
|
|
24
|
-
# Installation
|
|
25
|
-
|
|
26
|
-
TODO
|
|
@@ -1,112 +1,108 @@
|
|
|
1
|
+
import * as githubRESTAPI from "@jsenv/github-pull-request-impact/src/internal/github_rest_api.js"
|
|
2
|
+
import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
|
|
1
3
|
import { createLogger } from "@jsenv/logger"
|
|
2
|
-
|
|
3
|
-
assertAndNormalizeDirectoryUrl,
|
|
4
|
-
catchCancellation,
|
|
5
|
-
createCancellationTokenForProcess,
|
|
6
|
-
} from "@jsenv/util"
|
|
4
|
+
|
|
7
5
|
import { readProjectPackage } from "./internal/readProjectPackage.js"
|
|
8
|
-
import { getGithubRelease } from "./internal/getGithubRelease.js"
|
|
9
|
-
import { createGithubRelease } from "./internal/createGithubRelease.js"
|
|
10
6
|
|
|
11
7
|
export const ensureGithubReleaseForPackage = async ({
|
|
12
|
-
cancellationToken = createCancellationTokenForProcess(),
|
|
13
8
|
logLevel,
|
|
14
9
|
projectDirectoryUrl,
|
|
15
|
-
updateProcessExitCode = true,
|
|
16
10
|
}) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
const logger = createLogger({ logLevel })
|
|
12
|
+
logger.debug(
|
|
13
|
+
`autoReleaseOnGithub(${JSON.stringify(
|
|
14
|
+
{ projectDirectoryUrl, logLevel },
|
|
15
|
+
null,
|
|
16
|
+
" ",
|
|
17
|
+
)})`,
|
|
18
|
+
)
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const {
|
|
26
|
-
githubToken,
|
|
27
|
-
githubRepositoryOwner,
|
|
28
|
-
githubRepositoryName,
|
|
29
|
-
githubSha,
|
|
30
|
-
} = getOptionsFromGithubAction()
|
|
20
|
+
projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)
|
|
31
21
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
const {
|
|
23
|
+
githubToken,
|
|
24
|
+
githubRepositoryOwner,
|
|
25
|
+
githubRepositoryName,
|
|
26
|
+
githubSha,
|
|
27
|
+
} = getOptionsFromGithubAction()
|
|
36
28
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
githubRepositoryName,
|
|
43
|
-
githubReleaseName,
|
|
44
|
-
})
|
|
45
|
-
cancellationToken.throwIfRequested()
|
|
46
|
-
if (existingRelease) {
|
|
47
|
-
logger.info(
|
|
48
|
-
`${packageVersion} already released at ${generateReleaseUrl({
|
|
49
|
-
githubRepositoryOwner,
|
|
50
|
-
githubRepositoryName,
|
|
51
|
-
githubReleaseName,
|
|
52
|
-
})}`,
|
|
53
|
-
)
|
|
54
|
-
return
|
|
55
|
-
}
|
|
29
|
+
logger.debug(`reading project package.json`)
|
|
30
|
+
const { packageVersion } = await getOptionsFromProjectPackage({
|
|
31
|
+
projectDirectoryUrl,
|
|
32
|
+
})
|
|
33
|
+
logger.debug(`${packageVersion} found in package.json`)
|
|
56
34
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
35
|
+
logger.debug(`search release for ${packageVersion} on github`)
|
|
36
|
+
const githubReleaseName = `v${packageVersion}`
|
|
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}`,
|
|
40
|
+
githubToken,
|
|
41
|
+
})
|
|
42
|
+
if (existingRelease) {
|
|
65
43
|
logger.info(
|
|
66
|
-
|
|
44
|
+
`${packageVersion} already released at ${generateReleaseUrl({
|
|
67
45
|
githubRepositoryOwner,
|
|
68
46
|
githubRepositoryName,
|
|
69
47
|
githubReleaseName,
|
|
70
48
|
})}`,
|
|
71
49
|
)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
logger.info(`creating release for ${packageVersion}`)
|
|
54
|
+
// https://developer.github.com/v3/git/tags/
|
|
55
|
+
await githubRESTAPI.POST({
|
|
56
|
+
url: `https://api.github.com/repos/${githubRepositoryOwner}/${githubRepositoryName}/git/refs`,
|
|
57
|
+
githubToken,
|
|
58
|
+
body: {
|
|
59
|
+
ref: `refs/tags/${githubReleaseName}`,
|
|
60
|
+
sha: githubSha,
|
|
61
|
+
},
|
|
77
62
|
})
|
|
63
|
+
logger.info(
|
|
64
|
+
`release created at ${generateReleaseUrl({
|
|
65
|
+
githubRepositoryOwner,
|
|
66
|
+
githubRepositoryName,
|
|
67
|
+
githubReleaseName,
|
|
68
|
+
})}`,
|
|
69
|
+
)
|
|
78
70
|
}
|
|
79
71
|
|
|
80
|
-
const generateReleaseUrl = ({
|
|
72
|
+
const generateReleaseUrl = ({
|
|
73
|
+
githubRepositoryOwner,
|
|
74
|
+
githubRepositoryName,
|
|
75
|
+
githubReleaseName,
|
|
76
|
+
}) => {
|
|
81
77
|
return `https://github.com/${githubRepositoryOwner}/${githubRepositoryName}/releases/tag/${githubReleaseName}`
|
|
82
78
|
}
|
|
83
79
|
|
|
84
80
|
const getOptionsFromGithubAction = () => {
|
|
85
81
|
const eventName = process.env.GITHUB_EVENT_NAME
|
|
86
82
|
if (!eventName) {
|
|
87
|
-
throw new Error(
|
|
83
|
+
throw new Error(
|
|
84
|
+
`missing process.env.GITHUB_EVENT_NAME, we are not in a github action`,
|
|
85
|
+
)
|
|
88
86
|
}
|
|
89
87
|
if (eventName !== "push") {
|
|
90
|
-
throw new Error(
|
|
88
|
+
throw new Error(
|
|
89
|
+
`getOptionsFromGithubAction must be called only in a push action`,
|
|
90
|
+
)
|
|
91
91
|
}
|
|
92
|
-
|
|
93
92
|
const githubRepository = process.env.GITHUB_REPOSITORY
|
|
94
93
|
if (!githubRepository) {
|
|
95
94
|
throw new Error(`missing process.env.GITHUB_REPOSITORY`)
|
|
96
95
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
const [githubRepositoryOwner, githubRepositoryName] =
|
|
97
|
+
githubRepository.split("/")
|
|
100
98
|
const githubToken = process.env.GITHUB_TOKEN
|
|
101
99
|
if (!githubToken) {
|
|
102
100
|
throw new Error(`missing process.env.GITHUB_TOKEN`)
|
|
103
101
|
}
|
|
104
|
-
|
|
105
102
|
const githubSha = process.env.GITHUB_SHA
|
|
106
103
|
if (!githubSha) {
|
|
107
104
|
throw new Error(`missing process.env.GITHUB_SHA`)
|
|
108
105
|
}
|
|
109
|
-
|
|
110
106
|
return {
|
|
111
107
|
githubRepositoryOwner,
|
|
112
108
|
githubRepositoryName,
|
|
@@ -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
|
}
|