11#!/usr/bin/env npx ts-node
2+ import { spawnSync } from 'child_process' ;
23import { createWriteStream , existsSync , promises as fs } from 'fs' ;
34import path from 'path' ;
45import yargs from 'yargs' ;
@@ -7,6 +8,9 @@ import { hideBin } from 'yargs/helpers';
78import https from 'https' ;
89import { pick } from 'lodash' ;
910import { handler as writeBuildInfo } from 'hadron-build/commands/info' ;
11+ import type { InstalledAppInfo , Package } from './installers/types' ;
12+ import { installMacDMG } from './installers/mac-dmg' ;
13+ import { assertSpawnSyncResult } from './installers/helpers' ;
1014
1115const argv = yargs ( hideBin ( process . argv ) )
1216 . scriptName ( 'smoke-tests' )
@@ -137,6 +141,10 @@ async function run() {
137141 writeBuildInfo ( infoArgs ) ;
138142 const buildInfo = JSON . parse ( await fs . readFile ( infoArgs . out , 'utf8' ) ) ;
139143
144+ if ( ! buildInfoIsCommon ( buildInfo ) ) {
145+ throw new Error ( 'buildInfo is missing' ) ;
146+ }
147+
140148 // filter the extensions given the platform (isWindows, isOSX, isUbuntu, isRHEL) and extension
141149 const { isWindows, isOSX, isRHEL, isUbuntu, extension } = context ;
142150
@@ -150,9 +158,9 @@ async function run() {
150158
151159 if ( ! context . skipDownload ) {
152160 await Promise . all (
153- packages . map ( async ( { name , filepath } ) => {
161+ packages . map ( async ( { filename , filepath } ) => {
154162 await fs . mkdir ( path . dirname ( filepath ) , { recursive : true } ) ;
155- const url = `https://${ context . bucketName } .s3.amazonaws.com/${ context . bucketKeyPrefix } /${ name } ` ;
163+ const url = `https://${ context . bucketName } .s3.amazonaws.com/${ context . bucketKeyPrefix } /${ filename } ` ;
156164 console . log ( url ) ;
157165 return downloadFile ( url , filepath ) ;
158166 } )
@@ -162,6 +170,24 @@ async function run() {
162170 verifyPackagesExist ( packages ) ;
163171
164172 // TODO(COMPASS-8533): extract or install each package and then test the Compass binary
173+ for ( const pkg of packages ) {
174+ let appInfo : InstalledAppInfo | undefined = undefined ;
175+
176+ console . log ( 'installing' , pkg . filepath ) ;
177+
178+ if ( pkg . filename . endsWith ( '.dmg' ) ) {
179+ appInfo = await installMacDMG ( buildInfo . productName , pkg ) ;
180+ }
181+
182+ // TODO: all the other installers go here
183+
184+ if ( appInfo ) {
185+ console . log ( 'testing' , appInfo . appPath ) ;
186+ testInstalledApp ( appInfo ) ;
187+ } else {
188+ console . log ( `no app got installed for ${ pkg . filename } ` ) ;
189+ }
190+ }
165191}
166192
167193function platformFromContext (
@@ -189,6 +215,18 @@ type PackageFilterConfig = Pick<
189215
190216// subsets of the hadron-build info result
191217
218+ const commonKeys = [ 'productName' ] ;
219+ type CommonBuildInfo = Record < typeof commonKeys [ number ] , string > ;
220+
221+ function buildInfoIsCommon ( buildInfo : any ) : buildInfo is CommonBuildInfo {
222+ for ( const key of commonKeys ) {
223+ if ( ! buildInfo [ key ] ) {
224+ return false ;
225+ }
226+ }
227+ return true ;
228+ }
229+
192230const windowsFilenameKeys = [
193231 'windows_setup_filename' ,
194232 'windows_msi_filename' ,
@@ -245,11 +283,6 @@ function buildInfoIsRHEL(buildInfo: any): buildInfo is RHELBuildInfo {
245283 return true ;
246284}
247285
248- type Package = {
249- name : string ;
250- filepath : string ;
251- } ;
252-
253286function getFilteredPackages (
254287 compassDir : string ,
255288 buildInfo : any ,
@@ -282,11 +315,11 @@ function getFilteredPackages(
282315 const extension = config . extension ;
283316
284317 return names
285- . filter ( ( name ) => ! extension || name . endsWith ( extension ) )
286- . map ( ( name ) => {
318+ . filter ( ( filename ) => ! extension || filename . endsWith ( extension ) )
319+ . map ( ( filename ) => {
287320 return {
288- name ,
289- filepath : path . join ( compassDir , 'dist' , name ) ,
321+ filename ,
322+ filepath : path . join ( compassDir , 'dist' , filename ) ,
290323 } ;
291324 } ) ;
292325}
@@ -333,6 +366,32 @@ function verifyPackagesExist(packages: Package[]): void {
333366 }
334367}
335368
369+ function testInstalledApp ( appInfo : InstalledAppInfo ) {
370+ const result = spawnSync (
371+ 'npm' ,
372+ [
373+ 'run' ,
374+ '--unsafe-perm' ,
375+ 'test-packaged' ,
376+ '--workspace' ,
377+ 'compass-e2e-tests' ,
378+ '--' ,
379+ '--test-filter=time-to-first-query' ,
380+ ] ,
381+ {
382+ encoding : 'utf8' ,
383+ stdio : 'inherit' ,
384+ env : {
385+ ...process . env ,
386+ COMPASS_APP_NAME : appInfo . appName ,
387+ COMPASS_APP_PATH : appInfo . appPath ,
388+ } ,
389+ }
390+ ) ;
391+
392+ assertSpawnSyncResult ( result , 'npm run test-packaged' ) ;
393+ }
394+
336395run ( )
337396 . then ( function ( ) {
338397 console . log ( 'done' ) ;
0 commit comments