diff --git a/packages/sfpowerscripts-cli/messages/impact_release_config.json b/packages/sfpowerscripts-cli/messages/impact_release_config.json index e53051cc9..d96edc890 100644 --- a/packages/sfpowerscripts-cli/messages/impact_release_config.json +++ b/packages/sfpowerscripts-cli/messages/impact_release_config.json @@ -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" } diff --git a/packages/sfpowerscripts-cli/resources/schemas/releasedefinitiongenerator.schema.json b/packages/sfpowerscripts-cli/resources/schemas/releasedefinitiongenerator.schema.json index c06ece086..9a7f2cc7c 100644 --- a/packages/sfpowerscripts-cli/resources/schemas/releasedefinitiongenerator.schema.json +++ b/packages/sfpowerscripts-cli/resources/schemas/releasedefinitiongenerator.schema.json @@ -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", diff --git a/packages/sfpowerscripts-cli/src/commands/impact/releaseconfig.ts b/packages/sfpowerscripts-cli/src/commands/impact/releaseconfig.ts index 8a133a43c..c3dac0b9d 100644 --- a/packages/sfpowerscripts-cli/src/commands/impact/releaseconfig.ts +++ b/packages/sfpowerscripts-cli/src/commands/impact/releaseconfig.ts @@ -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'), }), @@ -63,6 +67,7 @@ export default class ReleaseConfig extends SfpowerscriptsCommand { let impactedReleaseConfigs = impactedReleaseConfigResolver.getImpactedReleaseConfigs( packagesToBeBuilt, this.flags.releaseconfig, + this.flags.explictDependencyCheck, this.flags.filterBy ); diff --git a/packages/sfpowerscripts-cli/src/impl/impact/ImpactedReleaseConfig.ts b/packages/sfpowerscripts-cli/src/impl/impact/ImpactedReleaseConfig.ts index 6a21ce73a..1af8798bc 100644 --- a/packages/sfpowerscripts-cli/src/impl/impact/ImpactedReleaseConfig.ts +++ b/packages/sfpowerscripts-cli/src/impl/impact/ImpactedReleaseConfig.ts @@ -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) => { @@ -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)) { diff --git a/packages/sfpowerscripts-cli/src/impl/release/ReleaseConfig.ts b/packages/sfpowerscripts-cli/src/impl/release/ReleaseConfig.ts index 55910eb19..299152d12 100644 --- a/packages/sfpowerscripts-cli/src/impl/release/ReleaseConfig.ts +++ b/packages/sfpowerscripts-cli/src/impl/release/ReleaseConfig.ts @@ -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); @@ -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; } @@ -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); + } } } diff --git a/packages/sfpowerscripts-cli/src/impl/validate/ValidateImpl.ts b/packages/sfpowerscripts-cli/src/impl/validate/ValidateImpl.ts index cf320350a..c01d52f7f 100644 --- a/packages/sfpowerscripts-cli/src/impl/validate/ValidateImpl.ts +++ b/packages/sfpowerscripts-cli/src/impl/validate/ValidateImpl.ts @@ -515,6 +515,7 @@ export default class ValidateImpl implements PostDeployHook, PreDeployHook { let releaseConfig: ReleaseConfig = new ReleaseConfig( logger, props.releaseConfigPath, + true ); return releaseConfig.getPackagesAsPerReleaseConfig(); }