Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 1.0] [CI][Build] Use BUILD_NUMBER for building bundles #1460

Merged
merged 1 commit into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/dev/build/lib/get_build_number.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

import { getBuildNumber } from './get_build_number';

const BUILD_NUMBER_ENV_KEY = 'BUILD_NUMBER';
const itif = process.env.CI === '1' ? it.skip : it;

describe('getBuildNumber', () => {
let previousBuildNumber: string;

beforeEach(() => {
if (BUILD_NUMBER_ENV_KEY in process.env) {
previousBuildNumber = process.env[BUILD_NUMBER_ENV_KEY] as string;
delete process.env[BUILD_NUMBER_ENV_KEY];
}
});

afterEach(() => {
if (BUILD_NUMBER_ENV_KEY in process.env) {
process.env[BUILD_NUMBER_ENV_KEY] = previousBuildNumber;
}
});

it('returns env BUILD_NUMBER count', async () => {
process.env.BUILD_NUMBER = '123';
const buildNumber = await getBuildNumber();
expect(buildNumber).toBe(123);
});

// If test is ran on the CI, it only gets 1 commit
itif('returns git commit count', async () => {
const buildNumber = await getBuildNumber();
expect(buildNumber).toBeGreaterThan(1000);
});
});
4 changes: 4 additions & 0 deletions src/dev/build/lib/get_build_number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import os from 'os';
import execa from 'execa';

export async function getBuildNumber() {
if ('BUILD_NUMBER' in process.env) {
return parseFloat(process.env.BUILD_NUMBER as string);
}

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"']);
Expand Down