@@ -4,6 +4,12 @@ import {getArtifactMetadata} from './git'
44import { spawn } from 'child_process'
55import * as fs from 'fs'
66
7+ async function sleep ( milliseconds : number ) : Promise < void > {
8+ return new Promise < void > ( ( resolve , _reject ) => {
9+ setTimeout ( resolve , milliseconds )
10+ } )
11+ }
12+
713export async function getViaCIArtifacts (
814 architecture : string ,
915 githubToken ?: string
@@ -21,35 +27,51 @@ export async function getViaCIArtifacts(
2127
2228 const octokit = githubToken ? new Octokit ( { auth : githubToken } ) : new Octokit ( )
2329
24- const ciArtifactsResponse = await octokit . repos . getReleaseByTag ( {
25- owner,
26- repo,
27- tag : 'ci-artifacts'
28- } )
30+ const {
31+ name,
32+ updated_at : updatedAt ,
33+ browser_download_url : url
34+ } = await ( async ( ) => {
35+ let error : Error | undefined
36+ for ( const seconds of [ 0 , 5 , 10 , 15 , 20 , 40 ] ) {
37+ if ( seconds ) await sleep ( seconds )
2938
30- if ( ciArtifactsResponse . status !== 200 ) {
31- throw new Error (
32- `Failed to get ci-artifacts release from the ${ owner } / ${ repo } repo: ${ ciArtifactsResponse . status } `
33- )
34- }
39+ const ciArtifactsResponse = await octokit . repos . getReleaseByTag ( {
40+ owner ,
41+ repo,
42+ tag : 'ci-artifacts'
43+ } )
3544
36- core . info ( `Found ci-artifacts release: ${ ciArtifactsResponse . data . html_url } ` )
37- const tarGzArtifact = ciArtifactsResponse . data . assets . find ( asset =>
38- asset . name . endsWith ( '.tar.gz' )
39- )
45+ if ( ciArtifactsResponse . status !== 200 ) {
46+ error = new Error (
47+ `Failed to get ci-artifacts release from the ${ owner } /${ repo } repo: ${ ciArtifactsResponse . status } `
48+ )
49+ continue
50+ }
4051
41- if ( ! tarGzArtifact ) {
42- throw new Error (
43- `Failed to find a .tar.gz artifact in the ci-artifacts release of the ${ owner } /${ repo } repo`
44- )
45- }
52+ core . info (
53+ `Found ci-artifacts release: ${ ciArtifactsResponse . data . html_url } `
54+ )
55+ const tarGzArtifact = ciArtifactsResponse . data . assets . find ( asset =>
56+ asset . name . endsWith ( '.tar.gz' )
57+ )
4658
47- const url = tarGzArtifact . browser_download_url
48- core . info ( `Found ${ tarGzArtifact . name } at ${ url } ` )
59+ if ( ! tarGzArtifact ) {
60+ error = new Error (
61+ `Failed to find a .tar.gz artifact in the ci-artifacts release of the ${ owner } /${ repo } repo`
62+ )
63+ continue
64+ }
65+
66+ return tarGzArtifact
67+ }
68+ throw error
69+ } ) ( )
70+ core . info ( `Found ${ name } at ${ url } ` )
4971
5072 return {
5173 artifactName,
52- id : `ci-artifacts-${ tarGzArtifact . updated_at } ` ,
74+ id : `ci-artifacts-${ updatedAt } ` ,
5375 download : async (
5476 outputDirectory : string ,
5577 verbose : number | boolean = false
0 commit comments