Skip to content

Commit 51a0f39

Browse files
authored
feat(cubestore): Installer - download binary without GH API (#5885)
1 parent fcb5c5e commit 51a0f39

File tree

1 file changed

+29
-54
lines changed

1 file changed

+29
-54
lines changed

rust/cubestore/js-wrapper/src/download.ts

Lines changed: 29 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -33,64 +33,39 @@ async function fetchRelease(version: string) {
3333
return data;
3434
}
3535

36-
function parseInfoFromAssetName(assetName: string): { target: string, type: string, format: string } | null {
37-
if (assetName.startsWith('cubestored-')) {
38-
const fileName = assetName.slice('cubestored-'.length);
39-
const targetAndType = fileName.slice(0, fileName.indexOf('.'));
40-
const format = fileName.slice(fileName.indexOf('.') + 1);
41-
42-
if (targetAndType.endsWith('-shared')) {
43-
return {
44-
target: targetAndType.slice(0, -'-shared'.length),
45-
format,
46-
type: 'shared'
47-
};
48-
}
49-
50-
return {
51-
target: targetAndType,
52-
format,
53-
type: 'static'
54-
};
55-
}
56-
57-
return null;
58-
}
59-
6036
export async function downloadBinaryFromRelease() {
6137
// eslint-disable-next-line global-require
6238
const { version } = require('../../package.json');
63-
64-
const release = await fetchRelease(version);
65-
if (release) {
66-
if (release.assets.length === 0) {
67-
throw new Error(
68-
`There are no artifacts for Cube Store v${version}. Most probably it is still building. Please try again later.`
69-
);
70-
}
71-
72-
const currentTarget = getTarget();
73-
74-
for (const asset of release.assets) {
75-
const assetInfo = parseInfoFromAssetName(asset.name);
76-
if (assetInfo && assetInfo.target === currentTarget
77-
&& assetInfo.type === 'static' && assetInfo.format === 'tar.gz'
78-
) {
79-
const cubestorePath = getCubeStorePath();
80-
81-
return downloadAndExtractFile(asset.browser_download_url, {
82-
cwd: cubestorePath,
83-
showProgress: true,
84-
});
39+
const cubestorePath = getCubeStorePath();
40+
const currentTarget = getTarget();
41+
42+
const url = `https://github.com/cube-js/cube.js/releases/download/v${version}/cubestored-${currentTarget}.tar.gz`;
43+
44+
try {
45+
await downloadAndExtractFile(url, {
46+
cwd: cubestorePath,
47+
showProgress: true,
48+
});
49+
} catch (e: any) {
50+
if (e.toString().includes('Not Found')) {
51+
const release = await fetchRelease(version);
52+
if (release) {
53+
if (release.assets.length === 0) {
54+
throw new Error(
55+
`There are no artifacts for Cube Store v${version}. Most probably it is still building. Please try again later.`
56+
);
57+
}
58+
59+
throw new Error(
60+
`Cube Store v${version} Artifact for ${currentTarget} doesn't exist. Most probably it is still building. Please try again later.`
61+
);
62+
} else {
63+
throw new Error(
64+
`Unable to find Cube Store release v${version}. Most probably it was removed.`
65+
);
8566
}
67+
} else {
68+
throw e;
8669
}
87-
88-
throw new Error(
89-
`Cube Store v${version} Artifact for ${process.platform} is not found. Most probably it is still building. Please try again later.`
90-
);
9170
}
92-
93-
throw new Error(
94-
`Unable to find Cube Store release v${version}. Most probably it was removed.`
95-
);
9671
}

0 commit comments

Comments
 (0)