@@ -11,3 +11,71 @@ export async function validateGit(_opts: ReleaseOpts) {
1111 ) ;
1212 }
1313}
14+
15+ export async function createAndPushTag ( opts : ReleaseOpts ) {
16+ console . log ( `Creating tag v${ opts . version } ...` ) ;
17+ try {
18+ // Create tag and force update if it exists
19+ await $ ( { cwd : opts . root } ) `git tag -f v${ opts . version } ` ;
20+
21+ // Push tag with force to ensure it's updated
22+ await $ ( { cwd : opts . root } ) `git push origin v${ opts . version } -f` ;
23+
24+ console . log ( `✅ Tag v${ opts . version } created and pushed` ) ;
25+ } catch ( err ) {
26+ console . error ( "❌ Failed to create or push tag" ) ;
27+ throw err ;
28+ }
29+ }
30+
31+ export async function createGitHubRelease ( opts : ReleaseOpts ) {
32+ console . log ( "Creating GitHub release..." ) ;
33+
34+ try {
35+ // Get the current tag name (should be the tag created during the release process)
36+ const { stdout : currentTag } = await $ ( {
37+ cwd : opts . root ,
38+ } ) `git describe --tags --exact-match` ;
39+ const tagName = currentTag . trim ( ) ;
40+
41+ console . log ( `Looking for existing release for ${ opts . version } ` ) ;
42+
43+ // Check if a release with this version name already exists
44+ const { stdout : releaseJson } = await $ ( {
45+ cwd : opts . root ,
46+ } ) `gh release list --json name,tagName` ;
47+ const releases = JSON . parse ( releaseJson ) ;
48+ const existingRelease = releases . find (
49+ ( r : any ) => r . name === opts . version ,
50+ ) ;
51+
52+ if ( existingRelease ) {
53+ console . log (
54+ `Updating release ${ opts . version } to point to new tag ${ tagName } ` ,
55+ ) ;
56+ await $ ( {
57+ cwd : opts . root ,
58+ } ) `gh release edit ${ existingRelease . tagName } --tag ${ tagName } ` ;
59+ } else {
60+ console . log (
61+ `Creating new release ${ opts . version } pointing to tag ${ tagName } ` ,
62+ ) ;
63+ await $ ( {
64+ cwd : opts . root ,
65+ } ) `gh release create ${ tagName } --title ${ opts . version } --generate-notes` ;
66+
67+ // Check if this is a pre-release (contains -rc. or similar)
68+ if ( opts . version . includes ( "-" ) ) {
69+ await $ ( {
70+ cwd : opts . root ,
71+ } ) `gh release edit ${ tagName } --prerelease` ;
72+ }
73+ }
74+
75+ console . log ( "✅ GitHub release created/updated" ) ;
76+ } catch ( err ) {
77+ console . error ( "❌ Failed to create GitHub release" ) ;
78+ console . warn ( "! You may need to create the release manually" ) ;
79+ throw err ;
80+ }
81+ }
0 commit comments