Skip to content

Commit

Permalink
Allow bumping extension major version
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNino committed Jan 12, 2022
1 parent eb1a4b2 commit d54f34a
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions buildScripts/bump-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (commandLineArgsOptions.help || !commandLineArgsOptions.version) {
console.log(usage);
process.exit(commandLineArgsOptions.help ? 0 : 1);
}
const splitVersion = commandLineArgsOptions.version.split('.');
const requestedVersionSplit = commandLineArgsOptions.version.split('.');

assertVersion();
updateTasksVersion();
Expand All @@ -35,16 +35,15 @@ updateExtensionVersion();
* Validate the format of the new version and also that it is larger than the existing version.
*/
function assertVersion() {
assert.strictEqual(splitVersion.length, 3, 'Version have a format of X.Y.Z');
assert.strictEqual(requestedVersionSplit.length, 3, 'Version have a format of X.Y.Z');
let vssExtension = fs.readFileSync('vss-extension.json', 'utf8');
let vssExtensionJson = JSON.parse(vssExtension);
assert.strictEqual(
compareVersions(commandLineArgsOptions.version, vssExtensionJson.version),
1,
'Input version must be bigger than current version'
);
let oldVersionSplit = vssExtensionJson.version.split('.');
assert.strictEqual(oldVersionSplit[0], splitVersion[0], 'Upgrading Major version using this script is forbidden');
let oldExtensionVersionSplit = vssExtensionJson.version.split('.');
assert.ok(
((oldExtensionVersionSplit[1] < requestedVersionSplit[1]) && (requestedVersionSplit[2] === 0)) || // Minor release
((oldExtensionVersionSplit[1] === requestedVersionSplit[1]) && (oldExtensionVersionSplit[2] < requestedVersionSplit[2])), // Patch release
'Input version must be bigger than current version')
// assert.strictEqual(oldExtensionVersionSplit[0], requestedVersionSplit[0], 'Upgrading Major version using this script is forbidden'); // todo uncomment
}

/**
Expand All @@ -57,15 +56,15 @@ function updateTasksVersion() {
let taskDir = path.join('tasks', taskName);
let taskJsonPath = path.join(taskDir, 'task.json');
if (fs.existsSync(taskJsonPath)) {
console.log('Updating version of task ' + taskName + ' to X.' + splitVersion[1] + '.' + splitVersion[2]);
console.log('Updating version of task ' + taskName + ' to X.' + requestedVersionSplit[1] + '.' + requestedVersionSplit[2]);
updateTaskJsonWithNewVersion(taskJsonPath);
} else {
fs.readdir(taskDir, (err, taskVersionDirs) => {
taskVersionDirs.forEach(versToBuild => {
let taskVersionDirJson = path.join(taskDir, versToBuild, 'task.json');
if (fs.existsSync(taskVersionDirJson)) {
console.log(
'Updating version of task ' + taskName + ', version: ' + versToBuild + ' to X.' + splitVersion[1] + '.' + splitVersion[2]
'Updating version of task ' + taskName + ', version: ' + versToBuild + ' to X.' + requestedVersionSplit[1] + '.' + requestedVersionSplit[2]
);
updateTaskJsonWithNewVersion(taskVersionDirJson);
}
Expand All @@ -80,8 +79,8 @@ function updateTaskJsonWithNewVersion(taskJsonPath) {
let curMajorVersion = taskJson.get('version.Major');
taskJson.set('version', {
Major: curMajorVersion,
Minor: splitVersion[1],
Patch: splitVersion[2]
Minor: requestedVersionSplit[1],
Patch: requestedVersionSplit[2]
});
}

Expand Down

0 comments on commit d54f34a

Please sign in to comment.