11import fs from 'node:fs/promises' ;
22import path from 'node:path' ;
3- import { execFile } from 'node:child_process' ;
4- import { promisify } from 'node:util' ;
53
64const token = process . env . GH_TOKEN || process . env . GITHUB_TOKEN ;
75const repository = process . env . GH_REPO || process . env . GITHUB_REPOSITORY ;
@@ -10,7 +8,6 @@ const installerDir = path.resolve(
108 process . env . RELEASE_INSTALLER_DIR || 'src-tauri/target/release/bundle/nsis'
119) ;
1210const latestJsonPath = path . resolve ( process . env . RELEASE_LATEST_JSON_PATH || 'latest.json' ) ;
13- const execFileAsync = promisify ( execFile ) ;
1411
1512if ( ! token ) throw new Error ( 'GH_TOKEN or GITHUB_TOKEN is not set' ) ;
1613if ( ! repository ) throw new Error ( 'GH_REPO or GITHUB_REPOSITORY is not set' ) ;
@@ -39,17 +36,33 @@ async function findInstaller(dir) {
3936
4037async function readTagNotes ( tagName ) {
4138 try {
42- const ref = `refs/tags/${ tagName } ` ;
43- const { stdout : objectType } = await execFileAsync ( 'git' , [ 'cat-file' , '-t' , ref ] ) ;
44- if ( objectType . trim ( ) !== 'tag' ) {
45- console . log ( `Tag ${ tagName } is not an annotated tag, fallback to generated release notes` ) ;
39+ const refResponse = await githubApi ( `/repos/${ owner } /${ repo } /git/ref/tags/${ encodeURIComponent ( tagName ) } ` , {
40+ okStatuses : [ 200 , 404 ] ,
41+ } ) ;
42+
43+ if ( refResponse . status === 404 ) {
44+ console . log ( `Tag ref ${ tagName } not found on GitHub, fallback to generated release notes` ) ;
45+ return '' ;
46+ }
47+
48+ const target = refResponse . json ?. object ;
49+ if ( ! target || target . type !== 'tag' || ! target . sha ) {
50+ console . log ( `Tag ${ tagName } is not an annotated tag on GitHub, fallback to generated release notes` ) ;
51+ return '' ;
52+ }
53+
54+ const tagObject = await githubApi ( `/repos/${ owner } /${ repo } /git/tags/${ target . sha } ` , {
55+ okStatuses : [ 200 , 404 ] ,
56+ } ) ;
57+
58+ if ( tagObject . status === 404 ) {
59+ console . log ( `Annotated tag object for ${ tagName } not found on GitHub, fallback to generated release notes` ) ;
4660 return '' ;
4761 }
4862
49- const { stdout } = await execFileAsync ( 'git' , [ 'for-each-ref' , ref , '--format=%(contents)' ] ) ;
50- return stdout . trim ( ) ;
63+ return ( tagObject . json ?. message || '' ) . trim ( ) ;
5164 } catch ( error ) {
52- console . warn ( `Failed to read git tag notes for ${ tagName } : ${ error . message } ` ) ;
65+ console . warn ( `Failed to read GitHub tag notes for ${ tagName } : ${ error . message } ` ) ;
5366 return '' ;
5467 }
5568}
0 commit comments