Skip to content

Commit 5269660

Browse files
committed
feat: Added script for creating GH releases
1 parent 6f7043d commit 5269660

File tree

6 files changed

+79
-13
lines changed

6 files changed

+79
-13
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"docs:generate": "pnpm --filter @prozilla-os/docs run generate",
3232
"packages:build": "pnpm -r --sequential --filter prozilla-os... build",
3333
"packages:update": "npx changeset && pnpm changeset version",
34-
"packages:release": "pnpm changeset publish"
34+
"packages:release": "pnpm changeset publish && pnpm vite-node scripts/releasePackage.ts"
3535
},
3636
"workspaces": [
3737
"packages/*",
@@ -42,6 +42,7 @@
4242
"url": "git+https://github.com/prozilla-os/ProzillaOS.git"
4343
},
4444
"dependencies": {
45+
"commander": "^12.1.0",
4546
"pnpm": "^9.5.0"
4647
},
4748
"devDependencies": {

packages/shared/src/configs/app.vite.config.d.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/shared/src/configs/index.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/releasePackage.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import fs from "node:fs";
2+
import path from "node:path";
3+
import { execSync } from "node:child_process";
4+
import { version, name } from "../packages/prozilla-os/package.json";
5+
import os from "node:os";
6+
import { ANSI } from "../packages/core/src/constants";
7+
8+
const getChangelog = (): string => {
9+
const changelogPath = path.resolve(__dirname, "../packages/prozilla-os/CHANGELOG.md");
10+
const changelog = fs.readFileSync(changelogPath, "utf-8");
11+
12+
const changelogEntries = changelog.split("\n## ");
13+
14+
const changelogEntry = changelogEntries.find((entry) => entry.startsWith(version));
15+
16+
if (changelogEntry) {
17+
return changelogEntry;
18+
} else {
19+
return `No changelog entry found for version ${version}`;
20+
}
21+
};
22+
23+
const createGitHubRelease = (): void => {
24+
const changelogFilePath = path.join(os.tmpdir(), `CHANGELOG-${version}.md`);
25+
26+
try {
27+
console.log(`Context: ${ANSI.decoration.bold}${name}${ANSI.reset}\n`);
28+
29+
const changelog = getChangelog();
30+
const tagName = `prozilla-os@${version}`;
31+
const releaseTitle = `Release ${version}`;
32+
33+
// Write changelog to a temporary file
34+
fs.writeFileSync(changelogFilePath, changelog);
35+
36+
// Push all tags, not recommended
37+
console.log(`${ANSI.fg.yellow}Pushing tags...${ANSI.reset}`);
38+
execSync("git push --tags", {
39+
stdio: "inherit"
40+
});
41+
42+
// Create a new release
43+
console.log(`${ANSI.fg.yellow}Creating release...${ANSI.reset}`);
44+
execSync(`gh release create ${tagName} --title "${releaseTitle}" --notes-file "${changelogFilePath}"`, {
45+
stdio: "inherit"
46+
});
47+
48+
console.log(`\n${ANSI.fg.green}✓ Release created:${ANSI.reset} ${releaseTitle}`);
49+
} catch (error) {
50+
if ((error as Record<string, string>).stdout) {
51+
console.error((error as Record<string, string>).stdout.toString());
52+
}
53+
if ((error as Record<string, string>).stderr) {
54+
console.error((error as Record<string, string>).stderr.toString());
55+
}
56+
57+
console.error(`${ANSI.fg.red}⚠ Failed to create release:${ANSI.reset} ${(error as Error).message}`);
58+
process.exit(1);
59+
} finally {
60+
// Clean up the temporary file
61+
fs.unlinkSync(changelogFilePath);
62+
}
63+
};
64+
65+
createGitHubRelease();

tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/* Modules */
88
"module": "ESNext",
99
"moduleResolution": "Bundler",
10-
"types": ["vite/client", "vite-plugin-svgr/client"],
10+
"types": ["vite/client", "vite-plugin-svgr/client", "node"],
1111
"allowUmdGlobalAccess": true,
1212
"resolveJsonModule": true,
1313

@@ -35,7 +35,8 @@
3535
}
3636
},
3737
"include": [
38-
"packages/**/*"
38+
"packages/**/*",
39+
"scripts/**/*"
3940
],
4041
"exclude": [
4142
"**/node_modules/**/*",

0 commit comments

Comments
 (0)