@reelout/github 0.1.1 → 0.4.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 +21 -0
- package/dist/index.js +145 -1
- package/dist/index.js.map +1 -0
- package/package.json +15 -5
- package/src/createRelease.ts +45 -0
- package/src/deleteRelease.ts +52 -0
- package/src/github.ts +66 -0
- package/src/index.ts +7 -2
- package/src/isRepositoryPublic.ts +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.js
CHANGED
|
@@ -1 +1,145 @@
|
|
|
1
|
-
|
|
1
|
+
import { Octokit } from "@octokit/rest";
|
|
2
|
+
//#region src/createRelease.ts
|
|
3
|
+
/**
|
|
4
|
+
* Create a GitHub release for a package tag.
|
|
5
|
+
*
|
|
6
|
+
* Skips creation when the tag has no message. Uses the Octokit REST API
|
|
7
|
+
* with the provided token to create the release.
|
|
8
|
+
*
|
|
9
|
+
* @param context Release context containing commit and prerelease information
|
|
10
|
+
* @param plan Release plan containing the tag to publish
|
|
11
|
+
* @param token GitHub authentication token
|
|
12
|
+
* @param repository Target repository
|
|
13
|
+
* @returns Promise that resolves when the release is created
|
|
14
|
+
*/
|
|
15
|
+
async function createRelease(context, plan, token, repository) {
|
|
16
|
+
if (!plan.release?.tag?.message) return;
|
|
17
|
+
await new Octokit({
|
|
18
|
+
auth: token,
|
|
19
|
+
log: {
|
|
20
|
+
debug: () => {},
|
|
21
|
+
info: () => {},
|
|
22
|
+
warn: () => {},
|
|
23
|
+
error: () => {}
|
|
24
|
+
}
|
|
25
|
+
}).rest.repos.createRelease({
|
|
26
|
+
owner: repository.owner,
|
|
27
|
+
repo: repository.repo,
|
|
28
|
+
tag_name: plan.release.tag.name,
|
|
29
|
+
target_commitish: context.commit.hash,
|
|
30
|
+
name: plan.release.tag.name,
|
|
31
|
+
body: plan.release.tag.message,
|
|
32
|
+
draft: false,
|
|
33
|
+
prerelease: Boolean(context.versionQualifier)
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/deleteRelease.ts
|
|
38
|
+
/**
|
|
39
|
+
* Delete a GitHub release associated with a package tag.
|
|
40
|
+
*
|
|
41
|
+
* Skips deletion if the plan does not contain a valid tag name. Resolves gracefully
|
|
42
|
+
* if the release does not exist on GitHub (e.g., 404 status).
|
|
43
|
+
*
|
|
44
|
+
* @param plan Release plan containing the tag associated with the release to delete
|
|
45
|
+
* @param token GitHub authentication token
|
|
46
|
+
* @param repository Target repository
|
|
47
|
+
* @returns Promise that resolves when the release is deleted
|
|
48
|
+
*/
|
|
49
|
+
async function deleteRelease(plan, token, repository) {
|
|
50
|
+
if (!plan.release?.tag?.name) return;
|
|
51
|
+
try {
|
|
52
|
+
/* istanbul ignore next */
|
|
53
|
+
const octokit = new Octokit({
|
|
54
|
+
auth: token,
|
|
55
|
+
log: {
|
|
56
|
+
debug: () => {},
|
|
57
|
+
info: () => {},
|
|
58
|
+
warn: () => {},
|
|
59
|
+
error: () => {}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const { data: release } = await octokit.rest.repos.getReleaseByTag({
|
|
63
|
+
owner: repository.owner,
|
|
64
|
+
repo: repository.repo,
|
|
65
|
+
tag: plan.release.tag.name
|
|
66
|
+
});
|
|
67
|
+
await octokit.rest.repos.deleteRelease({
|
|
68
|
+
owner: repository.owner,
|
|
69
|
+
repo: repository.repo,
|
|
70
|
+
release_id: release.id
|
|
71
|
+
});
|
|
72
|
+
} catch (err) {
|
|
73
|
+
if (err?.status === 404) return;
|
|
74
|
+
throw err;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region package.json
|
|
79
|
+
var version = "0.3.0";
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/github.ts
|
|
82
|
+
/**
|
|
83
|
+
* Built-in plugin that creates GitHub releases for finalized release plans.
|
|
84
|
+
*
|
|
85
|
+
* @remarks
|
|
86
|
+
* **Lifecycle Stages:**
|
|
87
|
+
* - `publish`: Creates GitHub releases in reverse alphabetical package order (ensuring the root package release
|
|
88
|
+
* is created last). Automatically rolls back and deletes created releases if subsequent publishing stages fail.
|
|
89
|
+
*
|
|
90
|
+
* @throws {Error} If `context.repository` is not configured or `GITHUB_TOKEN` environment variable is missing.
|
|
91
|
+
* @returns A release plugin configured for GitHub release creation.
|
|
92
|
+
*/
|
|
93
|
+
var github = () => ({
|
|
94
|
+
name: "@reelout/github",
|
|
95
|
+
version,
|
|
96
|
+
publish: async (context, next) => {
|
|
97
|
+
if (!context.repository) throw new Error("A Git repository is required to create a GitHub release.");
|
|
98
|
+
if (!context.env.GITHUB_TOKEN) throw new Error("The GITHUB_TOKEN environment variable is required.");
|
|
99
|
+
if (context.dryRun) {
|
|
100
|
+
context.logger.debug("[DRY RUN] GitHub releases will not be created.");
|
|
101
|
+
return next(context);
|
|
102
|
+
}
|
|
103
|
+
const plans = context.plans.toSorted((a, b) => (a.package.name || "").localeCompare(b.package.name || ""));
|
|
104
|
+
const token = context.env.GITHUB_TOKEN;
|
|
105
|
+
const repository = context.repository;
|
|
106
|
+
for (const plan of plans.toReversed()) await createRelease(context, plan, token, repository);
|
|
107
|
+
try {
|
|
108
|
+
return await next(context);
|
|
109
|
+
} catch (err) {
|
|
110
|
+
await Promise.allSettled(plans.map((plan) => deleteRelease(plan, token, repository)));
|
|
111
|
+
throw err;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/isRepositoryPublic.ts
|
|
117
|
+
/**
|
|
118
|
+
* Check if the target GitHub repository is public.
|
|
119
|
+
*
|
|
120
|
+
* Uses the Octokit REST API with the provided token to fetch the
|
|
121
|
+
* visibility status of the specified repository.
|
|
122
|
+
*
|
|
123
|
+
* @param token GitHub authentication token
|
|
124
|
+
* @param repository Target repository
|
|
125
|
+
* @returns Promise that resolves to `true` if the repository is public
|
|
126
|
+
*/
|
|
127
|
+
async function isRepositoryPublic(token, repository) {
|
|
128
|
+
const { data } = await new Octokit({
|
|
129
|
+
auth: token,
|
|
130
|
+
log: {
|
|
131
|
+
debug: () => {},
|
|
132
|
+
info: () => {},
|
|
133
|
+
warn: () => {},
|
|
134
|
+
error: () => {}
|
|
135
|
+
}
|
|
136
|
+
}).rest.repos.get({
|
|
137
|
+
owner: repository.owner,
|
|
138
|
+
repo: repository.repo
|
|
139
|
+
});
|
|
140
|
+
return data.visibility === "public";
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
export { createRelease, github as default, deleteRelease, isRepositoryPublic };
|
|
144
|
+
|
|
145
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/createRelease.ts","../src/deleteRelease.ts","../package.json","../src/github.ts","../src/isRepositoryPublic.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { Octokit } from '@octokit/rest'\nimport type { GitRepository, ReleaseContext, ReleasePlan } from '@reelout/core'\n\n/**\n * Create a GitHub release for a package tag.\n *\n * Skips creation when the tag has no message. Uses the Octokit REST API\n * with the provided token to create the release.\n *\n * @param context Release context containing commit and prerelease information\n * @param plan Release plan containing the tag to publish\n * @param token GitHub authentication token\n * @param repository Target repository\n * @returns Promise that resolves when the release is created\n */\nexport async function createRelease(\n context: ReleaseContext,\n plan: ReleasePlan,\n token: string,\n repository: GitRepository\n): Promise<void> {\n if (!plan.release?.tag?.message) {\n return\n }\n\n /* istanbul ignore next */\n const octokit = new Octokit({\n auth: token,\n log: { debug: () => {}, info: () => {}, warn: () => {}, error: () => {} },\n })\n\n await octokit.rest.repos.createRelease({\n owner: repository.owner,\n repo: repository.repo,\n tag_name: plan.release.tag.name,\n target_commitish: context.commit.hash,\n name: plan.release.tag.name,\n body: plan.release.tag.message,\n draft: false,\n prerelease: Boolean(context.versionQualifier),\n })\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { Octokit } from '@octokit/rest'\nimport type { GitRepository, ReleasePlan } from '@reelout/core'\n\n/**\n * Delete a GitHub release associated with a package tag.\n *\n * Skips deletion if the plan does not contain a valid tag name. Resolves gracefully\n * if the release does not exist on GitHub (e.g., 404 status).\n *\n * @param plan Release plan containing the tag associated with the release to delete\n * @param token GitHub authentication token\n * @param repository Target repository\n * @returns Promise that resolves when the release is deleted\n */\nexport async function deleteRelease(\n plan: ReleasePlan,\n token: string,\n repository: GitRepository\n): Promise<void> {\n if (!plan.release?.tag?.name) {\n return\n }\n\n try {\n /* istanbul ignore next */\n const octokit = new Octokit({\n auth: token,\n log: { debug: () => {}, info: () => {}, warn: () => {}, error: () => {} },\n })\n\n const { data: release } = await octokit.rest.repos.getReleaseByTag({\n owner: repository.owner,\n repo: repository.repo,\n tag: plan.release.tag.name,\n })\n\n await octokit.rest.repos.deleteRelease({\n owner: repository.owner,\n repo: repository.repo,\n release_id: release.id,\n })\n } catch (err) {\n if ((err as { status?: number } | undefined)?.status === 404) {\n return\n }\n\n throw err\n }\n}\n","{\n \"name\": \"@reelout/github\",\n \"version\": \"0.3.0\",\n \"description\": \"GitHub integration for automating releases.\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/aicest/reelout.git\",\n \"directory\": \"packages/github\"\n },\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"imports\": {},\n \"exports\": {\n \"./package.json\": {\n \"default\": \"./package.json\"\n },\n \".\": {\n \"module\": \"./src/index.ts\",\n \"development\": \"./src/index.ts\",\n \"types\": \"./src/index.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"./*\": {\n \"module\": \"./src/*.ts\",\n \"development\": \"./src/*.ts\",\n \"types\": \"./src/*.ts\",\n \"default\": \"./dist/*.js\"\n }\n },\n \"files\": [\n \"./dist\",\n \"./src\"\n ],\n \"scripts\": {\n \"build\": \"vite build --ssr --sourcemap\",\n \"dev\": \"vite build --ssr --watch\"\n },\n \"dependencies\": {\n \"@octokit/rest\": \"catalog:\",\n \"@reelout/core\": \"workspace:^\"\n },\n \"engines\": {\n \"node\": \">=24.15\"\n }\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { ReleasePlugin } from '@reelout/core'\nimport { version } from '../package.json'\nimport { createRelease } from './createRelease'\nimport { deleteRelease } from './deleteRelease'\n\n/**\n * Built-in plugin that creates GitHub releases for finalized release plans.\n *\n * @remarks\n * **Lifecycle Stages:**\n * - `publish`: Creates GitHub releases in reverse alphabetical package order (ensuring the root package release\n * is created last). Automatically rolls back and deletes created releases if subsequent publishing stages fail.\n *\n * @throws {Error} If `context.repository` is not configured or `GITHUB_TOKEN` environment variable is missing.\n * @returns A release plugin configured for GitHub release creation.\n */\nconst github = (): ReleasePlugin => ({\n name: '@reelout/github',\n version,\n publish: async (context, next) => {\n if (!context.repository) {\n throw new Error(\n 'A Git repository is required to create a GitHub release.'\n )\n }\n\n if (!context.env.GITHUB_TOKEN) {\n throw new Error('The GITHUB_TOKEN environment variable is required.')\n }\n\n if (context.dryRun) {\n context.logger.debug('[DRY RUN] GitHub releases will not be created.')\n return next(context)\n }\n\n const plans = context.plans.toSorted((a, b) =>\n (a.package.name || '').localeCompare(b.package.name || '')\n )\n\n const token = context.env.GITHUB_TOKEN\n\n const repository = context.repository\n\n // Create releases in reverse order\n // so that the root package release is created last,\n // as it is often the most important one.\n for (const plan of plans.toReversed()) {\n await createRelease(context, plan, token, repository)\n }\n\n try {\n return await next(context)\n } catch (err) {\n await Promise.allSettled(\n plans.map((plan) => deleteRelease(plan, token, repository))\n )\n\n throw err\n }\n },\n})\n\nexport default github\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { Octokit } from '@octokit/rest'\nimport type { GitRepository } from '@reelout/core'\n\n/**\n * Check if the target GitHub repository is public.\n *\n * Uses the Octokit REST API with the provided token to fetch the\n * visibility status of the specified repository.\n *\n * @param token GitHub authentication token\n * @param repository Target repository\n * @returns Promise that resolves to `true` if the repository is public\n */\nexport async function isRepositoryPublic(\n token: string,\n repository: GitRepository\n): Promise<boolean> {\n /* istanbul ignore next */\n const octokit = new Octokit({\n auth: token,\n log: { debug: () => {}, info: () => {}, warn: () => {}, error: () => {} },\n })\n\n const { data } = await octokit.rest.repos.get({\n owner: repository.owner,\n repo: repository.repo,\n })\n\n return data.visibility === 'public'\n}\n"],"mappings":";;;;;;;;;;;;;;AAkBA,eAAsB,cACpB,SACA,MACA,OACA,YACe;CACf,IAAI,CAAC,KAAK,SAAS,KAAK,SACtB;CASF,MAAM,IALc,QAAQ;EAC1B,MAAM;EACN,KAAK;GAAE,aAAa,CAAC;GAAG,YAAY,CAAC;GAAG,YAAY,CAAC;GAAG,aAAa,CAAC;EAAE;CAC1E,CAEM,CAAA,CAAQ,KAAK,MAAM,cAAc;EACrC,OAAO,WAAW;EAClB,MAAM,WAAW;EACjB,UAAU,KAAK,QAAQ,IAAI;EAC3B,kBAAkB,QAAQ,OAAO;EACjC,MAAM,KAAK,QAAQ,IAAI;EACvB,MAAM,KAAK,QAAQ,IAAI;EACvB,OAAO;EACP,YAAY,QAAQ,QAAQ,gBAAgB;CAC9C,CAAC;AACH;;;;;;;;;;;;;;AC3BA,eAAsB,cACpB,MACA,OACA,YACe;CACf,IAAI,CAAC,KAAK,SAAS,KAAK,MACtB;CAGF,IAAI;;EAEF,MAAM,UAAU,IAAI,QAAQ;GAC1B,MAAM;GACN,KAAK;IAAE,aAAa,CAAC;IAAG,YAAY,CAAC;IAAG,YAAY,CAAC;IAAG,aAAa,CAAC;GAAE;EAC1E,CAAC;EAED,MAAM,EAAE,MAAM,YAAY,MAAM,QAAQ,KAAK,MAAM,gBAAgB;GACjE,OAAO,WAAW;GAClB,MAAM,WAAW;GACjB,KAAK,KAAK,QAAQ,IAAI;EACxB,CAAC;EAED,MAAM,QAAQ,KAAK,MAAM,cAAc;GACrC,OAAO,WAAW;GAClB,MAAM,WAAW;GACjB,YAAY,QAAQ;EACtB,CAAC;CACH,SAAS,KAAK;EACZ,IAAK,KAAyC,WAAW,KACvD;EAGF,MAAM;CACR;AACF;;;;;;;;;;;;;;;;;AEhCA,IAAM,gBAA+B;CACnC,MAAM;CACN;CACA,SAAS,OAAO,SAAS,SAAS;EAChC,IAAI,CAAC,QAAQ,YACX,MAAM,IAAI,MACR,0DACF;EAGF,IAAI,CAAC,QAAQ,IAAI,cACf,MAAM,IAAI,MAAM,oDAAoD;EAGtE,IAAI,QAAQ,QAAQ;GAClB,QAAQ,OAAO,MAAM,gDAAgD;GACrE,OAAO,KAAK,OAAO;EACrB;EAEA,MAAM,QAAQ,QAAQ,MAAM,UAAU,GAAG,OACtC,EAAE,QAAQ,QAAQ,GAAA,CAAI,cAAc,EAAE,QAAQ,QAAQ,EAAE,CAC3D;EAEA,MAAM,QAAQ,QAAQ,IAAI;EAE1B,MAAM,aAAa,QAAQ;EAK3B,KAAK,MAAM,QAAQ,MAAM,WAAW,GAClC,MAAM,cAAc,SAAS,MAAM,OAAO,UAAU;EAGtD,IAAI;GACF,OAAO,MAAM,KAAK,OAAO;EAC3B,SAAS,KAAK;GACZ,MAAM,QAAQ,WACZ,MAAM,KAAK,SAAS,cAAc,MAAM,OAAO,UAAU,CAAC,CAC5D;GAEA,MAAM;EACR;CACF;AACF;;;;;;;;;;;;;AC/CA,eAAsB,mBACpB,OACA,YACkB;CAOlB,MAAM,EAAE,SAAS,MAAM,IALH,QAAQ;EAC1B,MAAM;EACN,KAAK;GAAE,aAAa,CAAC;GAAG,YAAY,CAAC;GAAG,YAAY,CAAC;GAAG,aAAa,CAAC;EAAE;CAC1E,CAEuB,CAAA,CAAQ,KAAK,MAAM,IAAI;EAC5C,OAAO,WAAW;EAClB,MAAM,WAAW;CACnB,CAAC;CAED,OAAO,KAAK,eAAe;AAC7B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reelout/github",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "GitHub integration for automating releases.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/aicest/reelout.git",
|
|
8
|
+
"directory": "packages/github"
|
|
9
|
+
},
|
|
4
10
|
"license": "MIT",
|
|
5
11
|
"type": "module",
|
|
6
12
|
"imports": {},
|
|
@@ -25,11 +31,15 @@
|
|
|
25
31
|
"./dist",
|
|
26
32
|
"./src"
|
|
27
33
|
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@octokit/rest": "^22.0.1",
|
|
36
|
+
"@reelout/core": "^0.4.0"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=24.15"
|
|
40
|
+
},
|
|
28
41
|
"scripts": {
|
|
29
42
|
"build": "vite build --ssr --sourcemap",
|
|
30
43
|
"dev": "vite build --ssr --watch"
|
|
31
|
-
},
|
|
32
|
-
"engines": {
|
|
33
|
-
"node": ">=24.11"
|
|
34
44
|
}
|
|
35
|
-
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
import { Octokit } from '@octokit/rest'
|
|
5
|
+
import type { GitRepository, ReleaseContext, ReleasePlan } from '@reelout/core'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Create a GitHub release for a package tag.
|
|
9
|
+
*
|
|
10
|
+
* Skips creation when the tag has no message. Uses the Octokit REST API
|
|
11
|
+
* with the provided token to create the release.
|
|
12
|
+
*
|
|
13
|
+
* @param context Release context containing commit and prerelease information
|
|
14
|
+
* @param plan Release plan containing the tag to publish
|
|
15
|
+
* @param token GitHub authentication token
|
|
16
|
+
* @param repository Target repository
|
|
17
|
+
* @returns Promise that resolves when the release is created
|
|
18
|
+
*/
|
|
19
|
+
export async function createRelease(
|
|
20
|
+
context: ReleaseContext,
|
|
21
|
+
plan: ReleasePlan,
|
|
22
|
+
token: string,
|
|
23
|
+
repository: GitRepository
|
|
24
|
+
): Promise<void> {
|
|
25
|
+
if (!plan.release?.tag?.message) {
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* istanbul ignore next */
|
|
30
|
+
const octokit = new Octokit({
|
|
31
|
+
auth: token,
|
|
32
|
+
log: { debug: () => {}, info: () => {}, warn: () => {}, error: () => {} },
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
await octokit.rest.repos.createRelease({
|
|
36
|
+
owner: repository.owner,
|
|
37
|
+
repo: repository.repo,
|
|
38
|
+
tag_name: plan.release.tag.name,
|
|
39
|
+
target_commitish: context.commit.hash,
|
|
40
|
+
name: plan.release.tag.name,
|
|
41
|
+
body: plan.release.tag.message,
|
|
42
|
+
draft: false,
|
|
43
|
+
prerelease: Boolean(context.versionQualifier),
|
|
44
|
+
})
|
|
45
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
import { Octokit } from '@octokit/rest'
|
|
5
|
+
import type { GitRepository, ReleasePlan } from '@reelout/core'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Delete a GitHub release associated with a package tag.
|
|
9
|
+
*
|
|
10
|
+
* Skips deletion if the plan does not contain a valid tag name. Resolves gracefully
|
|
11
|
+
* if the release does not exist on GitHub (e.g., 404 status).
|
|
12
|
+
*
|
|
13
|
+
* @param plan Release plan containing the tag associated with the release to delete
|
|
14
|
+
* @param token GitHub authentication token
|
|
15
|
+
* @param repository Target repository
|
|
16
|
+
* @returns Promise that resolves when the release is deleted
|
|
17
|
+
*/
|
|
18
|
+
export async function deleteRelease(
|
|
19
|
+
plan: ReleasePlan,
|
|
20
|
+
token: string,
|
|
21
|
+
repository: GitRepository
|
|
22
|
+
): Promise<void> {
|
|
23
|
+
if (!plan.release?.tag?.name) {
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
/* istanbul ignore next */
|
|
29
|
+
const octokit = new Octokit({
|
|
30
|
+
auth: token,
|
|
31
|
+
log: { debug: () => {}, info: () => {}, warn: () => {}, error: () => {} },
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const { data: release } = await octokit.rest.repos.getReleaseByTag({
|
|
35
|
+
owner: repository.owner,
|
|
36
|
+
repo: repository.repo,
|
|
37
|
+
tag: plan.release.tag.name,
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
await octokit.rest.repos.deleteRelease({
|
|
41
|
+
owner: repository.owner,
|
|
42
|
+
repo: repository.repo,
|
|
43
|
+
release_id: release.id,
|
|
44
|
+
})
|
|
45
|
+
} catch (err) {
|
|
46
|
+
if ((err as { status?: number } | undefined)?.status === 404) {
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
throw err
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/github.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
import type { ReleasePlugin } from '@reelout/core'
|
|
5
|
+
import { version } from '../package.json'
|
|
6
|
+
import { createRelease } from './createRelease'
|
|
7
|
+
import { deleteRelease } from './deleteRelease'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Built-in plugin that creates GitHub releases for finalized release plans.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* **Lifecycle Stages:**
|
|
14
|
+
* - `publish`: Creates GitHub releases in reverse alphabetical package order (ensuring the root package release
|
|
15
|
+
* is created last). Automatically rolls back and deletes created releases if subsequent publishing stages fail.
|
|
16
|
+
*
|
|
17
|
+
* @throws {Error} If `context.repository` is not configured or `GITHUB_TOKEN` environment variable is missing.
|
|
18
|
+
* @returns A release plugin configured for GitHub release creation.
|
|
19
|
+
*/
|
|
20
|
+
const github = (): ReleasePlugin => ({
|
|
21
|
+
name: '@reelout/github',
|
|
22
|
+
version,
|
|
23
|
+
publish: async (context, next) => {
|
|
24
|
+
if (!context.repository) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
'A Git repository is required to create a GitHub release.'
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!context.env.GITHUB_TOKEN) {
|
|
31
|
+
throw new Error('The GITHUB_TOKEN environment variable is required.')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (context.dryRun) {
|
|
35
|
+
context.logger.debug('[DRY RUN] GitHub releases will not be created.')
|
|
36
|
+
return next(context)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const plans = context.plans.toSorted((a, b) =>
|
|
40
|
+
(a.package.name || '').localeCompare(b.package.name || '')
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
const token = context.env.GITHUB_TOKEN
|
|
44
|
+
|
|
45
|
+
const repository = context.repository
|
|
46
|
+
|
|
47
|
+
// Create releases in reverse order
|
|
48
|
+
// so that the root package release is created last,
|
|
49
|
+
// as it is often the most important one.
|
|
50
|
+
for (const plan of plans.toReversed()) {
|
|
51
|
+
await createRelease(context, plan, token, repository)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
return await next(context)
|
|
56
|
+
} catch (err) {
|
|
57
|
+
await Promise.allSettled(
|
|
58
|
+
plans.map((plan) => deleteRelease(plan, token, repository))
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
throw err
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
export default github
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
//
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
2
3
|
|
|
3
|
-
export
|
|
4
|
+
export * from './createRelease'
|
|
5
|
+
export * from './deleteRelease'
|
|
6
|
+
export * from './github'
|
|
7
|
+
export { default } from './github'
|
|
8
|
+
export * from './isRepositoryPublic'
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
import { Octokit } from '@octokit/rest'
|
|
5
|
+
import type { GitRepository } from '@reelout/core'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Check if the target GitHub repository is public.
|
|
9
|
+
*
|
|
10
|
+
* Uses the Octokit REST API with the provided token to fetch the
|
|
11
|
+
* visibility status of the specified repository.
|
|
12
|
+
*
|
|
13
|
+
* @param token GitHub authentication token
|
|
14
|
+
* @param repository Target repository
|
|
15
|
+
* @returns Promise that resolves to `true` if the repository is public
|
|
16
|
+
*/
|
|
17
|
+
export async function isRepositoryPublic(
|
|
18
|
+
token: string,
|
|
19
|
+
repository: GitRepository
|
|
20
|
+
): Promise<boolean> {
|
|
21
|
+
/* istanbul ignore next */
|
|
22
|
+
const octokit = new Octokit({
|
|
23
|
+
auth: token,
|
|
24
|
+
log: { debug: () => {}, info: () => {}, warn: () => {}, error: () => {} },
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const { data } = await octokit.rest.repos.get({
|
|
28
|
+
owner: repository.owner,
|
|
29
|
+
repo: repository.repo,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
return data.visibility === 'public'
|
|
33
|
+
}
|