Skip to content

Commit

Permalink
feat(releaseconfig): add an option for explict dependency for package…
Browse files Browse the repository at this point in the history
…s within the repository (dxatscale#1447)

Adds an option in release config for explict dependency, especially allowing for validate to ensure
dependencies of a  package (source/data) within the same repository , though excluded are allowed to
be installed

Co-authored-by: sfopsbot <[email protected]>
  • Loading branch information
azlam-abdulsalam and sfopsbot authored Dec 12, 2023
1 parent 94042a5 commit 4d0159a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 4 deletions.
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

0 comments on commit 4d0159a

Please sign in to comment.