Skip to content

Commit

Permalink
fix(diff):various fixes in diff to support branch compare
Browse files Browse the repository at this point in the history
- Mimic files changed in PR by most ci/cd systems using ..
- Ignore packages with no tags unless they are modified
  • Loading branch information
azlam-abdulsalam authored Jan 9, 2024
1 parent 1885fb2 commit 5070266
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions packages/sfp-cli/src/core/package/diff/PackageDiffImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class PackageDiffImpl {
try {
if(this.diffOptions?.useBranchCompare)
{
modified_files = await git.diff(['--name-only', `${this.diffOptions.baseBranch}...${this.diffOptions.branch}`]);
modified_files = await git.diff(['--name-only', `${this.diffOptions.baseBranch}..${this.diffOptions.branch}`]);
}
else
{
Expand Down Expand Up @@ -107,12 +107,34 @@ export default class PackageDiffImpl {

return { isToBeBuilt: false, reason: `No changes found`, tag: tag };
} else {
SFPLogger.log(
`Tag missing for ${this.sfdx_package}...marking package for build anyways`,
LoggerLevel.TRACE,
this.logger
);
return { isToBeBuilt: true, reason: `Previous version not found` };

if(this.diffOptions?.useBranchCompare)
{
let modified_files = await git.diff(['--name-only', `${this.diffOptions.baseBranch}..${this.diffOptions.branch}`]);
// Check whether the package has been modified
for (let filename of modified_files) {

let normalizedPkgPath = path.normalize(pkgDescriptor.path);
let normalizedFilename = path.normalize(filename);

let relativePath = path.relative(normalizedPkgPath, normalizedFilename);

if (!relativePath.startsWith('..')) {
SFPLogger.log(`Found change(s) in ${filename}`, LoggerLevel.TRACE, this.logger);
return { isToBeBuilt: true, reason: `Found change(s) in package`, tag: tag };
}
}
return { isToBeBuilt: false, reason: `No changes found`, tag: tag };

}
else {
SFPLogger.log(
`Tag missing for ${this.sfdx_package}...marking package for build anyways`,
LoggerLevel.TRACE,
this.logger
);
return { isToBeBuilt: true, reason: `Previous version not found` };
}
}
}

Expand Down

0 comments on commit 5070266

Please sign in to comment.