Skip to content

Commit 07c5ad0

Browse files
committed
no need to fret about the correct filename
1 parent 866c367 commit 07c5ad0

File tree

3 files changed

+93
-63
lines changed

3 files changed

+93
-63
lines changed

packages/compass-smoke-tests/src/cli.ts

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import { createSandbox } from './directories';
1717
import { downloadFile } from './downloads';
1818
import { type PackageKind, SUPPORTED_PACKAGES } from './packages';
19+
import { getLatestRelease } from './releases';
1920
import { type SmokeTestsContext } from './context';
2021
import { installMacZIP } from './installers/mac-zip';
2122

@@ -145,60 +146,6 @@ async function getTestSubject(
145146
}
146147
}
147148

148-
type Arch = 'arm64' | 'x64';
149-
150-
type PlatformShortName =
151-
| 'darwin-arm64'
152-
| 'darwin-x64'
153-
| 'windows'
154-
| 'linux_deb'
155-
| 'linux_rpm';
156-
157-
function getPlatformShortName(
158-
arch: Arch,
159-
kind: PackageKind
160-
): PlatformShortName {
161-
if (arch === 'arm64') {
162-
if (kind === 'osx_dmg' || kind === 'osx_zip') {
163-
return 'darwin-arm64';
164-
}
165-
}
166-
if (arch === 'x64') {
167-
if (kind === 'osx_dmg' || kind === 'osx_zip') {
168-
return 'darwin-x64';
169-
}
170-
if (
171-
kind === 'windows_setup' ||
172-
kind === 'windows_msi' ||
173-
kind === 'windows_zip'
174-
) {
175-
return 'windows';
176-
}
177-
if (kind === 'linux_deb' || kind === 'linux_tar') {
178-
return 'linux_deb';
179-
}
180-
if (kind === 'linux_rpm' || kind === 'rhel_tar') {
181-
return 'linux_rpm';
182-
}
183-
}
184-
185-
throw new Error(`Unsupported arch/kind combo: ${arch}/${kind}`);
186-
}
187-
188-
async function getLatestRelease(
189-
channel: 'dev' | 'beta' | 'stable',
190-
arch: Arch,
191-
kind: PackageKind,
192-
forceDownload?: boolean
193-
): Promise<string> {
194-
const shortName = getPlatformShortName(arch, kind);
195-
196-
return await downloadFile({
197-
url: `http://compass.mongodb.com/api/v2/download/latest/compass/${channel}/${shortName}`,
198-
clearCache: forceDownload,
199-
});
200-
}
201-
202149
function getInstaller(kind: PackageKind) {
203150
if (kind === 'osx_dmg') {
204151
return installMacDMG;

packages/compass-smoke-tests/src/downloads.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ensureDownloadsDirectory } from './directories';
77

88
type DownloadFileOptions = {
99
url: string;
10-
targetFilename?: string;
10+
targetFilename: string;
1111
clearCache?: boolean;
1212
};
1313

@@ -18,14 +18,6 @@ export async function downloadFile({
1818
}: DownloadFileOptions): Promise<string> {
1919
const response = await fetch(url);
2020

21-
if (!targetFilename) {
22-
// if no filename was specified, work out the filename based on the final
23-
// URL the way a browser would
24-
targetFilename = path.basename(new URL(response.url).pathname);
25-
}
26-
27-
assert(targetFilename, 'Expected a filename');
28-
2921
const etag = response.headers.get('etag');
3022
assert(etag, 'Expected an ETag header');
3123
const cleanEtag = etag.match(/[0-9a-fA-F]/g)?.join('');
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { downloadFile } from './downloads';
2+
import { type PackageKind } from './packages';
3+
4+
type Arch = 'arm64' | 'x64';
5+
6+
type PlatformShortName =
7+
| 'darwin-arm64'
8+
| 'darwin-x64'
9+
| 'windows'
10+
| 'linux_deb'
11+
| 'linux_rpm';
12+
13+
function getPlatformShortName(
14+
arch: Arch,
15+
kind: PackageKind
16+
): PlatformShortName {
17+
if (arch === 'arm64') {
18+
if (kind === 'osx_dmg' || kind === 'osx_zip') {
19+
return 'darwin-arm64';
20+
}
21+
}
22+
if (arch === 'x64') {
23+
if (kind === 'osx_dmg' || kind === 'osx_zip') {
24+
return 'darwin-x64';
25+
}
26+
if (
27+
kind === 'windows_setup' ||
28+
kind === 'windows_msi' ||
29+
kind === 'windows_zip'
30+
) {
31+
return 'windows';
32+
}
33+
if (kind === 'linux_deb' || kind === 'linux_tar') {
34+
return 'linux_deb';
35+
}
36+
if (kind === 'linux_rpm' || kind === 'rhel_tar') {
37+
return 'linux_rpm';
38+
}
39+
}
40+
41+
throw new Error(`Unsupported arch/kind combo: ${arch}/${kind}`);
42+
}
43+
44+
type PlatformExtension = 'dmg' | 'exe' | 'deb' | 'rpm';
45+
46+
function getPlatformExtension(
47+
arch: Arch,
48+
kind: PackageKind
49+
): PlatformExtension {
50+
if (arch === 'arm64') {
51+
if (kind === 'osx_dmg' || kind === 'osx_zip') {
52+
return 'dmg';
53+
}
54+
}
55+
if (arch === 'x64') {
56+
if (kind === 'osx_dmg' || kind === 'osx_zip') {
57+
return 'dmg';
58+
}
59+
if (
60+
kind === 'windows_setup' ||
61+
kind === 'windows_msi' ||
62+
kind === 'windows_zip'
63+
) {
64+
return 'exe';
65+
}
66+
if (kind === 'linux_deb' || kind === 'linux_tar') {
67+
return 'deb';
68+
}
69+
if (kind === 'linux_rpm' || kind === 'rhel_tar') {
70+
return 'rpm';
71+
}
72+
}
73+
74+
throw new Error(`Unsupported arch/kind combo: ${arch}/${kind}`);
75+
}
76+
77+
export async function getLatestRelease(
78+
channel: 'dev' | 'beta' | 'stable',
79+
arch: Arch,
80+
kind: PackageKind,
81+
forceDownload?: boolean
82+
): Promise<string> {
83+
const shortName = getPlatformShortName(arch, kind);
84+
const extension = getPlatformExtension(arch, kind);
85+
86+
return await downloadFile({
87+
url: `http://compass.mongodb.com/api/v2/download/latest/compass/${channel}/${shortName}`,
88+
targetFilename: `latest-${channel}.${extension}`,
89+
clearCache: forceDownload,
90+
});
91+
}

0 commit comments

Comments
 (0)