-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(e2e): smoketest macOS .dmg files COMPASS-8709 #6582
Merged
+218
−30
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b7c235c
run smoketests on mac
lerouxb 2f29075
promisified async spawn helper rather
lerouxb c1147bb
the app might already exist
lerouxb afc47df
try and preserve permissions
lerouxb 545df56
print args
lerouxb 72bce49
we seem to need that
lerouxb 770ff84
basic test
lerouxb 98d02aa
all the webdriver logs
lerouxb 309b26d
really enable chromedriver's verbose logging
lerouxb 340acee
MOAR log output
lerouxb e9ff872
remove settings dir before starting
lerouxb 416fcc0
comment for clarification
lerouxb cb49d13
run this on the GUI machines
lerouxb 82b7497
ignore hadron-build-info.json
lerouxb 0b85081
Merge branch 'main' into test-dmg-2
lerouxb 5b0301c
comments
lerouxb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
fixtures | ||
.nyc_output | ||
coverage | ||
hadron-build-info.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { spawn } from 'child_process'; | ||
import type { SpawnOptions } from 'child_process'; | ||
|
||
export function execute( | ||
command: string, | ||
args: string[], | ||
options?: SpawnOptions | ||
): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
console.log(command, ...args); | ||
const p = spawn(command, args, { | ||
stdio: 'inherit', | ||
...options, | ||
}); | ||
p.on('error', (err: any) => { | ||
reject(err); | ||
}); | ||
p.on('close', (code: number | null, signal: NodeJS.Signals | null) => { | ||
if (code !== null) { | ||
if (code === 0) { | ||
resolve(); | ||
} else { | ||
reject( | ||
new Error(`${command} ${args.join(' ')} exited with code ${code}`) | ||
); | ||
} | ||
} else { | ||
if (signal !== null) { | ||
reject( | ||
new Error( | ||
`${command} ${args.join(' ')} exited with signal ${signal}` | ||
) | ||
); | ||
} else { | ||
// shouldn't happen | ||
reject( | ||
new Error( | ||
`${command} ${args.join(' ')} exited with no code or signal` | ||
) | ||
); | ||
} | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import path from 'path'; | ||
import { existsSync } from 'fs'; | ||
import type { InstalledAppInfo, Package } from './types'; | ||
import { execute } from './helpers'; | ||
|
||
export async function installMacDMG( | ||
appName: string, | ||
{ filepath }: Package | ||
): Promise<InstalledAppInfo> { | ||
const fullDestinationPath = `/Applications/${appName}.app`; | ||
|
||
if (existsSync(fullDestinationPath)) { | ||
// Would ideally just throw here, but unfortunately in CI the mac | ||
// environments aren't all clean so somewhere we have to remove it anyway. | ||
console.log(`${fullDestinationPath} already exists. Removing.`); | ||
await execute('rm', ['-rf', fullDestinationPath]); | ||
} | ||
|
||
await execute('hdiutil', ['attach', filepath]); | ||
try { | ||
await execute('cp', [ | ||
'-Rp', | ||
`/Volumes/${appName}/${appName}.app`, | ||
'/Applications', | ||
]); | ||
} finally { | ||
await execute('hdiutil', ['detach', `/Volumes/${appName}`]); | ||
} | ||
|
||
// see if the executable will run without being quarantined or similar | ||
await execute(`/Applications/${appName}.app/Contents/MacOS/${appName}`, [ | ||
'--version', | ||
]); | ||
|
||
if (process.env.HOME) { | ||
const settingsDir = path.resolve( | ||
process.env.HOME, | ||
'Library', | ||
'Application Support', | ||
appName | ||
); | ||
|
||
if (existsSync(settingsDir)) { | ||
console.log(`${settingsDir} already exists. Removing.`); | ||
await execute('rm', ['-rf', settingsDir]); | ||
} | ||
} | ||
|
||
return Promise.resolve({ | ||
appName, | ||
appPath: `/Applications/${appName}.app`, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export type Package = { | ||
filename: string; | ||
filepath: string; | ||
}; | ||
|
||
export type InstalledAppInfo = { | ||
appName: string; | ||
appPath: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ import { hideBin } from 'yargs/helpers'; | |
import https from 'https'; | ||
import { pick } from 'lodash'; | ||
import { handler as writeBuildInfo } from 'hadron-build/commands/info'; | ||
import type { InstalledAppInfo, Package } from './installers/types'; | ||
import { installMacDMG } from './installers/mac-dmg'; | ||
import { execute } from './installers/helpers'; | ||
|
||
const argv = yargs(hideBin(process.argv)) | ||
.scriptName('smoke-tests') | ||
|
@@ -137,6 +140,10 @@ async function run() { | |
writeBuildInfo(infoArgs); | ||
const buildInfo = JSON.parse(await fs.readFile(infoArgs.out, 'utf8')); | ||
|
||
if (!buildInfoIsCommon(buildInfo)) { | ||
throw new Error('buildInfo is missing'); | ||
} | ||
|
||
// filter the extensions given the platform (isWindows, isOSX, isUbuntu, isRHEL) and extension | ||
const { isWindows, isOSX, isRHEL, isUbuntu, extension } = context; | ||
|
||
|
@@ -150,9 +157,9 @@ async function run() { | |
|
||
if (!context.skipDownload) { | ||
await Promise.all( | ||
packages.map(async ({ name, filepath }) => { | ||
packages.map(async ({ filename, filepath }) => { | ||
await fs.mkdir(path.dirname(filepath), { recursive: true }); | ||
const url = `https://${context.bucketName}.s3.amazonaws.com/${context.bucketKeyPrefix}/${name}`; | ||
const url = `https://${context.bucketName}.s3.amazonaws.com/${context.bucketKeyPrefix}/${filename}`; | ||
console.log(url); | ||
return downloadFile(url, filepath); | ||
}) | ||
|
@@ -162,6 +169,24 @@ async function run() { | |
verifyPackagesExist(packages); | ||
|
||
// TODO(COMPASS-8533): extract or install each package and then test the Compass binary | ||
for (const pkg of packages) { | ||
let appInfo: InstalledAppInfo | undefined = undefined; | ||
|
||
console.log('installing', pkg.filepath); | ||
|
||
if (pkg.filename.endsWith('.dmg')) { | ||
appInfo = await installMacDMG(buildInfo.productName, pkg); | ||
} | ||
|
||
// TODO: all the other installers go here | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ie. the other sub-task tickets in this same story. |
||
|
||
if (appInfo) { | ||
console.log('testing', appInfo.appPath); | ||
await testInstalledApp(appInfo); | ||
} else { | ||
console.log(`no app got installed for ${pkg.filename}`); | ||
} | ||
} | ||
} | ||
|
||
function platformFromContext( | ||
|
@@ -189,6 +214,18 @@ type PackageFilterConfig = Pick< | |
|
||
// subsets of the hadron-build info result | ||
|
||
const commonKeys = ['productName']; | ||
type CommonBuildInfo = Record<typeof commonKeys[number], string>; | ||
|
||
function buildInfoIsCommon(buildInfo: any): buildInfo is CommonBuildInfo { | ||
for (const key of commonKeys) { | ||
if (!buildInfo[key]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
const windowsFilenameKeys = [ | ||
'windows_setup_filename', | ||
'windows_msi_filename', | ||
|
@@ -245,11 +282,6 @@ function buildInfoIsRHEL(buildInfo: any): buildInfo is RHELBuildInfo { | |
return true; | ||
} | ||
|
||
type Package = { | ||
name: string; | ||
filepath: string; | ||
}; | ||
|
||
function getFilteredPackages( | ||
compassDir: string, | ||
buildInfo: any, | ||
|
@@ -282,11 +314,11 @@ function getFilteredPackages( | |
const extension = config.extension; | ||
|
||
return names | ||
.filter((name) => !extension || name.endsWith(extension)) | ||
.map((name) => { | ||
.filter((filename) => !extension || filename.endsWith(extension)) | ||
.map((filename) => { | ||
return { | ||
name, | ||
filepath: path.join(compassDir, 'dist', name), | ||
filename, | ||
filepath: path.join(compassDir, 'dist', filename), | ||
}; | ||
}); | ||
} | ||
|
@@ -333,6 +365,28 @@ function verifyPackagesExist(packages: Package[]): void { | |
} | ||
} | ||
|
||
function testInstalledApp(appInfo: InstalledAppInfo): Promise<void> { | ||
return execute( | ||
'npm', | ||
[ | ||
'run', | ||
'--unsafe-perm', | ||
'test-packaged', | ||
'--workspace', | ||
'compass-e2e-tests', | ||
'--', | ||
'--test-filter=time-to-first-query', | ||
], | ||
{ | ||
env: { | ||
...process.env, | ||
COMPASS_APP_NAME: appInfo.appName, | ||
COMPASS_APP_PATH: appInfo.appPath, | ||
}, | ||
} | ||
); | ||
} | ||
|
||
run() | ||
.then(function () { | ||
console.log('done'); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oof. I missed -gui when I first mapped this out and didn't notice for days.