@@ -19,6 +19,47 @@ import {
1919 assertCommonBuildInfo ,
2020} from './helpers/buildinfo' ;
2121
22+ const SUPPORTED_PLATFORMS = [ 'win32' , 'darwin' , 'linux' ] as const ;
23+ const SUPPORTED_ARCHS = [ 'x64' , 'arm64' ] as const ;
24+
25+ function isSupportedPlatform (
26+ value : unknown
27+ ) : value is typeof SUPPORTED_PLATFORMS [ number ] {
28+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
29+ return SUPPORTED_PLATFORMS . includes ( value as any ) ;
30+ }
31+
32+ function isSupportedArch (
33+ value : unknown
34+ ) : value is typeof SUPPORTED_ARCHS [ number ] {
35+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
36+ return SUPPORTED_ARCHS . includes ( value as any ) ;
37+ }
38+
39+ function getDefaultPlatform ( ) {
40+ const {
41+ platform,
42+ env : { PLATFORM } ,
43+ } = process ;
44+ if ( isSupportedPlatform ( PLATFORM ) ) {
45+ return PLATFORM ;
46+ } else if ( isSupportedPlatform ( platform ) ) {
47+ return platform ;
48+ }
49+ }
50+
51+ function getDefaultArch ( ) {
52+ const {
53+ arch,
54+ env : { ARCH } ,
55+ } = process ;
56+ if ( isSupportedArch ( ARCH ) ) {
57+ return ARCH ;
58+ } else if ( isSupportedArch ( arch ) ) {
59+ return arch ;
60+ }
61+ }
62+
2263const argv = yargs ( hideBin ( process . argv ) )
2364 . scriptName ( 'smoke-tests' )
2465 . detectLocale ( false )
@@ -32,26 +73,15 @@ const argv = yargs(hideBin(process.argv))
3273 type : 'string' ,
3374 default : process . env . EVERGREEN_BUCKET_KEY_PREFIX ,
3475 } )
35- . option ( 'version' , {
36- type : 'string' ,
37- // For dev versions we need this from evergreen. For beta or stable (or by
38- // default, ie. when testing a locally packaged app) we get it from the
39- // package.json
40- default : process . env . DEV_VERSION_IDENTIFIER ,
41- description :
42- 'Will be read from packages/compass/package.json if not specified' ,
43- } )
4476 . option ( 'platform' , {
45- type : 'string' ,
46- choices : [ 'win32' , 'darwin' , 'linux' ] ,
77+ choices : SUPPORTED_PLATFORMS ,
4778 demandOption : true ,
48- default : process . env . PLATFORM ?? process . platform ,
79+ default : getDefaultPlatform ( ) ,
4980 } )
5081 . option ( 'arch' , {
51- type : 'string' ,
52- choices : [ 'x64' , 'arm64' ] ,
82+ choices : SUPPORTED_ARCHS ,
5383 demandOption : true ,
54- default : process . env . ARCH ?? process . arch ,
84+ default : getDefaultArch ( ) ,
5585 } )
5686 . option ( 'package' , {
5787 type : 'string' ,
@@ -65,7 +95,7 @@ const argv = yargs(hideBin(process.argv))
6595 'linux_tar' ,
6696 'linux_rpm' ,
6797 'rhel_tar' ,
68- ] ,
98+ ] as const ,
6999 demandOption : true ,
70100 description : 'Which package to test' ,
71101 } )
@@ -88,7 +118,6 @@ const argv = yargs(hideBin(process.argv))
88118type SmokeTestsContext = {
89119 bucketName ?: string ;
90120 bucketKeyPrefix ?: string ;
91- version ?: string ;
92121 platform : 'win32' | 'darwin' | 'linux' ;
93122 arch : 'x64' | 'arm64' ;
94123 package :
@@ -112,48 +141,49 @@ async function readJson<T extends object>(...segments: string[]): Promise<T> {
112141 return result as T ;
113142}
114143
115- async function readPackageVersion ( packagePath : string ) {
116- const pkg = await readJson ( packagePath , 'package.json' ) ;
117- assert (
118- 'version' in pkg && typeof pkg . version === 'string' ,
119- 'Expected a package version'
120- ) ;
121- return pkg . version ;
122- }
123-
124144async function run ( ) {
125- const parsedArgs = argv . parseSync ( ) ;
126-
127- const context = parsedArgs as SmokeTestsContext ;
145+ const context : SmokeTestsContext = argv . parseSync ( ) ;
128146
129147 console . log (
130148 'context' ,
131149 pick ( context , [
132150 'skipDownload' ,
133151 'bucketName' ,
134152 'bucketKeyPrefix' ,
135- 'version' ,
136153 'platform' ,
137154 'arch' ,
138155 'package' ,
139156 ] )
140157 ) ;
141158
142159 const compassDir = path . resolve ( __dirname , '..' , '..' , 'packages' , 'compass' ) ;
143- // use the specified DEV_VERSION_IDENTIFIER if set or load version from packages/compass/package.json
144- const version = context . version ?? ( await readPackageVersion ( compassDir ) ) ;
145160 const outPath = path . resolve ( __dirname , 'hadron-build-info.json' ) ;
146161
147162 // build-info
148163 const infoArgs = {
149164 format : 'json' ,
150165 dir : compassDir ,
151- version,
152166 platform : context . platform ,
153167 arch : context . arch ,
154168 out : outPath ,
155169 } ;
156170 console . log ( 'infoArgs' , infoArgs ) ;
171+
172+ // These are known environment variables that will affect the way
173+ // writeBuildInfo works. Log them as a reminder and for our own sanity
174+ console . log (
175+ 'info env vars' ,
176+ pick ( process . env , [
177+ 'HADRON_DISTRIBUTION' ,
178+ 'HADRON_APP_VERSION' ,
179+ 'HADRON_PRODUCT' ,
180+ 'HADRON_PRODUCT_NAME' ,
181+ 'HADRON_READONLY' ,
182+ 'HADRON_ISOLATED' ,
183+ 'DEV_VERSION_IDENTIFIER' ,
184+ 'IS_RHEL' ,
185+ ] )
186+ ) ;
157187 writeBuildInfo ( infoArgs ) ;
158188 const buildInfo = await readJson ( infoArgs . out ) ;
159189
0 commit comments