Skip to content

Commit

Permalink
Add autoUpdatable flag and refactor installer logic (#6623)
Browse files Browse the repository at this point in the history
Add autoUpdatable flag and refactor installer logic
  • Loading branch information
kraenhansen authored Jan 16, 2025
1 parent 84ffd4d commit 1de0c4c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 34 deletions.
29 changes: 25 additions & 4 deletions packages/compass-e2e-tests/helpers/smoke-test/build-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export function assertBuildInfoIsRHEL(
export type PackageDetails = {
kind: PackageKind;
filename: string;
autoUpdatable: boolean;
} & (
| {
kind: 'windows_setup' | 'windows_msi' | 'windows_zip';
Expand Down Expand Up @@ -124,16 +125,36 @@ export function getPackageDetails(
kind === 'windows_zip'
) {
assertBuildInfoIsWindows(buildInfo);
return { kind, buildInfo, filename: buildInfo[`${kind}_filename`] };
return {
kind,
buildInfo,
filename: buildInfo[`${kind}_filename`],
autoUpdatable: kind === 'windows_setup',
};
} else if (kind === 'osx_dmg' || kind === 'osx_zip') {
assertBuildInfoIsOSX(buildInfo);
return { kind, buildInfo, filename: buildInfo[`${kind}_filename`] };
return {
kind,
buildInfo,
filename: buildInfo[`${kind}_filename`],
autoUpdatable: true,
};
} else if (kind === 'linux_deb' || kind === 'linux_tar') {
assertBuildInfoIsUbuntu(buildInfo);
return { kind, buildInfo, filename: buildInfo[`${kind}_filename`] };
return {
kind,
buildInfo,
filename: buildInfo[`${kind}_filename`],
autoUpdatable: false,
};
} else if (kind === 'linux_rpm' || kind === 'rhel_tar') {
assertBuildInfoIsRHEL(buildInfo);
return { kind, buildInfo, filename: buildInfo[`${kind}_filename`] };
return {
kind,
buildInfo,
filename: buildInfo[`${kind}_filename`],
autoUpdatable: false,
};
} else {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
throw new Error(`Unsupported package kind: ${kind}`);
Expand Down
64 changes: 34 additions & 30 deletions packages/compass-e2e-tests/smoke-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import {
} from './helpers/smoke-test/build-info';
import { createSandbox } from './helpers/smoke-test/directories';
import { downloadFile } from './helpers/smoke-test/downloads';
import { SUPPORTED_PACKAGES } from './helpers/smoke-test/packages';
import {
type PackageKind,
SUPPORTED_PACKAGES,
} from './helpers/smoke-test/packages';
import { type SmokeTestsContext } from './helpers/smoke-test/context';
import { installMacZIP } from './installers/mac-zip';

Expand Down Expand Up @@ -98,7 +101,14 @@ const argv = yargs(hideBin(process.argv))
description: 'Use the local package instead of downloading',
});

type TestSubject = PackageDetails & { filepath: string };
type TestSubject = PackageDetails & {
filepath: string;
/**
* Is the package unsigned?
* In which case we'll expect auto-updating to fail.
*/
unsigned?: boolean;
};

/**
* Either finds the local package or downloads the package
Expand All @@ -120,6 +130,7 @@ async function getTestSubject(
return {
...details,
filepath: path.resolve(compassDistPath, details.filename),
unsigned: true,
};
} else {
assert(
Expand All @@ -137,6 +148,16 @@ async function getTestSubject(
}
}

function getInstaller(kind: PackageKind) {
if (kind === 'osx_dmg') {
return installMacDMG;
} else if (kind === 'osx_zip') {
return installMacZIP;
} else {
throw new Error(`Installer for '${kind}' is not yet implemented`);
}
}

async function run() {
const context: SmokeTestsContext = {
...argv.parseSync(),
Expand All @@ -157,43 +178,26 @@ async function run() {
])
);

const cleanups: (() => void | Promise<void>)[] = [
() => {
console.log('Cleaning up sandbox');
fs.rmSync(context.sandboxPath, { recursive: true });
},
];
const { kind, buildInfo, filepath } = await getTestSubject(context);
const install = getInstaller(kind);

try {
const appName = buildInfo.productName;
if (kind === 'osx_dmg') {
const { appPath, uninstall } = installMacDMG({
appName,
filepath,
destinationPath: context.sandboxPath,
});
cleanups.push(uninstall);

runTest({ appName, appPath });
} else if (kind === 'osx_zip') {
const { appPath, uninstall } = installMacZIP({
appName,
filepath,
destinationPath: context.sandboxPath,
});
cleanups.push(uninstall);
const { appPath, uninstall } = install({
appName,
filepath,
destinationPath: context.sandboxPath,
});

try {
runTest({ appName, appPath });
} else {
throw new Error(`Testing '${kind}' packages is not yet implemented`);
} finally {
await uninstall();
}
} finally {
// Chain the cleanup functions in reverse order
await cleanups
.slice()
.reverse()
.reduce((previous, cleanup) => previous.then(cleanup), Promise.resolve());
console.log('Cleaning up sandbox');
fs.rmSync(context.sandboxPath, { recursive: true });
}
}

Expand Down

0 comments on commit 1de0c4c

Please sign in to comment.