@@ -5,6 +5,7 @@ import path from 'node:path'
55import { notNullish } from '@antfu/utils'
66import { cyan , green , red } from 'ansis'
77import { $fetch } from 'ofetch'
8+ import { glob } from 'tinyglobby'
89
910export async function sendRelease (
1011 options : ChangelogOptions ,
@@ -152,7 +153,6 @@ export async function hasTagOnGitHub(tag: string, options: ChangelogOptions) {
152153
153154export async function uploadAssets ( options : ChangelogOptions , assets : string | string [ ] ) {
154155 const headers = getHeaders ( options )
155-
156156 let assetList : string [ ] = [ ]
157157 if ( typeof assets === 'string' ) {
158158 assetList = assets . split ( ',' ) . map ( s => s . trim ( ) ) . filter ( Boolean )
@@ -163,32 +163,58 @@ export async function uploadAssets(options: ChangelogOptions, assets: string | s
163163 ) . filter ( Boolean )
164164 }
165165
166+ // Expand glob patterns to actual file paths
167+ const expandedAssets : string [ ] = [ ]
168+ for ( const pattern of assetList ) {
169+ try {
170+ // Use the pattern directly without shell expansion
171+ const matches = await glob ( pattern )
172+ if ( matches . length ) {
173+ expandedAssets . push ( ...matches )
174+ }
175+ else {
176+ // If no matches found, treat as literal path
177+ expandedAssets . push ( pattern )
178+ }
179+ }
180+ catch ( error ) {
181+ console . error ( red ( `Failed to process glob pattern "${ pattern } ": ${ error } ` ) )
182+ // Keep the original pattern as fallback
183+ expandedAssets . push ( pattern )
184+ }
185+ }
186+
166187 // Get the release by tag to obtain the upload_url
167188 const release = await $fetch ( `https://${ options . baseUrlApi } /repos/${ options . releaseRepo } /releases/tags/${ options . to } ` , {
168189 headers,
169190 } )
170191
171- for ( const asset of assetList ) {
192+ for ( const asset of expandedAssets ) {
172193 const filePath = path . resolve ( asset )
173- const fileData = await fs . readFile ( filePath )
174- const fileName = path . basename ( filePath )
175- const contentType = 'application/octet-stream'
176-
177- const uploadUrl = release . upload_url . replace ( '{?name,label}' , `?name=${ encodeURIComponent ( fileName ) } ` )
178- console . log ( cyan ( `Uploading ${ fileName } ...` ) )
179194 try {
180- await $fetch ( uploadUrl , {
181- method : 'POST' ,
182- headers : {
183- ...headers ,
184- 'Content-Type' : contentType ,
185- } ,
186- body : fileData ,
187- } )
188- console . log ( green ( `Uploaded ${ fileName } successfully.` ) )
195+ const fileData = await fs . readFile ( filePath )
196+ const fileName = path . basename ( filePath )
197+ const contentType = 'application/octet-stream'
198+
199+ const uploadUrl = release . upload_url . replace ( '{?name,label}' , `?name=${ encodeURIComponent ( fileName ) } ` )
200+ console . log ( cyan ( `Uploading ${ fileName } ...` ) )
201+ try {
202+ await $fetch ( uploadUrl , {
203+ method : 'POST' ,
204+ headers : {
205+ ...headers ,
206+ 'Content-Type' : contentType ,
207+ } ,
208+ body : fileData ,
209+ } )
210+ console . log ( green ( `Uploaded ${ fileName } successfully.` ) )
211+ }
212+ catch ( error ) {
213+ console . error ( red ( `Failed to upload ${ fileName } : ${ error } ` ) )
214+ }
189215 }
190216 catch ( error ) {
191- console . error ( red ( `Failed to upload ${ fileName } : ${ error } ` ) )
217+ console . error ( red ( `Failed to read file ${ filePath } : ${ error } ` ) )
192218 }
193219 }
194220}
0 commit comments