11const MINIMUM_RELEASE_GAP_MS = 6 * 60 * 60 * 1000 ;
2- // Waits before each retry of a read that failed with a 5xx or a network error.
3- const RETRY_DELAYS_MS = [ 2_000 , 5_000 , 10_000 ] ;
4-
5- const defaultSleep = ( ms ) => new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
6-
7- // Octokit reports network failures as status 500, so this also covers resets.
8- // Auth, permission, validation, and GraphQL query errors fail at once.
9- async function withRetry ( label , request , { core, sleep = defaultSleep } = { } ) {
10- for ( let attempt = 0 ; ; attempt ++ ) {
11- try {
12- return await request ( ) ;
13- } catch ( error ) {
14- const delay = RETRY_DELAYS_MS [ attempt ] ;
15- if ( delay === undefined || ! ( error ?. status >= 500 ) ) throw error ;
16- core ?. warning ( `${ label } failed with status ${ error . status } . Retrying in ${ delay / 1000 } s.` ) ;
17- await sleep ( delay ) ;
18- }
19- }
20- }
212
223function repositoryDefaultBranch ( context ) {
234 const branch = context . payload . repository ?. default_branch ;
@@ -27,22 +8,21 @@ function repositoryDefaultBranch(context) {
278 return branch ;
289}
2910
30- async function assertCommitOnDefaultBranch ( { github, context, core , sleep , sha } ) {
11+ async function assertCommitOnDefaultBranch ( { github, context, sha } ) {
3112 const defaultBranch = repositoryDefaultBranch ( context ) ;
32- const basehead = `${ sha } ...${ defaultBranch } ` ;
33- const { data : comparison } = await withRetry (
34- `Compare ${ basehead } ` ,
35- ( ) => github . rest . repos . compareCommitsWithBasehead ( { ...context . repo , basehead, per_page : 1 } ) ,
36- { core, sleep } ,
37- ) ;
13+ const { data : comparison } = await github . rest . repos . compareCommitsWithBasehead ( {
14+ ...context . repo ,
15+ basehead : `${ sha } ...${ defaultBranch } ` ,
16+ per_page : 1 ,
17+ } ) ;
3818 if ( comparison . status !== "ahead" && comparison . status !== "identical" ) {
3919 throw new Error (
4020 `Release commit ${ sha } is not contained in ${ defaultBranch } (${ comparison . status } ).` ,
4121 ) ;
4222 }
4323}
4424
45- async function assertReleaseSource ( { github, context, core , sleep , releaseChannel } ) {
25+ async function assertReleaseSource ( { github, context, releaseChannel } ) {
4626 if ( releaseChannel === "preview" ) return ;
4727 if ( releaseChannel !== "stable" && releaseChannel !== "nightly" ) {
4828 throw new Error ( `Unsupported release channel: ${ releaseChannel } ` ) ;
@@ -55,7 +35,7 @@ async function assertReleaseSource({ github, context, core, sleep, releaseChanne
5535 ) ;
5636 }
5737
58- await assertCommitOnDefaultBranch ( { github, context, core , sleep , sha : context . sha } ) ;
38+ await assertCommitOnDefaultBranch ( { github, context, sha : context . sha } ) ;
5939}
6040
6141const isNightlyTag = ( tag ) => / ^ v .* - n i g h t l y \. / . test ( tag ) || tag . startsWith ( "nightly-v" ) ;
@@ -76,15 +56,11 @@ const RELEASES_QUERY = `
7656// Returns the nightly with the newest publishedAt. Release order follows the
7757// tagged commit date, not publication, so every page is read unless `isSettled`
7858// says the newest nightly seen so far already decides the caller's answer.
79- async function findLatestNightly ( { github, context, core , sleep , isSettled = ( ) => false } ) {
59+ async function findLatestNightly ( { github, context, isSettled = ( ) => false } ) {
8060 let latest ;
8161 let cursor = null ;
8262 do {
83- const { repository } = await withRetry (
84- "List releases" ,
85- ( ) => github . graphql ( RELEASES_QUERY , { ...context . repo , cursor } ) ,
86- { core, sleep } ,
87- ) ;
63+ const { repository } = await github . graphql ( RELEASES_QUERY , { ...context . repo , cursor } ) ;
8864 const { nodes, pageInfo } = repository . releases ;
8965 for ( const release of nodes ) {
9066 if ( release . isDraft || ! release . publishedAt || ! isNightlyTag ( release . tagName ) ) continue ;
@@ -98,10 +74,10 @@ async function findLatestNightly({ github, context, core, sleep, isSettled = ()
9874 return latest ;
9975}
10076
101- async function shouldReleaseNightly ( { github, context, core, sleep , now = Date . now ( ) } ) {
77+ async function shouldReleaseNightly ( { github, context, core, now = Date . now ( ) } ) {
10278 const isInGap = ( release ) => now - Date . parse ( release . publishedAt ) < MINIMUM_RELEASE_GAP_MS ;
10379 // Any nightly inside the gap means the newest one is too, so stop reading.
104- const lastNightly = await findLatestNightly ( { github, context, core , sleep , isSettled : isInGap } ) ;
80+ const lastNightly = await findLatestNightly ( { github, context, isSettled : isInGap } ) ;
10581
10682 if ( ! lastNightly ) {
10783 core . info ( "No published nightly found. Proceeding with release." ) ;
@@ -114,12 +90,11 @@ async function shouldReleaseNightly({ github, context, core, sleep, now = Date.n
11490 return false ;
11591 }
11692
117- const basehead = `${ tag } ...${ context . sha } ` ;
118- const { data : comparison } = await withRetry (
119- `Compare ${ basehead } ` ,
120- ( ) => github . rest . repos . compareCommitsWithBasehead ( { ...context . repo , basehead, per_page : 1 } ) ,
121- { core, sleep } ,
122- ) ;
93+ const { data : comparison } = await github . rest . repos . compareCommitsWithBasehead ( {
94+ ...context . repo ,
95+ basehead : `${ tag } ...${ context . sha } ` ,
96+ per_page : 1 ,
97+ } ) ;
12398 if ( comparison . status !== "ahead" ) {
12499 core . info ( `Candidate commit is ${ comparison . status } relative to ${ tag } . Skipping.` ) ;
125100 return false ;
@@ -129,18 +104,14 @@ async function shouldReleaseNightly({ github, context, core, sleep, now = Date.n
129104 return true ;
130105}
131106
132- async function resolveLatestNightlyCommit ( { github, context, core, sleep } ) {
133- const lastNightly = await findLatestNightly ( { github, context, core , sleep } ) ;
107+ async function resolveLatestNightlyCommit ( { github, context, core } ) {
108+ const lastNightly = await findLatestNightly ( { github, context } ) ;
134109 if ( ! lastNightly ) {
135110 throw new Error ( "No published nightly found. Stable releases build the latest nightly commit." ) ;
136111 }
137112
138113 const tag = lastNightly . tagName ;
139- const { data : commit } = await withRetry (
140- `Read commit ${ tag } ` ,
141- ( ) => github . rest . repos . getCommit ( { ...context . repo , ref : tag } ) ,
142- { core, sleep } ,
143- ) ;
114+ const { data : commit } = await github . rest . repos . getCommit ( { ...context . repo , ref : tag } ) ;
144115 const version = / ^ (?: n i g h t l y - ) ? v ( \d + \. \d + \. \d + ) - n i g h t l y \. / . exec ( tag ) ?. [ 1 ] ;
145116 if ( ! version ) {
146117 throw new Error ( `Cannot derive a stable version from nightly tag ${ tag } .` ) ;
0 commit comments