Skip to content

Commit ef62f43

Browse files
Add version bumping mechanism (#21066)
* Add version bumping mechanism * Add version bumping mechanism * Add additional converting of income parameter
1 parent 175bbef commit ef62f43

File tree

2 files changed

+97
-57
lines changed

2 files changed

+97
-57
lines changed

make-util.js

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ var createNugetPackagePerTask = function (packagePath, /*nonAggregatedLayoutPath
13681368

13691369
// Create the full task name so we don't need to rely on the folder name.
13701370
var fullTaskName = `Mseng.MS.TF.DistributedTask.Tasks.${taskName}V${taskJsonContents.version.Major}`;
1371-
if (taskJsonContents.hasOwnProperty('_buildConfigMapping')) {
1371+
if (taskJsonContents.hasOwnProperty('_buildConfigMapping')) {
13721372
for (let i in taskJsonContents._buildConfigMapping) {
13731373
if (taskJsonContents._buildConfigMapping[i] === taskVersion && i.toLocaleLowerCase() !== 'default') {
13741374
// take only first part of the name
@@ -1718,20 +1718,20 @@ const getTaskNodeVersion = function(buildPath, taskName) {
17181718
exports.getTaskNodeVersion = getTaskNodeVersion;
17191719

17201720
/**
1721-
*
1721+
*
17221722
* @param {String} buildPath - Path to the build folder
17231723
* @param {String} taskName - Name of the task
17241724
* @returns { Boolean } true if the task is a node task
17251725
*/
17261726
var isNodeTask = function(buildPath, taskName) {
17271727
const taskJsonPath = path.join(buildPath, taskName, "task.json");
17281728
if (!fs.existsSync(taskJsonPath)) return false;
1729-
1729+
17301730
const taskJsonContents = fs.readFileSync(taskJsonPath, { encoding: 'utf-8' });
17311731
const taskJson = JSON.parse(taskJsonContents);
17321732
const execution = ['execution', 'prejobexecution','postjobexecution']
17331733
.map(key => taskJson[key]);
1734-
1734+
17351735
for (const executors of execution) {
17361736
if (!executors) continue;
17371737
for (const key of Object.keys(executors)) {
@@ -1815,7 +1815,7 @@ var processGeneratedTasks = function(baseConfigToolPath, taskList, makeOptions,
18151815
args.push("--current-sprint");
18161816
args.push(sprintNumber);
18171817
}
1818-
1818+
18191819
var writeUpdateArg = "";
18201820
if(writeUpdates)
18211821
{
@@ -1824,7 +1824,7 @@ var processGeneratedTasks = function(baseConfigToolPath, taskList, makeOptions,
18241824

18251825
if(includeLocalPackagesBuildConfig)
18261826
{
1827-
writeUpdateArg += " --include-local-packages-build-config";
1827+
writeUpdateArg += " --include-local-packages-build-config";
18281828
}
18291829

18301830
var debugAgentDirArg = "";
@@ -1945,27 +1945,27 @@ function syncGeneratedFilesWrapper(originalFunction, basicGenTaskPath, basicGenT
19451945

19461946
const [ baseTaskName, config ] = taskName.split("_");
19471947
const copyCandidates = shell.find(genTaskPath)
1948-
.filter(function (item) {
1948+
.filter(function (item) {
19491949
// ignore node_modules
19501950
if (item.indexOf("node_modules") !== -1) return false
19511951
// ignore everything except package.json, package-lock.json, npm-shrinkwrap.json
19521952
if (!runtimeChangedFiles.some((pattern) => item.indexOf(pattern) !== -1)) return false;
1953-
1953+
19541954
return true;
19551955
});
19561956

19571957
copyCandidates.forEach((candidatePath) => {
19581958
const relativePath = path.relative(genTaskPath, candidatePath);
19591959
let dest = path.join(__dirname, 'Tasks', baseTaskName, relativePath);
1960-
1961-
if (config) {
1960+
1961+
if (config) {
19621962
if(config==="LocalPackages"){
19631963
dest = path.join(__dirname, '_generated', '_buildConfigs', baseTaskName, config, relativePath);
19641964
}else{
19651965
dest = path.join(__dirname, 'Tasks', baseTaskName, '_buildConfigs', config, relativePath);
19661966
}
19671967
}
1968-
1968+
19691969
// update Tasks/[task]/_buildConfigs/[configs]/package.json, etc if it already exists, unless it's package-lock.json/npm-shrinkwrap.json. (we need to update package-lock.json as the server build uses npm ci which requires package-lock.json to be in sync with package.json)
19701970
const isPackageLock = path.basename(dest).toLowerCase() == "package-lock.json";
19711971
const isNpmShrinkWrap = path.basename(dest).toLowerCase() == "npm-shrinkwrap.json";
@@ -1987,4 +1987,33 @@ function syncGeneratedFilesWrapper(originalFunction, basicGenTaskPath, basicGenT
19871987

19881988
exports.syncGeneratedFilesWrapper = syncGeneratedFilesWrapper;
19891989

1990+
function getChangedTasks() {
1991+
const changedTasks = [];
1992+
const changedFiles = run('git diff --name-only origin/master', false, true).split('\n');
1993+
1994+
changedFiles.forEach((file) => {
1995+
if (file.startsWith('Tasks/')) {
1996+
const taskName = file.split('/')[1];
1997+
if (!changedTasks.includes(taskName)) {
1998+
changedTasks.push(taskName);
1999+
}
2000+
}
2001+
});
2002+
return changedTasks;
2003+
}
2004+
2005+
exports.getChangedTasks = getChangedTasks;
2006+
2007+
async function getCurrentSprint() {
2008+
const result = await fetch("https://whatsprintis.it", {
2009+
headers: {
2010+
"Accept": "application/json"
2011+
}
2012+
});
2013+
2014+
return result.json();
2015+
}
2016+
2017+
exports.getCurrentSprint = getCurrentSprint;
2018+
19902019
//------------------------------------------------------------------------------

make.js

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ function getTaskList(taskList, includeLocalPackagesBuildConfig) {
157157
}
158158

159159
generatedTaskFolders = generatedTaskFolders.filter((taskName) => {
160-
return !taskName.endsWith(".versionmap.txt")
160+
return !taskName.endsWith(".versionmap.txt")
161161
&& (
162-
(((includeLocalPackagesBuildConfig && fs.existsSync(path.join(genTaskPath, taskName))) || !includeLocalPackagesBuildConfig) && fs.statSync(path.join(genTaskPath, taskName)).isDirectory())
162+
(((includeLocalPackagesBuildConfig && fs.existsSync(path.join(genTaskPath, taskName))) || !includeLocalPackagesBuildConfig) && fs.statSync(path.join(genTaskPath, taskName)).isDirectory())
163163
|| (includeLocalPackagesBuildConfig && fs.statSync(path.join(genTaskPathLocal, taskName)).isDirectory())
164164
);
165165
});
@@ -226,7 +226,7 @@ CLI.gendocs = function() {
226226
// ex: node make.js build
227227
// ex: node make.js build --task ShellScript
228228
//
229-
CLI.build = async function(/** @type {{ task: string }} */ argv)
229+
CLI.build = async function(/** @type {{ task: string }} */ argv)
230230
{
231231
if (process.env.TF_BUILD) {
232232
fail('Please use serverBuild for CI builds for proper validation');
@@ -285,7 +285,7 @@ CLI.serverBuild = async function(/** @type {{ task: string }} */ argv) {
285285
run("npm install", /*inheritStreams:*/true);
286286
run("node make.js build", /*inheritStreams:*/true);
287287

288-
288+
289289
await util.installNodeAsync('20');
290290
// build task-lib
291291
cd(tasksCommonPath);
@@ -296,7 +296,7 @@ CLI.serverBuild = async function(/** @type {{ task: string }} */ argv) {
296296

297297
const allTasks = getTaskList(taskList, argv.includeLocalPackagesBuildConfig);
298298

299-
// Wrap build function to store files that changes after the build
299+
// Wrap build function to store files that changes after the build
300300
const buildTaskWrapped = util.syncGeneratedFilesWrapper(buildTaskAsync, genTaskPath, genTaskPathLocal, argv.includeLocalPackagesBuildConfig, writeUpdatedsFromGenTasks);
301301
const { allTasksNode20, allTasksDefault } = allTasks.
302302
reduce((res, taskName) => {
@@ -308,14 +308,14 @@ CLI.serverBuild = async function(/** @type {{ task: string }} */ argv) {
308308

309309
return res;
310310
}, {allTasksNode20: [], allTasksDefault: []})
311-
311+
312312
if (allTasksNode20.length > 0) {
313313
await util.installNodeAsync('20');
314314
ensureTool('node', '--version', `v${node20Version}`);
315315
for (const taskName of allTasksNode20) {
316316
await buildTaskWrapped(taskName, allTasksNode20.length, 20, !writeUpdatedsFromGenTasks);
317317
}
318-
}
318+
}
319319
if (allTasksDefault.length > 0) {
320320
await util.installNodeAsync('10');
321321
ensureTool('node', '--version', `v${node10Version}`);
@@ -342,7 +342,7 @@ function getNodeVersion (taskName, includeLocalPackagesBuildConfig) {
342342
// if task exists inside gen folder prefere it
343343
if (fs.existsSync(path.join(genTaskPath, taskName))) {
344344
taskPath = genTaskPath;
345-
}
345+
}
346346
else if(includeLocalPackagesBuildConfig)
347347
{
348348
if(fs.existsSync(path.join(genTaskPathLocal, taskName)))
@@ -370,14 +370,14 @@ async function buildTaskAsync(taskName, taskListLength, nodeVersion, isServerBui
370370
// Need to add all tasks which starts with task name
371371
console.log('Found generated task: ' + taskName);
372372
isGeneratedTask = true;
373-
}
373+
}
374374
else if (argv.includeLocalPackagesBuildConfig && fs.existsSync(localTaskPath))
375375
{
376376
console.log('Found local generated task: ' + taskName);
377377
isGeneratedTask = true;
378378
taskPath = localTaskPath;
379-
}
380-
else
379+
}
380+
else
381381
{
382382
taskPath = path.join(tasksPath, taskName);
383383
}
@@ -441,13 +441,13 @@ async function buildTaskAsync(taskName, taskListLength, nodeVersion, isServerBui
441441
if (!fs.existsSync(genTaskCommonPath) && isGeneratedTask) {
442442
cp('-Rf', path.resolve(tasksPath, "Common"), genTaskCommonPath);
443443
}
444-
444+
445445
if(argv.includeLocalPackagesBuildConfig)
446446
{
447447
if (!fs.existsSync(genTaskCommonPathLocal) && isGeneratedTask) {
448448
cp('-Rf', path.resolve(tasksPath, "Common"), genTaskCommonPathLocal);
449449
}
450-
}
450+
}
451451

452452
mkdir('-p', modOutDir);
453453

@@ -718,7 +718,7 @@ CLI.test = async function(/** @type {{ suite: string; node: string; task: string
718718
results.forEach(({ taskName, result }) => {
719719
hasErrors = true;
720720
console.log(`Task: ${taskName}, Result: ${result}`);
721-
});
721+
});
722722

723723
if (hasErrors) {
724724
console.log('Errors occurred during tests');
@@ -921,43 +921,54 @@ CLI.publish = function(/** @type {{ server: string; task: string }} */ argv) {
921921
run(`nuget3.exe push ${nupkgFile} -Source ${server} -apikey Skyrise`);
922922
}
923923

924-
925-
var agentPluginTaskNames = ['Cache', 'CacheBeta', 'DownloadPipelineArtifact', 'PublishPipelineArtifact'];
926-
// used to bump the patch version in task.json files
927-
CLI.bump = function() {
928-
verifyAllAgentPluginTasksAreInSkipList();
929-
930-
taskList.forEach(function (taskName) {
931-
// load files
932-
var taskJsonPath = path.join(tasksPath, taskName, 'task.json');
933-
var taskJson = JSON.parse(fs.readFileSync(taskJsonPath));
934-
935-
var taskLocJsonPath = path.join(tasksPath, taskName, 'task.loc.json');
936-
var taskLocJson = JSON.parse(fs.readFileSync(taskLocJsonPath));
937-
938-
// skip agent plugin tasks
939-
if(agentPluginTaskNames.indexOf(taskJson.name) > -1) {
924+
/**
925+
* Bump the patch version for all tasks that have changed since the last commit
926+
* @param {Object} argv - Arguments object containing the sprint number
927+
* @param {number} [argv.sprint] - The sprint number to use for bumping the patch version. Default value is the current sprint.
928+
* @example
929+
* ```
930+
* node make.js bump
931+
* node make.js bump --sprint 258
932+
* ````
933+
*/
934+
CLI.bump = async (argv) => {
935+
// Get the list of changed tasks since the last commit
936+
const changedTasks = util.getChangedTasks();
937+
const jsons = ["task.json", "task.loc.json"];
938+
939+
argv.sprint = argv.sprint ?? Number((await util.getCurrentSprint()).sprint);
940+
941+
changedTasks.forEach((taskName) => {
942+
const taskPath = path.join(tasksPath, taskName);
943+
944+
if (!test('-d', taskPath)) {
940945
return;
941946
}
942947

943-
if (typeof taskJson.version.Patch != 'number') {
944-
fail(`Error processing '${taskName}'. version.Patch should be a number.`);
945-
}
948+
jsons.forEach((jsonFile) => {
949+
const taskJsonPath = path.join(taskPath, jsonFile);
946950

947-
taskJson.version.Patch = taskJson.version.Patch + 1;
948-
taskLocJson.version.Patch = taskLocJson.version.Patch + 1;
951+
if (!test('-f', taskJsonPath)) {
952+
return;
953+
}
949954

950-
const taskJsonStringified = JSON.stringify(taskJson, null, 2).replace(/(\n|\r\n)/g, os.EOL);
951-
fs.writeFileSync(taskJsonPath, taskJsonStringified);
952-
const taskLocJsonStringified = JSON.stringify(taskLocJson, null, 2).replace(/(\n|\r\n)/g, os.EOL);
953-
fs.writeFileSync(taskLocJsonPath, taskLocJsonStringified);
955+
const taskJson = fileToJson(taskJsonPath);
954956

955-
// Check that task.loc and task.loc.json versions match
956-
if ((taskJson.version.Major !== taskLocJson.version.Major) ||
957-
(taskJson.version.Minor !== taskLocJson.version.Minor) ||
958-
(taskJson.version.Patch !== taskLocJson.version.Patch)) {
959-
console.log(`versions dont match for task '${taskName}', task json: ${JSON.stringify(taskJson.version)} task loc json: ${JSON.stringify(taskLocJson.version)}`);
960-
}
957+
if (argv.sprint > taskJson.version.Minor) {
958+
taskJson.version.Minor = argv.sprint;
959+
taskJson.version.Patch = 0;
960+
} else if (argv.sprint === taskJson.version.Minor) {
961+
taskJson.version.Patch++;
962+
} else {
963+
throw new Error(`Sprint version ${argv.sprint} is less than the current task version Minor ${taskJson.version.Minor}. Cannot bump version.`);
964+
}
965+
966+
fs.writeFileSync(taskJsonPath, JSON.stringify(taskJson, null, 2));
967+
968+
if (jsonFile === "task.json") {
969+
console.log(`Bump version of ${taskName} to ${Object.values(taskJson.version).join(".")}`);
970+
}
971+
});
961972
});
962973
}
963974

@@ -1046,7 +1057,7 @@ function verifyAllAgentPluginTasksAreInSkipList() {
10461057
// 1. Copy generated task to base task, delete generated files in _generated/Task_Node20 and Tasks/taskname/_buildConfig/Node20.
10471058
// 2. Update versionmap.txt file.
10481059
// 3. Remove _buildConfigMapping section in task.json and task-loc.json
1049-
// 4. Update the buildConfig section in make-option.json.
1060+
// 4. Update the buildConfig section in make-option.json.
10501061
CLI.mergeBuildConfig = function(/** @type {{ config: string }} */ argv) {
10511062
var config = argv.config
10521063
banner(`Merging all tasks under ${config} build config into base tasks...`);

0 commit comments

Comments
 (0)