@@ -2,14 +2,16 @@ import assert from 'node:assert/strict';
22import fs from 'node:fs' ;
33import path from 'node:path' ;
44import createDebug from 'debug' ;
5+ import { pick } from 'lodash' ;
56
67import { handler as writeBuildInfo } from 'hadron-build/commands/info' ;
78
89import { type PackageKind } from './packages' ;
910import { type SmokeTestsContextWithSandbox } from './context' ;
10- import { pick } from 'lodash ' ;
11+ import { createSandbox } from './directories ' ;
1112
1213const debug = createDebug ( 'compass:smoketests:build-info' ) ;
14+ const COMPASS_PATH = path . resolve ( __dirname , '../../compass' ) ;
1315
1416const SUPPORTED_CHANNELS = [ 'dev' , 'beta' , 'stable' ] as const ;
1517
@@ -229,16 +231,18 @@ export function readPackageDetails(
229231 return getPackageDetails ( kind , result ) ;
230232}
231233
232- export function writeAndReadPackageDetails (
233- context : SmokeTestsContextWithSandbox
234- ) : PackageDetails {
235- const compassDir = path . resolve ( __dirname , '../../compass' ) ;
234+ export function writeAndReadPackageDetails ( {
235+ package : packageKind ,
236+ platform,
237+ arch,
238+ sandboxPath,
239+ } : SmokeTestsContextWithSandbox ) : PackageDetails {
236240 const infoArgs = {
237241 format : 'json' ,
238- dir : compassDir ,
239- platform : context . platform ,
240- arch : context . arch ,
241- out : path . resolve ( context . sandboxPath , 'target.json' ) ,
242+ dir : COMPASS_PATH ,
243+ platform,
244+ arch,
245+ out : path . resolve ( sandboxPath , 'target.json' ) ,
242246 } ;
243247 debug ( { infoArgs } ) ;
244248
@@ -258,5 +262,30 @@ export function writeAndReadPackageDetails(
258262 ] )
259263 ) ;
260264 writeBuildInfo ( infoArgs ) ;
261- return readPackageDetails ( context . package , infoArgs . out ) ;
265+ return readPackageDetails ( packageKind , infoArgs . out ) ;
266+ }
267+
268+ export function getCompassVersionFromBuildInfo ( ) : string {
269+ const out = path . resolve ( createSandbox ( ) , 'target.json' ) ;
270+ // We're hardcoding the platform and arch here because we're only interested in the version
271+ if ( typeof process . env . HADRON_DISTRIBUTION !== 'string' ) {
272+ // TODO: Ideally we would interface directly with the `Target` from the "hadron-build" package so we could pass this directly
273+ process . env . HADRON_DISTRIBUTION = 'compass' ;
274+ }
275+ writeBuildInfo ( {
276+ format : 'json' ,
277+ dir : COMPASS_PATH ,
278+ platform : 'linux' ,
279+ arch : 'x64' ,
280+ out,
281+ } ) ;
282+ const result = readJson ( out ) ;
283+ assert ( typeof result === 'object' , 'Expected hadron to write an object' ) ;
284+ assert (
285+ 'version' in result ,
286+ 'Expected hadron to write an object with a version'
287+ ) ;
288+ const { version } = result ;
289+ assert ( typeof version === 'string' , 'Expected version to be a string' ) ;
290+ return version ;
262291}
0 commit comments