@@ -26,10 +26,10 @@ function getSha() {
2626
2727function tagExists ( tag ) {
2828 try {
29- exec ( `gh api repos/ ${ process . env . GITHUB_REPOSITORY } /git/ref/tags/ ${ tag } ` , {
30- stdio : "ignore" ,
31- } ) ;
32- return true ;
29+ const result = exec (
30+ `gh api repos/ ${ process . env . GITHUB_REPOSITORY } /git/matching-refs/tags/ ${ tag } `
31+ ) ;
32+ return JSON . parse ( result ) . length > 0 ;
3333 } catch {
3434 return false ;
3535 }
@@ -44,47 +44,23 @@ function createTag(tag, sha) {
4444}
4545
4646async function createRelease ( version , tgzPath , body = "" ) {
47- const repo = process . env . GITHUB_REPOSITORY ;
48- if ( ! repo ) throw new Error ( "GITHUB_REPOSITORY not found" ) ;
49-
50- console . log ( `🚀 Creating GitHub Release: ${ version } ` ) ;
47+ const sha = getSha ( ) ;
5148
52- const prerelease = isPrerelease ( version ) ;
49+ console . log ( `Creating GitHub Release & Tag: ${ version } ` ) ;
5350
54- const payload = {
55- tag_name : version ,
56- name : version ,
57- body : body || `Release ${ version } ` ,
58- draft : true ,
59- prerelease,
60- } ;
61-
62- const tmp = ".release.json" ;
63- writeFileSync ( tmp , JSON . stringify ( payload ) ) ;
64-
65- const releaseJson = exec (
66- `gh api repos/${ repo } /releases -X POST --input ${ tmp } `
67- ) ;
51+ const prereleaseFlag = isPrerelease ( version ) ? "--prerelease" : "" ;
52+ const notes = body || `Release ${ version } ` ;
53+ const assetPath = tgzPath ? path . resolve ( tgzPath ) : "" ;
6854
69- const release = JSON . parse ( releaseJson ) ;
70- console . log ( `Release created (id=${ release . id } )` ) ;
71-
72- if ( tgzPath ) {
73- const resolved = path . resolve ( tgzPath ) ;
74-
75- console . log ( `Uploading asset: ${ resolved } ` ) ;
76-
77- exec (
78- `gh api "${ release . upload_url . replace ( / \{ .* $ / , "" ) } ?name=install.tgz" \
79- -X POST \
80- -H "Content-Type: application/gzip" \
81- --input "${ resolved } "`
82- ) ;
83- }
55+ let command = `gh release create ${ version } ${ assetPath } \
56+ --target ${ sha } \
57+ --title "${ version } " \
58+ --notes "${ notes } " \
59+ ${ prereleaseFlag } ` ;
8460
85- exec ( `gh release publish ${ version } ` ) ;
61+ exec ( command , { stdio : "inherit" } ) ;
8662
87- return release ;
63+ console . log ( `Release ${ version } successfully published.` ) ;
8864}
8965
9066module . exports = { getRepoInfo, getSha, tagExists, createTag, createRelease } ;
0 commit comments