11import * as core from '@actions/core' ;
2+ import fetch from 'node-fetch' ;
23import chalk from 'chalk' ;
34import { platform } from 'os' ;
45import { execaCommand } from 'execa' ;
56import ora from 'ora' ;
67import semver from 'semver' ;
78import path from 'path' ;
9+ import pWaitFor from 'p-wait-for' ;
810
911const binaries = {
1012 darwin : 'cloudquery_darwin_amd64' ,
@@ -16,6 +18,24 @@ const resolveDownloadUrl = async (version: string, binary: string) => {
1618 return `https://github.com/cloudquery/cloudquery/releases/download/${ tag } /${ binary } ` ;
1719} ;
1820
21+ const assetExists = async ( url : string ) => {
22+ try {
23+ core . debug ( `Checking if ${ url } exists` ) ;
24+ const response = await fetch ( url , { redirect : 'follow' } ) ;
25+ core . debug ( `Response status: ${ response . status } ` ) ;
26+ core . debug ( `Response statusText: ${ response . statusText } ` ) ;
27+ core . debug ( `Response ok: ${ response . ok } ` ) ;
28+ const ok = response . ok ;
29+ if ( ! ok ) {
30+ core . info ( `${ url } does not exist, retrying...` ) ;
31+ }
32+ return ok ;
33+ } catch ( error ) {
34+ core . error ( error as Error ) ;
35+ return false ;
36+ }
37+ } ;
38+
1939export const installBinary = async ( version : string ) => {
2040 const binary = binaries [ platform ( ) as keyof typeof binaries ] ;
2141 if ( ! binary ) {
@@ -24,6 +44,10 @@ export const installBinary = async (version: string) => {
2444 const message = `version '${ chalk . green ( version ) } '` ;
2545 const spinner = ora ( `Downloading ${ message } of CloudQuery` ) . start ( ) ;
2646 const downloadUrl = await resolveDownloadUrl ( version , binary ) ;
47+ await pWaitFor ( ( ) => assetExists ( downloadUrl ) , {
48+ interval : 5000 ,
49+ timeout : 60000 ,
50+ } ) ;
2751 await execaCommand ( `curl -L ${ downloadUrl } -o cloudquery` , {
2852 stdout : 'inherit' ,
2953 } ) ;
0 commit comments