Skip to content

Commit 7f1cec4

Browse files
authored
fix: wait for CLI binary to exist (#519)
Fixes #510
1 parent 3b16ac6 commit 7f1cec4

File tree

3 files changed

+200
-0
lines changed

3 files changed

+200
-0
lines changed

package-lock.json

Lines changed: 174 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
"@actions/core": "1.10.1",
2828
"chalk": "5.3.0",
2929
"execa": "8.0.1",
30+
"node-fetch": "^3.3.2",
3031
"ora": "8.0.1",
32+
"p-wait-for": "^5.0.2",
3133
"semver": "7.6.2"
3234
},
3335
"engines": {

src/main.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as core from '@actions/core';
2+
import fetch from 'node-fetch';
23
import chalk from 'chalk';
34
import { platform } from 'os';
45
import { execaCommand } from 'execa';
56
import ora from 'ora';
67
import semver from 'semver';
78
import path from 'path';
9+
import pWaitFor from 'p-wait-for';
810

911
const 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+
1939
export 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

Comments
 (0)