Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

feat(releaseconfig): add an option for explict dependency for packages within the repository #1447

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"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",
"baseCommitOrBranchFlagDescription": "The base branch on which the git tags should be used from",
"filterByFlagDescription": "Filter by a specific release config name"
"filterByFlagDescription": "Filter by a specific release config name",
"explictDependencyCheckFlagDescription": "Activate to consider dependencyOn attribut while handling impact"
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
"type": "string"
}
},
"dependencyOn": {
"type": "array",
"title": "Include the below artifacts as dependencies of this release definition,usefor for validation",
"items": {
"type": "string"
}
},
"releasedefinitionProperties":{
"type": "object",
"title": "Properties that need to be set in the generated definition file",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export default class ReleaseConfig extends SfpowerscriptsCommand {
description: messages.getMessage('releaseConfigFileFlagDescription'),
default: 'config',
}),
explictDependencyCheck: Flags.boolean({
description: messages.getMessage('explictDependencyCheckFlagDescription'),
default: false,
}),
filterBy: Flags.string({
description: messages.getMessage('filterByFlagDescription'),
}),
Expand Down Expand Up @@ -63,6 +67,7 @@ export default class ReleaseConfig extends SfpowerscriptsCommand {
let impactedReleaseConfigs = impactedReleaseConfigResolver.getImpactedReleaseConfigs(
packagesToBeBuilt,
this.flags.releaseconfig,
this.flags.explictDependencyCheck,
this.flags.filterBy
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';

export default class ImpactedRelaseConfigResolver {

public getImpactedReleaseConfigs(impactedPackages, configDir, filterBy?: string) {
public getImpactedReleaseConfigs(impactedPackages, configDir,isExplicitDependencyCheckEnabled:boolean=false, filterBy?: string) {
const impactedReleaseDefs = [];

fs.readdirSync(configDir).forEach((file) => {
Expand All @@ -25,6 +25,15 @@ export default class ImpactedRelaseConfigResolver {
);
}


// handle dependencyOn, only do impact if there is atleast one package that is impacted
if (releaseImpactedPackages.length>0 && isExplicitDependencyCheckEnabled && releaseConfig.dependencyOn) {
releaseImpactedPackages = releaseConfig.dependencyOn.filter((artifact) =>
impactedPackages.includes(artifact)
);
}


if (releaseImpactedPackages.length > 0) {
if (filterBy) {
if (releaseConfig.releaseName.includes(filterBy)) {
Expand Down
23 changes: 21 additions & 2 deletions packages/sfpowerscripts-cli/src/impl/release/ReleaseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class ReleaseConfig {
return lodash.cloneDeep(this._releaseDefinitionGeneratorSchema);
}

public constructor(private logger: Logger, pathToReleaseDefinition: string) {
public constructor(private logger: Logger, pathToReleaseDefinition: string, private isExplicitDependencyCheckEnabled:boolean=false) {
this._releaseDefinitionGeneratorSchema = yaml.load(fs.readFileSync(pathToReleaseDefinition, 'utf8'));
this.validateReleaseDefinitionGeneratorConfig(this._releaseDefinitionGeneratorSchema);

Expand Down Expand Up @@ -55,6 +55,16 @@ export default class ReleaseConfig {
}
}

if(packages.length>0)
{
for (const sfdxPackage of sfdxPackages) {
if (this.getPackageDependencyPredicate(sfdxPackage)) {
packages.push(sfdxPackage);
}
}
}


return packages;
}

Expand Down Expand Up @@ -91,6 +101,15 @@ export default class ReleaseConfig {
return this.releaseDefinitionGeneratorConfigSchema.includeOnlyArtifacts?.includes(artifact);
} else if (this.releaseDefinitionGeneratorConfigSchema.excludeArtifacts) {
return !this.releaseDefinitionGeneratorConfigSchema.excludeArtifacts?.includes(artifact);
} else return true;
} else if(this.isExplicitDependencyCheckEnabled && this.releaseDefinitionGeneratorConfigSchema.dependencyOn) {
return this.releaseDefinitionGeneratorConfigSchema.dependencyOn?.includes(artifact);
}
else return true;
}

private getPackageDependencyPredicate(artifact: string): boolean {
if(this.isExplicitDependencyCheckEnabled && this.releaseDefinitionGeneratorConfigSchema.dependencyOn) {
return this.releaseDefinitionGeneratorConfigSchema.dependencyOn?.includes(artifact);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ export default class ValidateImpl implements PostDeployHook, PreDeployHook {
let releaseConfig: ReleaseConfig = new ReleaseConfig(
logger,
props.releaseConfigPath,
true
);
return releaseConfig.getPackagesAsPerReleaseConfig();
}
Expand Down