@jsenv/github-release-package 1.2.1 → 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.
File without changes
package/package.json CHANGED
@@ -1,14 +1,20 @@
1
1
  {
2
2
  "name": "@jsenv/github-release-package",
3
- "version": "1.2.1",
3
+ "version": "1.3.1",
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,50 +23,34 @@
17
23
  "type": "module",
18
24
  "exports": {
19
25
  ".": {
20
- "import": "./index.js",
21
- "require": "./dist/commonjs/main.cjs"
26
+ "import": "./main.js"
22
27
  }
23
28
  },
24
- "main": "dist/commonjs/main.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
- "test": "node ./script/test/test.js",
32
- "test-with-coverage": "node ./script/test/test.js --coverage",
33
- "eslint-check": "eslint .",
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
- "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/logger": "3.3.1",
48
- "@jsenv/server": "1.6.0",
49
- "@jsenv/util": "3.5.2"
42
+ "@jsenv/filesystem": "2.7.1",
43
+ "@jsenv/logger": "4.0.1",
44
+ "@jsenv/github-pull-request-impact": "1.6.6"
50
45
  },
51
46
  "devDependencies": {
52
- "@jsenv/assert": "1.2.2",
53
- "@jsenv/codecov-upload": "3.2.0",
54
- "@jsenv/core": "11.6.1",
55
- "@jsenv/eslint-config": "12.3.1",
56
- "@jsenv/git-hooks": "1.3.1",
57
- "@jsenv/github-release-package": "1.2.0",
58
- "@jsenv/node-module-import-map": "11.0.0",
59
- "@jsenv/package-publish": "1.5.0",
60
- "@jsenv/prettier-config": "1.2.0",
61
- "@jsenv/prettier-check-project": "5.4.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 [![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 {
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
- return catchCancellation(async () => {
18
- const logger = createLogger({ logLevel })
19
- logger.debug(
20
- `autoReleaseOnGithub(${JSON.stringify({ projectDirectoryUrl, logLevel }, null, " ")})`,
21
- )
11
+ const logger = createLogger({ logLevel })
12
+ logger.debug(
13
+ `autoReleaseOnGithub(${JSON.stringify(
14
+ { projectDirectoryUrl, logLevel },
15
+ null,
16
+ " ",
17
+ )})`,
18
+ )
22
19
 
23
- projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)
24
-
25
- const {
26
- githubToken,
27
- githubRepositoryOwner,
28
- githubRepositoryName,
29
- githubSha,
30
- } = getOptionsFromGithubAction()
20
+ projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)
31
21
 
32
- logger.debug(`reading project package.json`)
33
- const { packageVersion } = await getOptionsFromProjectPackage({ projectDirectoryUrl })
34
- cancellationToken.throwIfRequested()
35
- logger.debug(`${packageVersion} found in package.json`)
22
+ const {
23
+ githubToken,
24
+ githubRepositoryOwner,
25
+ githubRepositoryName,
26
+ githubSha,
27
+ } = getOptionsFromGithubAction()
36
28
 
37
- logger.debug(`search release for ${packageVersion} on github`)
38
- const githubReleaseName = `v${packageVersion}`
39
- const existingRelease = await getGithubRelease({
40
- githubToken,
41
- githubRepositoryOwner,
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
- logger.info(`creating release for ${packageVersion}`)
58
- await createGithubRelease({
59
- githubToken,
60
- githubRepositoryOwner,
61
- githubRepositoryName,
62
- githubSha,
63
- githubReleaseName,
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
- `release created at ${generateReleaseUrl({
44
+ `${packageVersion} already released at ${generateReleaseUrl({
67
45
  githubRepositoryOwner,
68
46
  githubRepositoryName,
69
47
  githubReleaseName,
70
48
  })}`,
71
49
  )
72
- }).catch((e) => {
73
- if (updateProcessExitCode) {
74
- process.exitCode = 1
75
- }
76
- throw e
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 = ({ 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
  }