import execa from 'execa' ; import fs from 'fs' ; import { join } from 'path' ; import { REPO_ROOT } from '@kbn/utils' ; import { getBuildNumber } from './get_build_number' ; interface Options { isRelease : boolean ; versionQualifier ? : string ; pkg : { version : string ; } ; } type ResolvedType < T extends Promise < any > > = T extends Promise < infer X > ? X : never ; export type VersionInfo = ResolvedType < ReturnType < typeof getVersionInfo > > ; export async function getVersionInfo ( { isRelease , versionQualifier , pkg } ) { const buildVersion = pkg . version . concat ( versionQualifier ? `-${ versionQualifier }` : '' , isRelease ? '' : '-SNAPSHOT' ) ; const buildSha = fs . existsSync ( join ( REPO_ROOT , '.git' ) ) ? ( await execa ( 'git' , [ 'rev-parse' , 'HEAD' ] , { cwd : REPO_ROOT } ) ) . stdout : process . env . GIT_COMMIT || process . env . BUILDKITE_COMMIT || '' ; return { buildSha , buildVersion , buildNumber : await getBuildNumber ( ) , } ; }