From 39dfa60755b6c3be249647119ccec0693202b74a Mon Sep 17 00:00:00 2001 From: Brian Seeders Date: Tue, 8 Jun 2021 12:38:49 -0400 Subject: [PATCH 1/5] [CI] Restore old version_info behavior when .git directory is present --- src/dev/build/lib/version_info.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/dev/build/lib/version_info.ts b/src/dev/build/lib/version_info.ts index 6be34a54e24f8..739fea30595e9 100644 --- a/src/dev/build/lib/version_info.ts +++ b/src/dev/build/lib/version_info.ts @@ -7,6 +7,8 @@ */ import execa from 'execa'; +import fs from 'fs'; +import { join } from 'path'; import { getBuildNumber } from './get_build_number'; interface Options { @@ -27,11 +29,12 @@ export async function getVersionInfo({ isRelease, versionQualifier, pkg }: Optio isRelease ? '' : '-SNAPSHOT' ); + const buildSha = fs.existsSync('./.git') + ? await execa('git', ['rev-parse', 'HEAD']).stdout + : process.env.GIT_COMMIT || process.env.BUILDKITE_COMMIT; + return { - buildSha: - process.env.GIT_COMMIT || - process.env.BUILDKITE_COMMIT || - (await execa('git', ['rev-parse', 'HEAD'])).stdout, + buildSha, buildVersion, buildNumber: await getBuildNumber(), }; From 19d868be9ecfc01bb36b957107495c3501efbe05 Mon Sep 17 00:00:00 2001 From: Brian Seeders Date: Tue, 8 Jun 2021 12:42:52 -0400 Subject: [PATCH 2/5] Remove unused join reference --- src/dev/build/lib/version_info.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/dev/build/lib/version_info.ts b/src/dev/build/lib/version_info.ts index 739fea30595e9..b01f97a1977ba 100644 --- a/src/dev/build/lib/version_info.ts +++ b/src/dev/build/lib/version_info.ts @@ -8,7 +8,6 @@ import execa from 'execa'; import fs from 'fs'; -import { join } from 'path'; import { getBuildNumber } from './get_build_number'; interface Options { @@ -29,7 +28,7 @@ export async function getVersionInfo({ isRelease, versionQualifier, pkg }: Optio isRelease ? '' : '-SNAPSHOT' ); - const buildSha = fs.existsSync('./.git') + const buildSha = fs.existsSync('.git') ? await execa('git', ['rev-parse', 'HEAD']).stdout : process.env.GIT_COMMIT || process.env.BUILDKITE_COMMIT; From 4380bc982d60dd237a5dad4866451dc470bf70d9 Mon Sep 17 00:00:00 2001 From: Brian Seeders Date: Tue, 8 Jun 2021 13:16:47 -0400 Subject: [PATCH 3/5] Update src/dev/build/lib/version_info.ts Co-authored-by: Spencer --- src/dev/build/lib/version_info.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dev/build/lib/version_info.ts b/src/dev/build/lib/version_info.ts index b01f97a1977ba..4d7bb4699d07d 100644 --- a/src/dev/build/lib/version_info.ts +++ b/src/dev/build/lib/version_info.ts @@ -29,7 +29,7 @@ export async function getVersionInfo({ isRelease, versionQualifier, pkg }: Optio ); const buildSha = fs.existsSync('.git') - ? await execa('git', ['rev-parse', 'HEAD']).stdout + ? (await execa('git', ['rev-parse', 'HEAD'])).stdout : process.env.GIT_COMMIT || process.env.BUILDKITE_COMMIT; return { From d6add4ba338c21f38df8ed6eaf695ec78957b98e Mon Sep 17 00:00:00 2001 From: Brian Seeders Date: Tue, 8 Jun 2021 13:56:39 -0400 Subject: [PATCH 4/5] Default to empty string for build sha, if it's not present from any other sources --- src/dev/build/lib/version_info.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dev/build/lib/version_info.ts b/src/dev/build/lib/version_info.ts index 4d7bb4699d07d..c3ce209e7616a 100644 --- a/src/dev/build/lib/version_info.ts +++ b/src/dev/build/lib/version_info.ts @@ -30,7 +30,7 @@ export async function getVersionInfo({ isRelease, versionQualifier, pkg }: Optio const buildSha = fs.existsSync('.git') ? (await execa('git', ['rev-parse', 'HEAD'])).stdout - : process.env.GIT_COMMIT || process.env.BUILDKITE_COMMIT; + : process.env.GIT_COMMIT || process.env.BUILDKITE_COMMIT || ''; return { buildSha, From d0fbb4d6c28d37410d55f183ac0221d2e3e78ac3 Mon Sep 17 00:00:00 2001 From: Brian Seeders Date: Tue, 8 Jun 2021 17:00:24 -0400 Subject: [PATCH 5/5] Use REPO_ROOT to set working directory and absolute paths --- src/dev/build/lib/version_info.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/dev/build/lib/version_info.ts b/src/dev/build/lib/version_info.ts index c3ce209e7616a..9ad20b4a6935b 100644 --- a/src/dev/build/lib/version_info.ts +++ b/src/dev/build/lib/version_info.ts @@ -8,6 +8,8 @@ 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 { @@ -28,8 +30,8 @@ export async function getVersionInfo({ isRelease, versionQualifier, pkg }: Optio isRelease ? '' : '-SNAPSHOT' ); - const buildSha = fs.existsSync('.git') - ? (await execa('git', ['rev-parse', 'HEAD'])).stdout + 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 {