Skip to content

Commit d4215ba

Browse files
Improving the logging while checking out the Azure DevOps Repo in Courtesy Push pipeline (#21215)
* Adding more logs for better debugging
1 parent 9307f34 commit d4215ba

File tree

2 files changed

+62
-7
lines changed

2 files changed

+62
-7
lines changed

ci/courtesy-push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ steps:
3636

3737
- powershell: $(Build.SourcesDirectory)/ci/courtesy-push/send-notification.ps1
3838
displayName: Send MS Teams notification
39-
condition: eq(variables['build.reason'], 'Schedule')
39+
condition: or(eq(variables['build.reason'], 'Schedule'), eq(variables['build.reason'], 'Manual'))
4040
env:
4141
TEAMS_WEBHOOK: $(MSTeamsUri)

ci/courtesy-push/courtesy-push.js

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,20 @@ Generated: ${new Date().toISOString()}`
190190
console.log(` Repository: ${repo}`);
191191
console.log(` Pull-Request description:${JSON.stringify(pullRequestToCreate,null,2)}`)
192192
console.log('DRYRUN set to true-skipping actual PR creation...')
193+
const timestamp = Date.now();
194+
const dummyPrId = `DRYRUN-${timestamp}`;
195+
const dummyPrLink = `https://${orgUrl}/${project}/_git/${repo}/pullrequest/DRYRUN-${timestamp}`;
196+
197+
console.log(`##vso[task.setvariable variable=PR_ID]${dummyPrId}`);
198+
console.log(`##vso[task.setvariable variable=PR_LINK]${dummyPrLink}`);
199+
200+
console.log(`DRYRUN: Generated dummy PR_ID = ${dummyPrId}`);
201+
console.log(`DRYRUN: Generated dummy PR_LINK = ${dummyPrLink}`);
202+
203+
return {
204+
prId: dummyPrId,
205+
prLink: dummyPrLink
206+
};
193207
}
194208

195209

@@ -340,16 +354,13 @@ async function updateConfigsForTasks(depsArray, depsForUpdate, updatedDeps) {
340354
while (index < newDepsArr.length) {
341355
const currentDep = newDepsArr[index];
342356
const [ name ] = await extractDependency(currentDep);
343-
344357
const lowerName = name && name.toLowerCase();
345358
if (!name || !basicDepsForUpdate.has(lowerName)) {
346359
index++;
347360
continue;
348361
}
349-
350362
newDepsArr.splice(index, 1, depsForUpdate[lowerName].depStr);
351363
index++;
352-
353364
if (depsForUpdate[lowerName].configs) {
354365
depsForUpdate[lowerName].configs
355366
.sort((a, b) => a.name > b.name)
@@ -387,15 +398,28 @@ async function updateUnifiedDeps(unifiedDepsPath, newUnifiedDepsPath) {
387398
let currentDependencies = parseUnifiedDependencies(unifiedDepsPath);
388399
let updatedDependencies = parseUnifiedDependencies(newUnifiedDepsPath);
389400

401+
console.log('=== DETAILED Directory.Packages.props COMPARISON DEBUGGING ===');
402+
console.log(`Reading current dependencies from: ${unifiedDepsPath}`);
403+
console.log(`Reading new dependencies from: ${newUnifiedDepsPath}`);
404+
console.log(`Current dependencies count: ${currentDependencies.length}`);
405+
console.log(`Updated dependencies count: ${updatedDependencies.length}`);
406+
console.log('Updated Dependencies:', updatedDependencies);
390407
const updatedDependenciesStructure = await getDeps(updatedDependencies);
408+
console.log('Updated Dependencies Structure:', updatedDependenciesStructure);
391409

410+
// Initialize the updatedDeps object to track added and removed configs for the updated Tasks
392411
let updatedDeps = { added: [], removed: [] };
393412

394413
[ currentDependencies, updatedDeps ] = await removeConfigsForTasks(currentDependencies, updatedDependenciesStructure, updatedDeps);
414+
console.log('=== BEFORE updateConfigsForTasks ===');
415+
console.log('Dependencies for update keys:', Object.keys(updatedDependenciesStructure));
416+
console.log('Current dependencies array length:', currentDependencies.length);
395417
[ currentDependencies, updatedDeps ] = await updateConfigsForTasks(currentDependencies, updatedDependenciesStructure, updatedDeps);
396-
397418
fs.writeFileSync(unifiedDepsPath, currentDependencies.join('\n'));
398419
console.log('Updating Unified Dependencies file done.');
420+
console.log('Updated Dependencies:', updatedDependencies);
421+
console.log('Added Config Dependencies:', updatedDeps.added);
422+
console.log('Removed Config Dependencies:', updatedDeps.removed);
399423
return updatedDeps;
400424
}
401425

@@ -416,6 +440,12 @@ async function updateTfsServerDeps() {
416440
const unifiedDepsPath = path.join(repoPath, 'Directory.Packages.props');
417441
const tfsServerPath = path.join(repoPath, 'Tfs', 'Service', 'Deploy', 'components', 'TfsServer.hosted.xml');
418442
const pathToTfsCore=tfsServerPath
443+
444+
// Capture content BEFORE any changes
445+
const beforeUnifiedContent = fs.readFileSync(unifiedDepsPath, 'utf8');
446+
const beforeTfsContent = fs.readFileSync(pathToTfsCore, 'utf8');
447+
448+
419449
// Update the unified dependencies
420450
const depsToUpdate = await updateUnifiedDeps(unifiedDepsPath, newDeps);
421451

@@ -424,6 +454,11 @@ async function updateTfsServerDeps() {
424454
const depsToAdd = depsToUpdate.added.filter(dep => depsToUpdate.removed.indexOf(dep) === -1);
425455
const depsToRemove = depsToUpdate.removed.filter(dep => depsToUpdate.added.indexOf(dep) === -1);
426456

457+
console.log('=== TfsServer.hosted.xml MODIFICATION DEBUGGING ===');
458+
console.log(`Dependencies to add: ${JSON.stringify(depsToAdd, null, 2)}`);
459+
console.log(`Dependencies to remove: ${JSON.stringify(depsToRemove, null, 2)}`);
460+
console.log(`Total directories in TFS XML before modification: ${tfxCoreJson.Component.Directory.length}`);
461+
427462
// removing dependencies
428463
for (let idx = 0; idx < tfxCoreJson.Component.Directory.length; idx++) {
429464
const directory = tfxCoreJson.Component.Directory[idx];
@@ -440,6 +475,8 @@ async function updateTfsServerDeps() {
440475
tfxCoreJson.Component.Directory.unshift(directory);
441476
});
442477

478+
console.log(`Total directories in TFS XML after addition: ${tfxCoreJson.Component.Directory.length}`);
479+
443480
const builder = new xml2js.Builder({
444481
xmldec: { version: '1.0', encoding: 'utf-8' },
445482
renderOpts: { pretty: true, indent: ' ', newline: '\n', allowEmpty: false, spacebeforeslash: ' ' }
@@ -448,10 +485,28 @@ async function updateTfsServerDeps() {
448485

449486
fs.writeFileSync(pathToTfsCore, xml);
450487
console.log('Inserting into Tfs Servicing Core file done.');
488+
489+
// Capture content AFTER all changes
490+
const afterUnifiedContent = fs.readFileSync(unifiedDepsPath, 'utf8');
491+
const afterTfsContent = fs.readFileSync(pathToTfsCore, 'utf8');
492+
493+
// Check if ANY files changed
494+
const unifiedChanged = beforeUnifiedContent !== afterUnifiedContent;
495+
const tfsChanged = beforeTfsContent !== afterTfsContent;
496+
const anyFilesChanged = unifiedChanged || tfsChanged;
497+
498+
499+
500+
console.log('=== FILE CHANGE DETECTION ===');
501+
console.log(`Directory.Packages.props changed: ${unifiedChanged}`);
502+
console.log(`TfsServer.hosted.xml changed: ${tfsChanged}`);
503+
console.log(`Any files changed: ${anyFilesChanged}`);
504+
console.log(`Config additions: ${depsToUpdate.added.length}`);
505+
console.log(`Config removals: ${depsToUpdate.removed.length}`);
451506

452507
// Commit and push changes if there are any updates
453-
if (depsToUpdate.added.length > 0 || depsToUpdate.removed.length > 0) {
454-
console.log(`Dependencies updated: ${depsToUpdate.added.length} added, ${depsToUpdate.removed.length} removed`);
508+
if (depsToUpdate.added.length > 0 || depsToUpdate.removed.length > 0 || anyFilesChanged) {
509+
console.log(`Config Dependencies added: ${depsToUpdate.added.length}, Config Dependencies removed: ${depsToUpdate.removed.length}, Changes in the base task version: ${anyFilesChanged}`);
455510

456511
// Commit both the unified dependencies file and the TFS server file
457512
const filesToCommit = [

0 commit comments

Comments
 (0)