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 ( ) ;
0 commit comments