From 6fae52876b1f9e549a6e1b91789d5fff82d61f0c Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Sun, 8 Jul 2018 15:16:19 -0700 Subject: [PATCH] Fix #53445 - change build id generation to not depend on git tags --- build/gulpfile.vscode.js | 28 ++++++++----- build/lib/test/util.test.js | 56 -------------------------- build/lib/test/util.test.ts | 79 ------------------------------------- build/lib/util.js | 57 -------------------------- build/lib/util.ts | 61 ---------------------------- 5 files changed, 18 insertions(+), 263 deletions(-) delete mode 100644 build/lib/test/util.test.js delete mode 100644 build/lib/test/util.test.ts diff --git a/build/gulpfile.vscode.js b/build/gulpfile.vscode.js index 22d0b2fcdf5..c363f4d26cf 100644 --- a/build/gulpfile.vscode.js +++ b/build/gulpfile.vscode.js @@ -271,10 +271,8 @@ function packageTask(platform, arch, opts) { const date = new Date().toISOString(); const productJsonUpdate = { commit, date, checksums }; - try { + if (shouldSetupSettingsSearch()) { productJsonUpdate.settingsSearchBuildId = getSettingsSearchBuildId(packageJson); - } catch (err) { - console.warn(err); } const productJsonStream = gulp.src(['product.json'], { base: '.' }) @@ -474,9 +472,8 @@ gulp.task('upload-vscode-sourcemaps', ['minify-vscode'], () => { const allConfigDetailsPath = path.join(os.tmpdir(), 'configuration.json'); gulp.task('upload-vscode-configuration', ['generate-vscode-configuration'], () => { - const branch = process.env.BUILD_SOURCEBRANCH; - - if (!/\/master$/.test(branch) && branch.indexOf('/release/') < 0) { + if (!shouldSetupSettingsSearch()) { + const branch = process.env.BUILD_SOURCEBRANCH; console.log(`Only runs on master and release branches, not ${branch}`); return; } @@ -499,13 +496,24 @@ gulp.task('upload-vscode-configuration', ['generate-vscode-configuration'], () = })); }); -function getSettingsSearchBuildId(packageJson) { - const previous = util.getPreviousVersion(packageJson.version); +function shouldSetupSettingsSearch() { + const branch = process.env.BUILD_SOURCEBRANCH; + return branch && (/\/master$/.test(branch) || branch.indexOf('/release/') >= 0); +} +function getSettingsSearchBuildId(packageJson) { try { - const out = cp.execSync(`git rev-list ${previous}..HEAD --count`); + const branch = process.env.BUILD_SOURCEBRANCH; + const branchId = branch.indexOf('/release/') >= 0 ? 0 : + /\/master$/.test(branch) ? 1 : + 2; // Some unexpected branch + + const out = cp.execSync(`git rev-list master --count`); const count = parseInt(out.toString()); - return util.versionStringToNumber(packageJson.version) * 1e4 + count; + + // + // 1.25.1, 1,234,567 commits, master = 1250112345671 + return util.versionStringToNumber(packageJson.version) * 1e8 + count * 10 + branchId; } catch (e) { throw new Error('Could not determine build number: ' + e.toString()); } diff --git a/build/lib/test/util.test.js b/build/lib/test/util.test.js deleted file mode 100644 index ef0616173b6..00000000000 --- a/build/lib/test/util.test.js +++ /dev/null @@ -1,56 +0,0 @@ -"use strict"; -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -Object.defineProperty(exports, "__esModule", { value: true }); -var assert = require("assert"); -var util = require("../util"); -function getMockTagExists(tags) { - return function (tag) { return tags.indexOf(tag) >= 0; }; -} -suite('util tests', function () { - test('getPreviousVersion - patch', function () { - assert.equal(util.getPreviousVersion('1.2.3', getMockTagExists(['1.2.2', '1.2.1', '1.2.0', '1.1.0'])), '1.2.2'); - }); - test('getPreviousVersion - patch invalid', function () { - try { - util.getPreviousVersion('1.2.2', getMockTagExists(['1.2.0', '1.1.0'])); - } - catch (e) { - // expected - return; - } - throw new Error('Expected an exception'); - }); - test('getPreviousVersion - minor', function () { - assert.equal(util.getPreviousVersion('1.2.0', getMockTagExists(['1.1.0', '1.1.1', '1.1.2', '1.1.3'])), '1.1.3'); - assert.equal(util.getPreviousVersion('1.2.0', getMockTagExists(['1.1.0', '1.0.0'])), '1.1.0'); - }); - test('getPreviousVersion - minor gap', function () { - assert.equal(util.getPreviousVersion('1.2.0', getMockTagExists(['1.1.0', '1.1.1', '1.1.3'])), '1.1.1'); - }); - test('getPreviousVersion - minor invalid', function () { - try { - util.getPreviousVersion('1.2.0', getMockTagExists(['1.0.0'])); - } - catch (e) { - // expected - return; - } - throw new Error('Expected an exception'); - }); - test('getPreviousVersion - major', function () { - assert.equal(util.getPreviousVersion('2.0.0', getMockTagExists(['1.0.0', '1.1.0', '1.2.0', '1.2.1', '1.2.2'])), '1.2.2'); - }); - test('getPreviousVersion - major invalid', function () { - try { - util.getPreviousVersion('3.0.0', getMockTagExists(['1.0.0'])); - } - catch (e) { - // expected - return; - } - throw new Error('Expected an exception'); - }); -}); diff --git a/build/lib/test/util.test.ts b/build/lib/test/util.test.ts deleted file mode 100644 index 928e730f06c..00000000000 --- a/build/lib/test/util.test.ts +++ /dev/null @@ -1,79 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import assert = require('assert'); -import util = require('../util'); - -function getMockTagExists(tags: string[]) { - return (tag: string) => tags.indexOf(tag) >= 0; -} - -suite('util tests', () => { - test('getPreviousVersion - patch', () => { - assert.equal( - util.getPreviousVersion('1.2.3', getMockTagExists(['1.2.2', '1.2.1', '1.2.0', '1.1.0'])), - '1.2.2' - ); - }); - - test('getPreviousVersion - patch invalid', () => { - try { - util.getPreviousVersion('1.2.2', getMockTagExists(['1.2.0', '1.1.0'])); - } catch (e) { - // expected - return; - } - - throw new Error('Expected an exception'); - }); - - test('getPreviousVersion - minor', () => { - assert.equal( - util.getPreviousVersion('1.2.0', getMockTagExists(['1.1.0', '1.1.1', '1.1.2', '1.1.3'])), - '1.1.3' - ); - - assert.equal( - util.getPreviousVersion('1.2.0', getMockTagExists(['1.1.0', '1.0.0'])), - '1.1.0' - ); - }); - - test('getPreviousVersion - minor gap', () => { - assert.equal( - util.getPreviousVersion('1.2.0', getMockTagExists(['1.1.0', '1.1.1', '1.1.3'])), - '1.1.1' - ); - }); - - test('getPreviousVersion - minor invalid', () => { - try { - util.getPreviousVersion('1.2.0', getMockTagExists(['1.0.0'])); - } catch (e) { - // expected - return; - } - - throw new Error('Expected an exception'); - }); - - test('getPreviousVersion - major', () => { - assert.equal( - util.getPreviousVersion('2.0.0', getMockTagExists(['1.0.0', '1.1.0', '1.2.0', '1.2.1', '1.2.2'])), - '1.2.2' - ); - }); - - test('getPreviousVersion - major invalid', () => { - try { - util.getPreviousVersion('3.0.0', getMockTagExists(['1.0.0'])); - } catch (e) { - // expected - return; - } - - throw new Error('Expected an exception'); - }); -}); diff --git a/build/lib/util.js b/build/lib/util.js index 1a2d40327cd..dd6f0b56992 100644 --- a/build/lib/util.js +++ b/build/lib/util.js @@ -14,7 +14,6 @@ var fs = require("fs"); var _rimraf = require("rimraf"); var git = require("./git"); var VinylFile = require("vinyl"); -var cp = require("child_process"); var NoCancellationToken = { isCancellationRequested: function () { return false; } }; function incremental(streamProvider, initial, supportsCancellation) { var input = es.through(); @@ -211,62 +210,6 @@ function filter(fn) { return result; } exports.filter = filter; -function tagExists(tagName) { - try { - cp.execSync("git rev-parse " + tagName, { stdio: 'ignore' }); - return true; - } - catch (e) { - return false; - } -} -/** - * Returns the version previous to the given version. Throws if a git tag for that version doesn't exist. - * Given 1.17.2, return 1.17.1 - * 1.18.0 => 1.17.2. (or the highest 1.17.x) - * 2.0.0 => 1.18.0 (or the highest 1.x) - */ -function getPreviousVersion(versionStr, _tagExists) { - if (_tagExists === void 0) { _tagExists = tagExists; } - function getLatestTagFromBase(semverArr, componentToTest) { - var baseVersion = semverArr.join('.'); - if (!_tagExists(baseVersion)) { - throw new Error('Failed to find git tag for base version, ' + baseVersion); - } - var goodTag; - do { - goodTag = semverArr.join('.'); - semverArr[componentToTest]++; - } while (_tagExists(semverArr.join('.'))); - return goodTag; - } - var semverArr = versionStringToNumberArray(versionStr); - if (semverArr[2] > 0) { - semverArr[2]--; - var previous = semverArr.join('.'); - if (!_tagExists(previous)) { - throw new Error('Failed to find git tag for previous version, ' + previous); - } - return previous; - } - else if (semverArr[1] > 0) { - semverArr[1]--; - return getLatestTagFromBase(semverArr, 2); - } - else { - semverArr[0]--; - // Find 1.x.0 for latest x - var latestMinorVersion = getLatestTagFromBase(semverArr, 1); - // Find 1.x.y for latest y - return getLatestTagFromBase(versionStringToNumberArray(latestMinorVersion), 2); - } -} -exports.getPreviousVersion = getPreviousVersion; -function versionStringToNumberArray(versionStr) { - return versionStr - .split('.') - .map(function (s) { return parseInt(s); }); -} function versionStringToNumber(versionStr) { var semverRegex = /(\d+)\.(\d+)\.(\d+)/; var match = versionStr.match(semverRegex); diff --git a/build/lib/util.ts b/build/lib/util.ts index 9dcbbe72484..e1393b86c5b 100644 --- a/build/lib/util.ts +++ b/build/lib/util.ts @@ -17,7 +17,6 @@ import * as git from './git'; import * as VinylFile from 'vinyl'; import { ThroughStream } from 'through'; import * as sm from 'source-map'; -import * as cp from 'child_process'; export interface ICancellationToken { isCancellationRequested(): boolean; @@ -271,66 +270,6 @@ export function filter(fn: (data: any) => boolean): FilterStream { return result; } -function tagExists(tagName: string): boolean { - try { - cp.execSync(`git rev-parse ${tagName}`, { stdio: 'ignore' }); - return true; - } catch (e) { - return false; - } -} - -/** - * Returns the version previous to the given version. Throws if a git tag for that version doesn't exist. - * Given 1.17.2, return 1.17.1 - * 1.18.0 => 1.17.2. (or the highest 1.17.x) - * 2.0.0 => 1.18.0 (or the highest 1.x) - */ -export function getPreviousVersion(versionStr: string, _tagExists = tagExists) { - function getLatestTagFromBase(semverArr: number[], componentToTest: number): string { - const baseVersion = semverArr.join('.'); - if (!_tagExists(baseVersion)) { - throw new Error('Failed to find git tag for base version, ' + baseVersion); - } - - let goodTag; - do { - goodTag = semverArr.join('.'); - semverArr[componentToTest]++; - } while (_tagExists(semverArr.join('.'))); - - return goodTag; - } - - const semverArr = versionStringToNumberArray(versionStr); - if (semverArr[2] > 0) { - semverArr[2]--; - const previous = semverArr.join('.'); - if (!_tagExists(previous)) { - throw new Error('Failed to find git tag for previous version, ' + previous); - } - - return previous; - } else if (semverArr[1] > 0) { - semverArr[1]--; - return getLatestTagFromBase(semverArr, 2); - } else { - semverArr[0]--; - - // Find 1.x.0 for latest x - const latestMinorVersion = getLatestTagFromBase(semverArr, 1); - - // Find 1.x.y for latest y - return getLatestTagFromBase(versionStringToNumberArray(latestMinorVersion), 2); - } -} - -function versionStringToNumberArray(versionStr: string): number[] { - return versionStr - .split('.') - .map(s => parseInt(s)); -} - export function versionStringToNumber(versionStr: string) { const semverRegex = /(\d+)\.(\d+)\.(\d+)/; const match = versionStr.match(semverRegex); -- GitLab