@jsenv/github-release-package 1.2.3 → 1.3.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.
File without changes
package/package.json CHANGED
@@ -1,14 +1,20 @@
1
1
  {
2
2
  "name": "@jsenv/github-release-package",
3
- "version": "1.2.3",
3
+ "version": "1.3.3",
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/jsenv-github-release-package"
13
+ "url": "https://github.com/jsenv/workflow",
14
+ "directory": "packages/jsenv-github-release-package"
9
15
  },
10
16
  "engines": {
11
- "node": ">=12.8.0"
17
+ "node": ">=16.13.0"
12
18
  },
13
19
  "publishConfig": {
14
20
  "access": "public",
@@ -17,48 +23,34 @@
17
23
  "type": "module",
18
24
  "exports": {
19
25
  ".": {
20
- "import": "./index.js",
21
- "require": "./dist/commonjs/jsenv_publish_node_package.cjs"
26
+ "import": "./main.js"
22
27
  }
23
28
  },
24
- "main": "dist/commonjs/jsenv_publish_node_package.cjs",
29
+ "main": "./main.js",
25
30
  "files": [
26
- "/dist/",
27
31
  "/src/",
28
- "/index.js"
32
+ "/main.js"
29
33
  ],
30
34
  "scripts": {
31
- "eslint-check": "eslint .",
32
- "test": "node ./script/test/test.js",
33
- "test-with-coverage": "node ./script/test/test.js --coverage",
34
- "prettier-format": "node ./script/prettier-format/prettier-format.js",
35
- "prettier-format-stage": "npm run prettier-format -- --staged",
36
- "prettier-check": "npm run prettier-format -- --dry-run",
37
- "upload-coverage": "node ./script/upload-coverage/upload-coverage.js",
38
- "build": "node --experimental-import-meta-resolve ./script/build/build.js",
39
- "generate-import-map": "node ./script/generate-import-map/generate-import-map.js",
40
- "dist": "npm run build",
41
- "prepublishOnly": "node ./script/transform-package/remove-postinstall.js && npm run dist",
42
- "postpublish": "node ./script/transform-package/restore-postinstall.js"
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 ."
43
40
  },
44
41
  "dependencies": {
42
+ "@jsenv/filesystem": "2.7.1",
45
43
  "@jsenv/logger": "4.0.1",
46
- "@jsenv/server": "6.0.3",
47
- "@jsenv/util": "4.1.1"
44
+ "@jsenv/github-pull-request-impact": "1.6.8"
48
45
  },
49
46
  "devDependencies": {
50
- "@jsenv/assert": "2.2.5",
51
- "@jsenv/cancellation": "2.0.4",
52
- "@jsenv/codecov-upload": "3.4.3",
53
- "@jsenv/core": "18.1.2",
54
- "@jsenv/eslint-config": "15.0.1",
55
- "@jsenv/importmap-eslint-resolver": "5.0.0",
56
- "@jsenv/node-module-import-map": "13.4.2",
57
- "@jsenv/package-publish": "1.5.2",
58
- "@jsenv/prettier-check-project": "5.6.1",
59
- "@jsenv/prettier-config": "1.2.0",
60
- "eslint": "7.26.0",
61
- "eslint-plugin-import": "2.22.1",
62
- "prettier": "2.3.0"
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"
63
55
  }
64
56
  }
package/readme.md CHANGED
@@ -1,26 +1,3 @@
1
- # github-release-package
1
+ # Github Release Package [![npm package](https://img.shields.io/npm/v/@jsenv/github-release-package.svg?logo=npm&label=package)](https://www.npmjs.com/package/@jsenv/github-release-package)
2
2
 
3
3
  Create github release for package version updates.
4
-
5
- [![github package](https://img.shields.io/github/package-json/v/jsenv/jsenv-github-release-package.svg?logo=github&label=package)](https://github.com/jsenv/jsenv-github-release-package/packages)
6
- [![npm package](https://img.shields.io/npm/v/@jsenv/github-release-package.svg?logo=npm&label=package)](https://www.npmjs.com/package/@jsenv/github-release-package)
7
- [![github ci](https://github.com/jsenv/jsenv-github-release-package/workflows/ci/badge.svg)](https://github.com/jsenv/jsenv-github-release-package/actions?workflow=ci)
8
- [![codecov coverage](https://codecov.io/gh/jsenv/jsenv-github-release-package/branch/master/graph/badge.svg)](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
- import { assertAndNormalizeDirectoryUrl } from "@jsenv/util"
3
- import { executeAsyncFunction, createCancellationTokenForProcess } from "@jsenv/cancellation"
4
4
 
5
5
  import { readProjectPackage } from "./internal/readProjectPackage.js"
6
- import { getGithubRelease } from "./internal/getGithubRelease.js"
7
- import { createGithubRelease } from "./internal/createGithubRelease.js"
8
6
 
9
7
  export const ensureGithubReleaseForPackage = async ({
10
8
  logLevel,
11
- cancellationToken = createCancellationTokenForProcess(),
12
9
  projectDirectoryUrl,
13
- updateProcessExitCode = true,
14
10
  }) => {
15
- return executeAsyncFunction(
16
- async () => {
17
- const logger = createLogger({ logLevel })
18
- logger.debug(
19
- `autoReleaseOnGithub(${JSON.stringify({ projectDirectoryUrl, logLevel }, null, " ")})`,
20
- )
11
+ const logger = createLogger({ logLevel })
12
+ logger.debug(
13
+ `autoReleaseOnGithub(${JSON.stringify(
14
+ { projectDirectoryUrl, logLevel },
15
+ null,
16
+ " ",
17
+ )})`,
18
+ )
21
19
 
22
- projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)
20
+ projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)
23
21
 
24
- const { githubToken, githubRepositoryOwner, githubRepositoryName, githubSha } =
25
- getOptionsFromGithubAction()
22
+ const {
23
+ githubToken,
24
+ githubRepositoryOwner,
25
+ githubRepositoryName,
26
+ githubSha,
27
+ } = getOptionsFromGithubAction()
26
28
 
27
- logger.debug(`reading project package.json`)
28
- const { packageVersion } = await getOptionsFromProjectPackage({ projectDirectoryUrl })
29
- cancellationToken.throwIfRequested()
30
- logger.debug(`${packageVersion} found in package.json`)
29
+ logger.debug(`reading project package.json`)
30
+ const { packageVersion } = await getOptionsFromProjectPackage({
31
+ projectDirectoryUrl,
32
+ })
33
+ logger.debug(`${packageVersion} found in package.json`)
31
34
 
32
- logger.debug(`search release for ${packageVersion} on github`)
33
- const githubReleaseName = `v${packageVersion}`
34
- const existingRelease = await getGithubRelease({
35
- githubToken,
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) {
43
+ logger.info(
44
+ `${packageVersion} already released at ${generateReleaseUrl({
36
45
  githubRepositoryOwner,
37
46
  githubRepositoryName,
38
47
  githubReleaseName,
39
- })
40
- cancellationToken.throwIfRequested()
41
- if (existingRelease) {
42
- logger.info(
43
- `${packageVersion} already released at ${generateReleaseUrl({
44
- githubRepositoryOwner,
45
- githubRepositoryName,
46
- githubReleaseName,
47
- })}`,
48
- )
49
- return
50
- }
48
+ })}`,
49
+ )
50
+ return
51
+ }
51
52
 
52
- logger.info(`creating release for ${packageVersion}`)
53
- await createGithubRelease({
54
- githubToken,
55
- githubRepositoryOwner,
56
- githubRepositoryName,
57
- githubSha,
58
- githubReleaseName,
59
- })
60
- logger.info(
61
- `release created at ${generateReleaseUrl({
62
- githubRepositoryOwner,
63
- githubRepositoryName,
64
- githubReleaseName,
65
- })}`,
66
- )
67
- },
68
- {
69
- catchCancellation: true,
70
- considerUnhandledRejectionsAsExceptions: true,
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,
71
61
  },
72
- ).catch((e) => {
73
- if (updateProcessExitCode) {
74
- process.exitCode = 1
75
- }
76
- throw e
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 = ({ githubRepositoryOwner, githubRepositoryName, githubReleaseName }) => {
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(`missing process.env.GITHUB_EVENT_NAME, we are not in a github action`)
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(`getOptionsFromGithubAction must be called only in a push action`)
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
- const [githubRepositoryOwner, githubRepositoryName] = githubRepository.split("/")
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/util"
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
  }
@@ -1,268 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var logger = require('@jsenv/logger');
6
- var util = require('@jsenv/util');
7
- var cancellation = require('@jsenv/cancellation');
8
- var server = require('@jsenv/server');
9
-
10
- const readProjectPackage = async ({
11
- projectDirectoryUrl
12
- }) => {
13
- const packageFileUrl = util.resolveUrl("./package.json", projectDirectoryUrl);
14
- let packageInProject;
15
-
16
- try {
17
- const packageString = await util.readFile(packageFileUrl);
18
-
19
- try {
20
- packageInProject = JSON.parse(packageString);
21
- } catch (e) {
22
- if (e.name === "SyntaxError") {
23
- throw new Error(`syntax error while parsing project package.json
24
- --- syntax error stack ---
25
- ${e.stack}
26
- --- package.json path ---
27
- ${util.urlToFileSystemPath(packageFileUrl)}`);
28
- }
29
-
30
- throw e;
31
- }
32
- } catch (e) {
33
- if (e.code === "ENOENT") {
34
- throw new Error(`cannot find project package.json
35
- --- package.json path ---
36
- ${util.urlToFileSystemPath(packageFileUrl)}`);
37
- }
38
-
39
- throw e;
40
- }
41
-
42
- return packageInProject;
43
- };
44
-
45
- // https://developer.github.com/v3/git/refs/#get-a-single-reference
46
- const getGithubRelease = async ({
47
- githubToken,
48
- githubRepositoryOwner,
49
- githubRepositoryName,
50
- githubReleaseName
51
- }) => {
52
- const requestUrl = `https://api.github.com/repos/${githubRepositoryOwner}/${githubRepositoryName}/git/ref/tags/${githubReleaseName}`;
53
- const response = await server.fetchUrl(requestUrl, {
54
- headers: {
55
- authorization: `token ${githubToken}`
56
- },
57
- method: "GET"
58
- });
59
- const responseStatus = response.status;
60
-
61
- if (responseStatus === 404) {
62
- return null;
63
- }
64
-
65
- if (responseStatus !== 200) {
66
- throw new Error(writeUnexpectedResponseStatus$1({
67
- requestUrl,
68
- responseStatus,
69
- responseText: await response.text()
70
- }));
71
- }
72
-
73
- const responseJson = await response.json();
74
- return responseJson;
75
- };
76
-
77
- const writeUnexpectedResponseStatus$1 = ({
78
- requestUrl,
79
- responseStatus,
80
- responseText
81
- }) => `github api response status should be 200.
82
- --- request url ----
83
- ${requestUrl}
84
- --- response status ---
85
- ${responseStatus}
86
- --- response text ---
87
- ${responseText}`;
88
-
89
- // https://developer.github.com/v3/git/tags/
90
- const createGithubRelease = async ({
91
- githubToken,
92
- githubRepositoryOwner,
93
- githubRepositoryName,
94
- githubSha,
95
- githubReleaseName
96
- }) => {
97
- const requestUrl = `https://api.github.com/repos/${githubRepositoryOwner}/${githubRepositoryName}/git/refs`;
98
- const body = JSON.stringify({
99
- ref: `refs/tags/${githubReleaseName}`,
100
- sha: githubSha
101
- });
102
- const response = await server.fetchUrl(requestUrl, {
103
- headers: {
104
- "authorization": `token ${githubToken}`,
105
- "content-length": Buffer.byteLength(body)
106
- },
107
- method: "POST",
108
- body
109
- });
110
- const responseStatus = response.status;
111
-
112
- if (responseStatus !== 201) {
113
- throw new Error(writeUnexpectedResponseStatus({
114
- requestUrl,
115
- responseStatus,
116
- responseText: await response.text()
117
- }));
118
- }
119
-
120
- const responseJson = await response.json();
121
- return responseJson;
122
- };
123
-
124
- const writeUnexpectedResponseStatus = ({
125
- requestUrl,
126
- responseStatus,
127
- responseText
128
- }) => `github api response status should be 201.
129
- --- request url ----
130
- ${requestUrl}
131
- --- response status ---
132
- ${responseStatus}
133
- --- response text ---
134
- ${responseText}`;
135
-
136
- const ensureGithubReleaseForPackage = async ({
137
- logLevel,
138
- cancellationToken = cancellation.createCancellationTokenForProcess(),
139
- projectDirectoryUrl,
140
- updateProcessExitCode = true
141
- }) => {
142
- return cancellation.executeAsyncFunction(async () => {
143
- const logger$1 = logger.createLogger({
144
- logLevel
145
- });
146
- logger$1.debug(`autoReleaseOnGithub(${JSON.stringify({
147
- projectDirectoryUrl,
148
- logLevel
149
- }, null, " ")})`);
150
- projectDirectoryUrl = util.assertAndNormalizeDirectoryUrl(projectDirectoryUrl);
151
- const {
152
- githubToken,
153
- githubRepositoryOwner,
154
- githubRepositoryName,
155
- githubSha
156
- } = getOptionsFromGithubAction();
157
- logger$1.debug(`reading project package.json`);
158
- const {
159
- packageVersion
160
- } = await getOptionsFromProjectPackage({
161
- projectDirectoryUrl
162
- });
163
- cancellationToken.throwIfRequested();
164
- logger$1.debug(`${packageVersion} found in package.json`);
165
- logger$1.debug(`search release for ${packageVersion} on github`);
166
- const githubReleaseName = `v${packageVersion}`;
167
- const existingRelease = await getGithubRelease({
168
- githubToken,
169
- githubRepositoryOwner,
170
- githubRepositoryName,
171
- githubReleaseName
172
- });
173
- cancellationToken.throwIfRequested();
174
-
175
- if (existingRelease) {
176
- logger$1.info(`${packageVersion} already released at ${generateReleaseUrl({
177
- githubRepositoryOwner,
178
- githubRepositoryName,
179
- githubReleaseName
180
- })}`);
181
- return;
182
- }
183
-
184
- logger$1.info(`creating release for ${packageVersion}`);
185
- await createGithubRelease({
186
- githubToken,
187
- githubRepositoryOwner,
188
- githubRepositoryName,
189
- githubSha,
190
- githubReleaseName
191
- });
192
- logger$1.info(`release created at ${generateReleaseUrl({
193
- githubRepositoryOwner,
194
- githubRepositoryName,
195
- githubReleaseName
196
- })}`);
197
- }, {
198
- catchCancellation: true,
199
- considerUnhandledRejectionsAsExceptions: true
200
- }).catch(e => {
201
- if (updateProcessExitCode) {
202
- process.exitCode = 1;
203
- }
204
-
205
- throw e;
206
- });
207
- };
208
-
209
- const generateReleaseUrl = ({
210
- githubRepositoryOwner,
211
- githubRepositoryName,
212
- githubReleaseName
213
- }) => {
214
- return `https://github.com/${githubRepositoryOwner}/${githubRepositoryName}/releases/tag/${githubReleaseName}`;
215
- };
216
-
217
- const getOptionsFromGithubAction = () => {
218
- const eventName = process.env.GITHUB_EVENT_NAME;
219
-
220
- if (!eventName) {
221
- throw new Error(`missing process.env.GITHUB_EVENT_NAME, we are not in a github action`);
222
- }
223
-
224
- if (eventName !== "push") {
225
- throw new Error(`getOptionsFromGithubAction must be called only in a push action`);
226
- }
227
-
228
- const githubRepository = process.env.GITHUB_REPOSITORY;
229
-
230
- if (!githubRepository) {
231
- throw new Error(`missing process.env.GITHUB_REPOSITORY`);
232
- }
233
-
234
- const [githubRepositoryOwner, githubRepositoryName] = githubRepository.split("/");
235
- const githubToken = process.env.GITHUB_TOKEN;
236
-
237
- if (!githubToken) {
238
- throw new Error(`missing process.env.GITHUB_TOKEN`);
239
- }
240
-
241
- const githubSha = process.env.GITHUB_SHA;
242
-
243
- if (!githubSha) {
244
- throw new Error(`missing process.env.GITHUB_SHA`);
245
- }
246
-
247
- return {
248
- githubRepositoryOwner,
249
- githubRepositoryName,
250
- githubToken,
251
- githubSha
252
- };
253
- };
254
-
255
- const getOptionsFromProjectPackage = async ({
256
- projectDirectoryUrl
257
- }) => {
258
- const projectPackage = await readProjectPackage({
259
- projectDirectoryUrl
260
- });
261
- return {
262
- packageVersion: projectPackage.version
263
- };
264
- };
265
-
266
- exports.ensureGithubReleaseForPackage = ensureGithubReleaseForPackage;
267
-
268
- //# sourceMappingURL=jsenv_publish_node_package.cjs.map
@@ -1,92 +0,0 @@
1
- {
2
- "version": 3,
3
- "file": "jsenv_publish_node_package.cjs",
4
- "sources": [
5
- "../../src/internal/readProjectPackage.js",
6
- "../../src/internal/getGithubRelease.js",
7
- "../../src/internal/createGithubRelease.js",
8
- "../../src/ensureGithubReleaseForPackage.js"
9
- ],
10
- "sourcesContent": [
11
- "import { resolveUrl, urlToFileSystemPath, readFile } from \"@jsenv/util\"\n\nexport const readProjectPackage = async ({ projectDirectoryUrl }) => {\n const packageFileUrl = resolveUrl(\"./package.json\", projectDirectoryUrl)\n\n let packageInProject\n try {\n const packageString = await readFile(packageFileUrl)\n try {\n packageInProject = JSON.parse(packageString)\n } catch (e) {\n if (e.name === \"SyntaxError\") {\n throw new Error(`syntax error while parsing project package.json\n--- syntax error stack ---\n${e.stack}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`)\n }\n throw e\n }\n } catch (e) {\n if (e.code === \"ENOENT\") {\n throw new Error(\n `cannot find project package.json\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`,\n )\n }\n throw e\n }\n\n return packageInProject\n}\n",
12
- "// https://developer.github.com/v3/git/refs/#get-a-single-reference\n\nimport { fetchUrl } from \"@jsenv/server\"\n\nexport const getGithubRelease = async ({\n githubToken,\n githubRepositoryOwner,\n githubRepositoryName,\n githubReleaseName,\n}) => {\n const requestUrl = `https://api.github.com/repos/${githubRepositoryOwner}/${githubRepositoryName}/git/ref/tags/${githubReleaseName}`\n const response = await fetchUrl(requestUrl, {\n headers: {\n authorization: `token ${githubToken}`,\n },\n method: \"GET\",\n })\n\n const responseStatus = response.status\n\n if (responseStatus === 404) {\n return null\n }\n\n if (responseStatus !== 200) {\n throw new Error(\n writeUnexpectedResponseStatus({\n requestUrl,\n responseStatus,\n responseText: await response.text(),\n }),\n )\n }\n\n const responseJson = await response.json()\n return responseJson\n}\n\nconst writeUnexpectedResponseStatus = ({\n requestUrl,\n responseStatus,\n responseText,\n}) => `github api response status should be 200.\n--- request url ----\n${requestUrl}\n--- response status ---\n${responseStatus}\n--- response text ---\n${responseText}`\n",
13
- "// https://developer.github.com/v3/git/tags/\n\nimport { fetchUrl } from \"@jsenv/server\"\n\nexport const createGithubRelease = async ({\n githubToken,\n githubRepositoryOwner,\n githubRepositoryName,\n githubSha,\n githubReleaseName,\n}) => {\n const requestUrl = `https://api.github.com/repos/${githubRepositoryOwner}/${githubRepositoryName}/git/refs`\n const body = JSON.stringify({\n ref: `refs/tags/${githubReleaseName}`,\n sha: githubSha,\n })\n const response = await fetchUrl(requestUrl, {\n headers: {\n \"authorization\": `token ${githubToken}`,\n \"content-length\": Buffer.byteLength(body),\n },\n method: \"POST\",\n body,\n })\n\n const responseStatus = response.status\n\n if (responseStatus !== 201) {\n throw new Error(\n writeUnexpectedResponseStatus({\n requestUrl,\n responseStatus,\n responseText: await response.text(),\n }),\n )\n }\n\n const responseJson = await response.json()\n return responseJson\n}\n\nconst writeUnexpectedResponseStatus = ({\n requestUrl,\n responseStatus,\n responseText,\n}) => `github api response status should be 201.\n--- request url ----\n${requestUrl}\n--- response status ---\n${responseStatus}\n--- response text ---\n${responseText}`\n",
14
- "import { createLogger } from \"@jsenv/logger\"\nimport { assertAndNormalizeDirectoryUrl } from \"@jsenv/util\"\nimport { executeAsyncFunction, createCancellationTokenForProcess } from \"@jsenv/cancellation\"\n\nimport { readProjectPackage } from \"./internal/readProjectPackage.js\"\nimport { getGithubRelease } from \"./internal/getGithubRelease.js\"\nimport { createGithubRelease } from \"./internal/createGithubRelease.js\"\n\nexport const ensureGithubReleaseForPackage = async ({\n logLevel,\n cancellationToken = createCancellationTokenForProcess(),\n projectDirectoryUrl,\n updateProcessExitCode = true,\n}) => {\n return executeAsyncFunction(\n async () => {\n const logger = createLogger({ logLevel })\n logger.debug(\n `autoReleaseOnGithub(${JSON.stringify({ projectDirectoryUrl, logLevel }, null, \" \")})`,\n )\n\n projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)\n\n const { githubToken, githubRepositoryOwner, githubRepositoryName, githubSha } =\n getOptionsFromGithubAction()\n\n logger.debug(`reading project package.json`)\n const { packageVersion } = await getOptionsFromProjectPackage({ projectDirectoryUrl })\n cancellationToken.throwIfRequested()\n logger.debug(`${packageVersion} found in package.json`)\n\n logger.debug(`search release for ${packageVersion} on github`)\n const githubReleaseName = `v${packageVersion}`\n const existingRelease = await getGithubRelease({\n githubToken,\n githubRepositoryOwner,\n githubRepositoryName,\n githubReleaseName,\n })\n cancellationToken.throwIfRequested()\n if (existingRelease) {\n logger.info(\n `${packageVersion} already released at ${generateReleaseUrl({\n githubRepositoryOwner,\n githubRepositoryName,\n githubReleaseName,\n })}`,\n )\n return\n }\n\n logger.info(`creating release for ${packageVersion}`)\n await createGithubRelease({\n githubToken,\n githubRepositoryOwner,\n githubRepositoryName,\n githubSha,\n githubReleaseName,\n })\n logger.info(\n `release created at ${generateReleaseUrl({\n githubRepositoryOwner,\n githubRepositoryName,\n githubReleaseName,\n })}`,\n )\n },\n {\n catchCancellation: true,\n considerUnhandledRejectionsAsExceptions: true,\n },\n ).catch((e) => {\n if (updateProcessExitCode) {\n process.exitCode = 1\n }\n throw e\n })\n}\n\nconst generateReleaseUrl = ({ githubRepositoryOwner, githubRepositoryName, githubReleaseName }) => {\n return `https://github.com/${githubRepositoryOwner}/${githubRepositoryName}/releases/tag/${githubReleaseName}`\n}\n\nconst getOptionsFromGithubAction = () => {\n const eventName = process.env.GITHUB_EVENT_NAME\n if (!eventName) {\n throw new Error(`missing process.env.GITHUB_EVENT_NAME, we are not in a github action`)\n }\n if (eventName !== \"push\") {\n throw new Error(`getOptionsFromGithubAction must be called only in a push action`)\n }\n\n const githubRepository = process.env.GITHUB_REPOSITORY\n if (!githubRepository) {\n throw new Error(`missing process.env.GITHUB_REPOSITORY`)\n }\n\n const [githubRepositoryOwner, githubRepositoryName] = githubRepository.split(\"/\")\n\n const githubToken = process.env.GITHUB_TOKEN\n if (!githubToken) {\n throw new Error(`missing process.env.GITHUB_TOKEN`)\n }\n\n const githubSha = process.env.GITHUB_SHA\n if (!githubSha) {\n throw new Error(`missing process.env.GITHUB_SHA`)\n }\n\n return {\n githubRepositoryOwner,\n githubRepositoryName,\n githubToken,\n githubSha,\n }\n}\n\nconst getOptionsFromProjectPackage = async ({ projectDirectoryUrl }) => {\n const projectPackage = await readProjectPackage({ projectDirectoryUrl })\n return {\n packageVersion: projectPackage.version,\n }\n}\n"
15
- ],
16
- "names": [
17
- "readProjectPackage",
18
- "projectDirectoryUrl",
19
- "packageFileUrl",
20
- "resolveUrl",
21
- "packageInProject",
22
- "packageString",
23
- "readFile",
24
- "JSON",
25
- "parse",
26
- "e",
27
- "name",
28
- "Error",
29
- "stack",
30
- "urlToFileSystemPath",
31
- "code",
32
- "getGithubRelease",
33
- "githubToken",
34
- "githubRepositoryOwner",
35
- "githubRepositoryName",
36
- "githubReleaseName",
37
- "requestUrl",
38
- "response",
39
- "fetchUrl",
40
- "headers",
41
- "authorization",
42
- "method",
43
- "responseStatus",
44
- "status",
45
- "writeUnexpectedResponseStatus",
46
- "responseText",
47
- "text",
48
- "responseJson",
49
- "json",
50
- "createGithubRelease",
51
- "githubSha",
52
- "body",
53
- "stringify",
54
- "ref",
55
- "sha",
56
- "Buffer",
57
- "byteLength",
58
- "ensureGithubReleaseForPackage",
59
- "logLevel",
60
- "cancellationToken",
61
- "createCancellationTokenForProcess",
62
- "updateProcessExitCode",
63
- "executeAsyncFunction",
64
- "logger",
65
- "createLogger",
66
- "debug",
67
- "assertAndNormalizeDirectoryUrl",
68
- "getOptionsFromGithubAction",
69
- "packageVersion",
70
- "getOptionsFromProjectPackage",
71
- "throwIfRequested",
72
- "existingRelease",
73
- "info",
74
- "generateReleaseUrl",
75
- "catchCancellation",
76
- "considerUnhandledRejectionsAsExceptions",
77
- "catch",
78
- "process",
79
- "exitCode",
80
- "eventName",
81
- "env",
82
- "GITHUB_EVENT_NAME",
83
- "githubRepository",
84
- "GITHUB_REPOSITORY",
85
- "split",
86
- "GITHUB_TOKEN",
87
- "GITHUB_SHA",
88
- "projectPackage",
89
- "version"
90
- ],
91
- "mappings": ";;;;;;;;;AAEO,MAAMA,kBAAkB,GAAG,OAAO;AAAEC,EAAAA;AAAF,CAAP,KAAmC;AACnE,QAAMC,cAAc,GAAGC,eAAU,CAAC,gBAAD,EAAmBF,mBAAnB,CAAjC;AAEA,MAAIG,gBAAJ;;AACA,MAAI;AACF,UAAMC,aAAa,GAAG,MAAMC,aAAQ,CAACJ,cAAD,CAApC;;AACA,QAAI;AACFE,MAAAA,gBAAgB,GAAGG,IAAI,CAACC,KAAL,CAAWH,aAAX,CAAnB;AACD,KAFD,CAEE,OAAOI,CAAP,EAAU;AACV,UAAIA,CAAC,CAACC,IAAF,KAAW,aAAf,EAA8B;AAC5B,cAAM,IAAIC,KAAJ,CAAW;AACzB;AACA,EAAEF,CAAC,CAACG,KAAM;AACV;AACA,EAAEC,wBAAmB,CAACX,cAAD,CAAiB,EAJxB,CAAN;AAKD;;AACD,YAAMO,CAAN;AACD;AACF,GAdD,CAcE,OAAOA,CAAP,EAAU;AACV,QAAIA,CAAC,CAACK,IAAF,KAAW,QAAf,EAAyB;AACvB,YAAM,IAAIH,KAAJ,CACH;AACT;AACA,EAAEE,wBAAmB,CAACX,cAAD,CAAiB,EAH1B,CAAN;AAKD;;AACD,UAAMO,CAAN;AACD;;AAED,SAAOL,gBAAP;AACD,CA9BM;;ACFP;AAIO,MAAMW,gBAAgB,GAAG,OAAO;AACrCC,EAAAA,WADqC;AAErCC,EAAAA,qBAFqC;AAGrCC,EAAAA,oBAHqC;AAIrCC,EAAAA;AAJqC,CAAP,KAK1B;AACJ,QAAMC,UAAU,GAAI,gCAA+BH,qBAAsB,IAAGC,oBAAqB,iBAAgBC,iBAAkB,EAAnI;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,CAACpC,SAAL,EAAgB;AACd,UAAM,IAAIvB,KAAJ,CAAW,gCAAX,CAAN;AACD;;AAED,SAAO;AACLM,IAAAA,qBADK;AAELC,IAAAA,oBAFK;AAGLF,IAAAA,WAHK;AAILkB,IAAAA;AAJK,GAAP;AAMD,CAhCD;;AAkCA,MAAMmB,4BAA4B,GAAG,OAAO;AAAEpD,EAAAA;AAAF,CAAP,KAAmC;AACtE,QAAMsE,cAAc,GAAG,MAAMvE,kBAAkB,CAAC;AAAEC,IAAAA;AAAF,GAAD,CAA/C;AACA,SAAO;AACLmD,IAAAA,cAAc,EAAEmB,cAAc,CAACC;AAD1B,GAAP;AAGD,CALD;;;;"
92
- }
@@ -1,52 +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
-
26
- const responseStatus = response.status
27
-
28
- if (responseStatus !== 201) {
29
- throw new Error(
30
- writeUnexpectedResponseStatus({
31
- requestUrl,
32
- responseStatus,
33
- responseText: await response.text(),
34
- }),
35
- )
36
- }
37
-
38
- const responseJson = await response.json()
39
- return responseJson
40
- }
41
-
42
- const writeUnexpectedResponseStatus = ({
43
- requestUrl,
44
- responseStatus,
45
- responseText,
46
- }) => `github api response status should be 201.
47
- --- request url ----
48
- ${requestUrl}
49
- --- response status ---
50
- ${responseStatus}
51
- --- response text ---
52
- ${responseText}`
@@ -1,49 +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
-
19
- const responseStatus = response.status
20
-
21
- if (responseStatus === 404) {
22
- return null
23
- }
24
-
25
- if (responseStatus !== 200) {
26
- throw new Error(
27
- writeUnexpectedResponseStatus({
28
- requestUrl,
29
- responseStatus,
30
- responseText: await response.text(),
31
- }),
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 200.
44
- --- request url ----
45
- ${requestUrl}
46
- --- response status ---
47
- ${responseStatus}
48
- --- response text ---
49
- ${responseText}`