@@ -4,6 +4,12 @@ import {getArtifactMetadata} from './git'
4
4
import { spawn } from 'child_process'
5
5
import * as fs from 'fs'
6
6
7
+ async function sleep ( milliseconds : number ) : Promise < void > {
8
+ return new Promise < void > ( ( resolve , _reject ) => {
9
+ setTimeout ( resolve , milliseconds )
10
+ } )
11
+ }
12
+
7
13
export async function getViaCIArtifacts (
8
14
architecture : string ,
9
15
githubToken ?: string
@@ -21,35 +27,51 @@ export async function getViaCIArtifacts(
21
27
22
28
const octokit = githubToken ? new Octokit ( { auth : githubToken } ) : new Octokit ( )
23
29
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 )
29
38
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
+ } )
35
44
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
+ }
40
51
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
+ )
46
58
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 } ` )
49
71
50
72
return {
51
73
artifactName,
52
- id : `ci-artifacts-${ tarGzArtifact . updated_at } ` ,
74
+ id : `ci-artifacts-${ updatedAt } ` ,
53
75
download : async (
54
76
outputDirectory : string ,
55
77
verbose : number | boolean = false
0 commit comments