diff --git a/src/dev/build/lib/__mocks__/get_build_number.ts b/src/dev/build/lib/__mocks__/get_build_number.ts new file mode 100644 index 00000000000000..60cfd3d82557a3 --- /dev/null +++ b/src/dev/build/lib/__mocks__/get_build_number.ts @@ -0,0 +1,22 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export function getBuildNumber() { + return 12345; +} diff --git a/src/dev/build/lib/get_build_number.ts b/src/dev/build/lib/get_build_number.ts new file mode 100644 index 00000000000000..c512042592002a --- /dev/null +++ b/src/dev/build/lib/get_build_number.ts @@ -0,0 +1,34 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import os from 'os'; +import execa from 'execa'; + +export async function getBuildNumber() { + if (/^win/.test(os.platform())) { + // Windows does not have the wc process and `find /C /V ""` does not consistently work + const log = await execa('git', ['log', '--format="%h"']); + return log.stdout.split('\n').length; + } + + const wc = await execa.command('git log --format="%h" | wc -l', { + shell: true, + }); + return parseFloat(wc.stdout.trim()); +} diff --git a/src/dev/build/lib/version_info.test.ts b/src/dev/build/lib/version_info.test.ts index 1b0c71bf9220ee..ec8c363ddaccf1 100644 --- a/src/dev/build/lib/version_info.test.ts +++ b/src/dev/build/lib/version_info.test.ts @@ -20,6 +20,8 @@ import pkg from '../../../../package.json'; import { getVersionInfo } from './version_info'; +jest.mock('./get_build_number'); + describe('isRelease = true', () => { it('returns unchanged package.version, build sha, and build number', async () => { const versionInfo = await getVersionInfo({ diff --git a/src/dev/build/lib/version_info.ts b/src/dev/build/lib/version_info.ts index 958112c524bac7..fb3530b4c4edf2 100644 --- a/src/dev/build/lib/version_info.ts +++ b/src/dev/build/lib/version_info.ts @@ -17,22 +17,8 @@ * under the License. */ -import os from 'os'; - import execa from 'execa'; - -async function getBuildNumber() { - if (/^win/.test(os.platform())) { - // Windows does not have the wc process and `find /C /V ""` does not consistently work - const log = await execa('git', ['log', '--format="%h"']); - return log.stdout.split('\n').length; - } - - const wc = await execa.command('git log --format="%h" | wc -l', { - shell: true, - }); - return parseFloat(wc.stdout.trim()); -} +import { getBuildNumber } from './get_build_number'; interface Options { isRelease: boolean; diff --git a/src/dev/build/tasks/nodejs/download_node_builds_task.test.ts b/src/dev/build/tasks/nodejs/download_node_builds_task.test.ts index 6f08c8aa697506..413bf95cde8773 100644 --- a/src/dev/build/tasks/nodejs/download_node_builds_task.test.ts +++ b/src/dev/build/tasks/nodejs/download_node_builds_task.test.ts @@ -26,13 +26,10 @@ import { import { Config, Platform } from '../../lib'; import { DownloadNodeBuilds } from './download_node_builds_task'; -// import * as NodeShasumsNS from '../node_shasums'; -// import * as NodeDownloadInfoNS from '../node_download_info'; -// import * as DownloadNS from '../../../lib/download'; -// import { DownloadNodeBuilds } from '../download_node_builds_task'; jest.mock('./node_shasums'); jest.mock('./node_download_info'); jest.mock('../../lib/download'); +jest.mock('../../lib/get_build_number'); expect.addSnapshotSerializer(createAnyInstanceSerializer(ToolingLog)); diff --git a/src/dev/build/tasks/nodejs/extract_node_builds_task.test.ts b/src/dev/build/tasks/nodejs/extract_node_builds_task.test.ts index 94c421f7c9a626..f1700ef7b578c1 100644 --- a/src/dev/build/tasks/nodejs/extract_node_builds_task.test.ts +++ b/src/dev/build/tasks/nodejs/extract_node_builds_task.test.ts @@ -27,6 +27,7 @@ import { Config } from '../../lib'; import { ExtractNodeBuilds } from './extract_node_builds_task'; jest.mock('../../lib/fs'); +jest.mock('../../lib/get_build_number'); const Fs = jest.requireMock('../../lib/fs'); diff --git a/src/dev/build/tasks/nodejs/verify_existing_node_builds_task.test.ts b/src/dev/build/tasks/nodejs/verify_existing_node_builds_task.test.ts index f24b7ffc59c148..19416963d5eddc 100644 --- a/src/dev/build/tasks/nodejs/verify_existing_node_builds_task.test.ts +++ b/src/dev/build/tasks/nodejs/verify_existing_node_builds_task.test.ts @@ -29,6 +29,7 @@ import { VerifyExistingNodeBuilds } from './verify_existing_node_builds_task'; jest.mock('./node_shasums'); jest.mock('./node_download_info'); jest.mock('../../lib/fs'); +jest.mock('../../lib/get_build_number'); const { getNodeShasums } = jest.requireMock('./node_shasums'); const { getNodeDownloadInfo } = jest.requireMock('./node_download_info');