@@ -19,6 +19,47 @@ import {
19
19
assertCommonBuildInfo ,
20
20
} from './helpers/buildinfo' ;
21
21
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
+
22
63
const argv = yargs ( hideBin ( process . argv ) )
23
64
. scriptName ( 'smoke-tests' )
24
65
. detectLocale ( false )
@@ -32,26 +73,15 @@ const argv = yargs(hideBin(process.argv))
32
73
type : 'string' ,
33
74
default : process . env . EVERGREEN_BUCKET_KEY_PREFIX ,
34
75
} )
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
- } )
44
76
. option ( 'platform' , {
45
- type : 'string' ,
46
- choices : [ 'win32' , 'darwin' , 'linux' ] ,
77
+ choices : SUPPORTED_PLATFORMS ,
47
78
demandOption : true ,
48
- default : process . env . PLATFORM ?? process . platform ,
79
+ default : getDefaultPlatform ( ) ,
49
80
} )
50
81
. option ( 'arch' , {
51
- type : 'string' ,
52
- choices : [ 'x64' , 'arm64' ] ,
82
+ choices : SUPPORTED_ARCHS ,
53
83
demandOption : true ,
54
- default : process . env . ARCH ?? process . arch ,
84
+ default : getDefaultArch ( ) ,
55
85
} )
56
86
. option ( 'package' , {
57
87
type : 'string' ,
@@ -65,7 +95,7 @@ const argv = yargs(hideBin(process.argv))
65
95
'linux_tar' ,
66
96
'linux_rpm' ,
67
97
'rhel_tar' ,
68
- ] ,
98
+ ] as const ,
69
99
demandOption : true ,
70
100
description : 'Which package to test' ,
71
101
} )
@@ -88,7 +118,6 @@ const argv = yargs(hideBin(process.argv))
88
118
type SmokeTestsContext = {
89
119
bucketName ?: string ;
90
120
bucketKeyPrefix ?: string ;
91
- version ?: string ;
92
121
platform : 'win32' | 'darwin' | 'linux' ;
93
122
arch : 'x64' | 'arm64' ;
94
123
package :
@@ -112,48 +141,49 @@ async function readJson<T extends object>(...segments: string[]): Promise<T> {
112
141
return result as T ;
113
142
}
114
143
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
-
124
144
async function run ( ) {
125
- const parsedArgs = argv . parseSync ( ) ;
126
-
127
- const context = parsedArgs as SmokeTestsContext ;
145
+ const context : SmokeTestsContext = argv . parseSync ( ) ;
128
146
129
147
console . log (
130
148
'context' ,
131
149
pick ( context , [
132
150
'skipDownload' ,
133
151
'bucketName' ,
134
152
'bucketKeyPrefix' ,
135
- 'version' ,
136
153
'platform' ,
137
154
'arch' ,
138
155
'package' ,
139
156
] )
140
157
) ;
141
158
142
159
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 ) ) ;
145
160
const outPath = path . resolve ( __dirname , 'hadron-build-info.json' ) ;
146
161
147
162
// build-info
148
163
const infoArgs = {
149
164
format : 'json' ,
150
165
dir : compassDir ,
151
- version,
152
166
platform : context . platform ,
153
167
arch : context . arch ,
154
168
out : outPath ,
155
169
} ;
156
170
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
+ ) ;
157
187
writeBuildInfo ( infoArgs ) ;
158
188
const buildInfo = await readJson ( infoArgs . out ) ;
159
189
0 commit comments