Skip to content

Commit

Permalink
feat(impact): add additional options to consider only changed files d…
Browse files Browse the repository at this point in the history
…uring release config impact

This PR enhances the impact release config with additonal flags that allow to check for impact for
changed files, useful during PR validation
  • Loading branch information
sfopsbot committed Jan 9, 2024
1 parent b51f4ee commit 3a5d87a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/sfp-cli/messages/impact_release_config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"commandDescription": "Figures out impacted release configurations of a project, due to a change,from the last known tags",
"releaseConfigFileFlagDescription":"Path to the directory containing release defns",
"branchFlagDescription":"The branch on which the comparison is carried out",
"baseCommitOrBranchFlagDescription": "The base branch on which the git tags should be used from",
"filterByFlagDescription": "Filter by a specific release config name",
"filterByChangesInBranchFlagDescription": "Filter packages by changes with the provided branches as opposed to tags",
"explictDependencyCheckFlagDescription": "Activate to consider dependencyOn attribut while handling impact"
}
14 changes: 14 additions & 0 deletions packages/sfp-cli/src/commands/impact/releaseconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const messages = Messages.loadMessages('@flxblio/sfp', 'impact_release_config');
export default class ReleaseConfig extends sfpCommand {
public static flags = {
loglevel,
branch: Flags.string({
description: messages.getMessage('branchFlagDescription'),
required: true,
}),
basebranch: Flags.string({
description: messages.getMessage('baseCommitOrBranchFlagDescription'),
required: true,
Expand All @@ -33,6 +37,9 @@ export default class ReleaseConfig extends sfpCommand {
filterBy: Flags.string({
description: messages.getMessage('filterByFlagDescription'),
}),
filterByChangesInBranch: Flags.boolean({
description: messages.getMessage('filterByChangesInBranchFlagDescription'),
}),
};

public static description = messages.getMessage('commandDescription');
Expand All @@ -52,6 +59,13 @@ export default class ReleaseConfig extends sfpCommand {
},
};

if(this.flags.filterByChangesInBranch)
{
this.props.diffOptions.useBranchCompare=true;
this.props.diffOptions.branch=this.flags.branch;
this.props.diffOptions.baseBranch=this.flags.basebranch;
}

const impactedPackageResolver = new ImpactedPackageResolver(this.props, new ConsoleLogger());

let packagesToBeBuiltWithReasons = await impactedPackageResolver.getImpactedPackages();
Expand Down
9 changes: 5 additions & 4 deletions packages/sfp-cli/src/core/git/GitTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ export default class GitTags {
let refTagsPointingToBranch: string[] = refTags.filter((refTag) => commits.includes(refTag.substring(0, 40)));

// Only match the name of the tags pointing to the branch
refTagsPointingToBranch = refTagsPointingToBranch.map(
(refTagPointingToBranch) => refTagPointingToBranch.match(/(?:refs\/tags\/)(.*)((?:-ALIGN)|(?:\^{}))/)[1]
);
refTagsPointingToBranch = refTagsPointingToBranch.map((refTagPointingToBranch) => {
const match = refTagPointingToBranch.match(/(?:refs\/tags\/)(.*)((?:-ALIGN)|(?:\^{}))/);
return match ? match[1] : null;
});

// Filter the sorted tags - only including tags that point to the branch
let tagsPointingToBranch: string[] = tags.filter((tag) => refTagsPointingToBranch.includes(tag));
let tagsPointingToBranch: string[] = tags.filter((tag) => refTagsPointingToBranch?.includes(tag));

return tagsPointingToBranch;
}
Expand Down
12 changes: 11 additions & 1 deletion packages/sfp-cli/src/core/package/diff/PackageDiffImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export class PackageDiffOptions {
useLatestGitTags?:boolean=true;
packagesMappedToLastKnownCommitId?: { [p: string]: string };
pathToReplacementForceIgnore?: string;
useBranchCompare?: boolean = false;
branch?: string;
baseBranch?: string;
}

export default class PackageDiffImpl {
Expand Down Expand Up @@ -52,7 +55,14 @@ export default class PackageDiffImpl {
// Get the list of modified files between the tag and HEAD refs
let modified_files: string[];
try {
modified_files = await git.diff([`${tag}`, `HEAD`, `--no-renames`, `--name-only`]);
if(this.diffOptions?.useBranchCompare)
{
modified_files = await git.diff(['--name-only', `${this.diffOptions.baseBranch}...${this.diffOptions.branch}`]);
}
else
{
modified_files = await git.diff([`${tag}`, `HEAD`, `--no-renames`, `--name-only`]);
}
} catch (error) {
SFPLogger.log(COLOR_ERROR(`Unable to compute diff, The head of the branch is not reachable from the commit id ${tag}`));
SFPLogger.log(COLOR_ERROR(`Check your current branch (in case of build) or the scratch org in case of validate command`));
Expand Down

0 comments on commit 3a5d87a

Please sign in to comment.