@@ -53,22 +53,36 @@ async function uploadModuleToAppStore(pkgName, marketplaceId, version, minimumMX
5353
5454async function getGithubAssetUrl ( ) {
5555 console . log ( "Retrieving informations from Github Tag" ) ;
56- const request = await fetch ( "GET" , "https://api.github.com/repos/mendix/native-widgets/releases?per_page=10" ) ;
57- const data = ( await request ) ?? [ ] ;
58- const releaseId = data . find ( info => info . tag_name === process . env . TAG ) ?. id ;
59- if ( ! releaseId ) {
60- throw new Error ( `Could not find release with tag ${ process . env . TAG } on GitHub` ) ;
61- }
62- const assetsRequest = await fetch (
63- "GET" ,
64- `https://api.github.com/repos/mendix/native-widgets/releases/${ releaseId } /assets`
65- ) ;
66- const assetsData = ( await assetsRequest ) ?? [ ] ;
67- const downloadUrl = assetsData . find ( asset => asset . name . endsWith ( ".mpk" ) ) ?. browser_download_url ;
68- if ( ! downloadUrl ) {
69- throw new Error ( `Could not retrieve MPK url from GitHub release with tag ${ process . env . TAG } ` ) ;
56+ const tag = process . env . TAG ;
57+ // Use direct tag lookup endpoint instead of listing releases
58+ // This avoids pagination issues and is more reliable
59+ const maxRetries = 5 ;
60+ const retryDelayMs = 5000 ;
61+
62+ for ( let attempt = 1 ; attempt <= maxRetries ; attempt ++ ) {
63+ console . log ( `Attempt ${ attempt } /${ maxRetries } : Fetching release for tag ${ tag } ` ) ;
64+
65+ const releaseData = await fetch (
66+ "GET" ,
67+ `https://api.github.com/repos/mendix/native-widgets/releases/tags/${ tag } `
68+ ) ;
69+
70+ if ( releaseData && releaseData . id ) {
71+ console . log ( `Found release: ${ releaseData . name } (id: ${ releaseData . id } )` ) ;
72+ const downloadUrl = releaseData . assets ?. find ( asset => asset . name . endsWith ( ".mpk" ) ) ?. browser_download_url ;
73+ if ( ! downloadUrl ) {
74+ throw new Error ( `Could not retrieve MPK url from GitHub release with tag ${ tag } ` ) ;
75+ }
76+ return downloadUrl ;
77+ }
78+
79+ if ( attempt < maxRetries ) {
80+ console . log ( `Release not found yet, waiting ${ retryDelayMs / 1000 } s before retry...` ) ;
81+ await new Promise ( resolve => setTimeout ( resolve , retryDelayMs ) ) ;
82+ }
7083 }
71- return downloadUrl ;
84+
85+ throw new Error ( `Could not find release with tag ${ tag } on GitHub after ${ maxRetries } attempts` ) ;
7286}
7387
7488async function createDraft ( marketplaceId , version , minimumMXVersion ) {
@@ -143,6 +157,12 @@ async function fetch(method, url, body, additionalHeaders) {
143157 } else if ( response . status === 503 ) {
144158 throw new Error ( `Fetching Failed. "${ url } " is unreachable (Code ${ response . status } ).` ) ;
145159 } else if ( response . status !== 200 && response . status !== 201 ) {
160+ try {
161+ const responseBody = await response . text ( ) ;
162+ console . error ( `Failed API response code: ${ response . status } content: ${ responseBody } ` ) ;
163+ } catch {
164+ console . error ( `Failed to parse error response body.` ) ;
165+ }
146166 throw new Error ( `Fetching Failed (Code ${ response . status } ). ${ response . statusText } ` ) ;
147167 } else if ( response . ok ) {
148168 return response . json ( ) ;
0 commit comments