Skip to content

Commit

Permalink
feat(release): introduce additional properties to release config and …
Browse files Browse the repository at this point in the history
…definition

Introduce additional properties such as releaseConfigName, metadata  into release configuration.
Refactor the implementation across to make the variables and lass clear
  • Loading branch information
azlam-abdulsalam committed Feb 8, 2024
1 parent 878ac4e commit 4f33fd4
Show file tree
Hide file tree
Showing 23 changed files with 387 additions and 337 deletions.
3 changes: 2 additions & 1 deletion packages/sfp-cli/messages/release.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"allowUnpromotedPackagesFlagDescription": "Allow un-promoted packages to be installed in production",
"devhubAliasFlagDescription": "Provide the alias of the devhub previously authenticated, default value is HubOrg",
"directoryFlagDescription": "Relative path to directory to which the changelog should be generated, if the directory doesnt exist, it will be created",
"branchNameFlagDescription": "Repository branch in which the changelog files are located"
"branchNameFlagDescription": "Repository branch in which the changelog files are located",
"changelogByDomainsFlagDescription":"Create changelog files by domains or name mentioned in release config"
}
5 changes: 3 additions & 2 deletions packages/sfp-cli/messages/releasedefinition_generate.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"commandDescription": "Generates release definition based on the artifacts installed from a commit reference",
"configFileFlagDescription":"Path to the config file which determines how the release definition should be generated",
"configFileFlagDescription":"Path to the release config file which determines how the release definition should be generated",
"releaseNameFlagDescription": "Set a release name on the release definition file created",
"commitFlagDescription": "Utilize the tags on the source branch to generate release definiton",
"directoryFlagDescription": "Relative path to directory to which the release definition file should be generated, if the directory doesnt exist, it will be created",
"branchNameFlagDescription": "Repository branch in which the release definition files are to be written",
"noPushFlagDescription":"Do not push the changelog to a repository to the provided branch",
"forcePushFlagDescription": "Force push changes to the repository branch"
"forcePushFlagDescription": "Force push changes to the repository branch",
"metadataFlagDescription": "Additional metadata in json format that needs to be added to the release definition file"
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://github.com/flxbl-io/sfp/blob/develop/packages/sfp-cli/resources/releasedefinitiongenerator.schema.json",
"title": "release definition generator",
"description": "The definition for generating a release defintion using generator command",
"$id": "https://github.com/flxbl-io/json-schemas/blob/main/release-config.schema.json",
"title": "Configuration of a release, used as an input to the release definition generator or by sfops for understanding how the repo is structure",
"description": "Configuration of a release",
"type": "object",
"additionalProperties": true,
"dependencies": {
"baselineOrg": ["skipIfAlreadyInstalled"]
},
"properties": {
"releaseName": {
"type": "string",
"title": "Name of the domain this release configuration belongs to"
},
"pool": {
"type": "string",
"title": "The pool of review sandbox or scratch org to be used for validating the packages that are part of this release configuration"
},
"excludeArtifacts": {
"type": "array",
"title": "Exclude the below artifacts while creating a release definition",
Expand Down Expand Up @@ -57,7 +65,7 @@
},
"releasedefinitionProperties":{
"type": "object",
"title": "Properties that need to be set in the generated definition file",
"title": "Properties that need to be set in the generated release definition",
"additionalProperties": true,
"properties": {
"skipIfAlreadyInstalled": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://github.com/flxbl-io/sfp/blob/develop/packages/sfp-cli/resources/releasedefinition.schema.json",
"title": "release definition",
"description": "The definition for a release using sfp orchestrator",
"$id": "https://github.com/flxbl-io/json-schemas/blob/main/release-defn.schema.json",
"title": "A definition of a release, the artifacts to be deployed along with its version,",
"description": "This yaml file is either manually defined or auto generated by sfp release definition generator",
"type": "object",
"required": ["release", "artifacts"],
"additionalProperties": false,
Expand All @@ -13,6 +13,14 @@
"release": {
"type": "string"
},
"releaseConfigName": {
"type": "string",
"title": "The name of the release config that generated this release definition,autopopulated when generated by release definition generator"
},
"metadata": {
"type": "object",
"title": "Additional data to be written to the release definition"
},
"skipIfAlreadyInstalled": {
"type": "boolean"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/sfp-cli/src/BuildBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import SFPLogger, {
} from '@flxblio/sfp-logger';
import getFormattedTime from './core/utils/GetFormattedTime';
import SfpPackage from './core/package/SfpPackage';
import ReleaseConfig from './impl/release/ReleaseConfig';
import ReleaseConfigLoader from './impl/release/ReleaseConfigLoader';
import { Flags } from '@oclif/core';
import { loglevel, orgApiVersionFlagSfdxStyle, targetdevhubusername } from './flags/sfdxflags';

Expand Down Expand Up @@ -234,8 +234,8 @@ export default abstract class BuildBase extends SfpCommand {

private includeOnlyPackagesAsPerReleaseConfig(releaseConfigFilePath:string,buildProps: BuildProps,logger?:Logger): BuildProps {
if (releaseConfigFilePath) {
let releaseConfig:ReleaseConfig = new ReleaseConfig(logger, releaseConfigFilePath);
buildProps.includeOnlyPackages = releaseConfig.getPackagesAsPerReleaseConfig();
let releaseConfigLoader:ReleaseConfigLoader = new ReleaseConfigLoader(logger, releaseConfigFilePath);
buildProps.includeOnlyPackages = releaseConfigLoader.getPackagesAsPerReleaseConfig();
printIncludeOnlyPackages(buildProps.includeOnlyPackages);
}
return buildProps;
Expand Down
4 changes: 2 additions & 2 deletions packages/sfp-cli/src/commands/artifacts/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SfpCommand from '../../SfpCommand';
import { LoggerLevel, Messages } from '@salesforce/core';
import FetchImpl, { ArtifactVersion } from '../../impl/artifacts/FetchImpl';
import ReleaseDefinition from '../../impl/release/ReleaseDefinition';
import ReleaseDefinitionLoader from '../../impl/release/ReleaseDefinitionLoader';
import FetchArtifactsError from '../../impl/artifacts/FetchArtifactsError';
import { ConsoleLogger } from '@flxblio/sfp-logger';
import { Flags } from '@oclif/core';
Expand Down Expand Up @@ -58,7 +58,7 @@ export default class Fetch extends SfpCommand {
public async execute() {
this.validateFlags();

let releaseDefinition = (await ReleaseDefinition.loadReleaseDefinition(this.flags.releasedefinition)).releaseDefinition;
let releaseDefinition = await ReleaseDefinitionLoader.loadReleaseDefinition(this.flags.releasedefinition);
let result: {
success: ArtifactVersion[];
failed: ArtifactVersion[];
Expand Down
12 changes: 8 additions & 4 deletions packages/sfp-cli/src/commands/orchestrator/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SfpCommand from '../../SfpCommand';
import { LoggerLevel, Messages } from '@salesforce/core';
import SFPStatsSender from '../../core/stats/SFPStatsSender';
import ReleaseImpl, { ReleaseProps, ReleaseResult } from '../../impl/release/ReleaseImpl';
import ReleaseDefinition from '../../impl/release/ReleaseDefinition';
import ReleaseDefinitionLoader from '../../impl/release/ReleaseDefinitionLoader';
import ReleaseError from '../../errors/ReleaseError';
import path = require('path');
import SFPLogger, {
Expand All @@ -14,7 +14,7 @@ import SFPLogger, {
COLOR_KEY_MESSAGE,
ConsoleLogger,
} from '@flxblio/sfp-logger';
import ReleaseDefinitionSchema from '../../impl/release/ReleaseDefinitionSchema';
import ReleaseDefinition from '../../impl/release/ReleaseDefinition';
import { arrayFlagSfdxStyle, loglevel, logsgroupsymbol, optionalDevHubFlag, requiredUserNameFlag } from '../../flags/sfdxflags';
import { Flags } from '@oclif/core';

Expand Down Expand Up @@ -95,6 +95,10 @@ export default class Release extends SfpCommand {
message: '--allowunpromotedpackages is deprecated, All packages are allowed',
},
}),
changelogByDomains: Flags.boolean({
description: messages.getMessage('changelogByDomainsFlagDescription'),
hidden: true
}),
devhubalias: optionalDevHubFlag,
loglevel
};
Expand All @@ -119,9 +123,9 @@ export default class Release extends SfpCommand {

SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);

let releaseDefinitions: ReleaseDefinitionSchema[] = [];
let releaseDefinitions: ReleaseDefinition[] = [];
for (const pathToReleaseDefintion of this.flags.releasedefinition) {
let releaseDefinition = (await ReleaseDefinition.loadReleaseDefinition(pathToReleaseDefintion)).releaseDefinition;
let releaseDefinition = await ReleaseDefinitionLoader.loadReleaseDefinition(pathToReleaseDefintion);

//Support Legacy by taking the existing single workItemFilter and pushing it to the new model
if(releaseDefinition.changelog?.workItemFilter)
Expand Down
5 changes: 5 additions & 0 deletions packages/sfp-cli/src/commands/releasedefinition/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export default class Generate extends SfpCommand {
description: messages.getMessage('forcePushFlagDescription'),
dependsOn: ['push'],
}),
metadata: Flags.string({
char: 'm',
description: messages.getMessage('metadataFlagDescription'),
}),
loglevel
};

Expand All @@ -61,6 +65,7 @@ export default class Generate extends SfpCommand {
this.flags.configfile,
this.flags.releasename,
this.flags.branchname,
this.flags.metadata,
this.flags.directory,
this.flags.nopush,
this.flags.forcepush
Expand Down
15 changes: 7 additions & 8 deletions packages/sfp-cli/src/commands/repo/patch.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Messages } from '@salesforce/core';
import SfpCommand from '../../SfpCommand';
import ReleaseDefinition from '../../impl/release/ReleaseDefinition';
import ReleaseDefinitionLoader from '../../impl/release/ReleaseDefinitionLoader';
import ProjectConfig from '../../core/project/ProjectConfig';
import GroupConsoleLogs from '../../ui/GroupConsoleLogs';
import FetchImpl from '../../impl/artifacts/FetchImpl';
import ReleaseDefinitionSchema from '../../impl/release/ReleaseDefinitionSchema';
import ReleaseDefinition from '../../impl/release/ReleaseDefinition';
import path = require('path');
import ArtifactFetcher, { Artifact } from '../../core/artifacts/ArtifactFetcher';
import SfpPackage, { PackageType } from '../../core/package/SfpPackage';
Expand Down Expand Up @@ -127,7 +127,7 @@ export default class Patch extends SfpCommand {


private async fetchArtifacts(
releaseDefintions: ReleaseDefinitionSchema[],
releaseDefintions: ReleaseDefinition[],
fetchArtifactScript: string,
scope: string,
npmrcPath: string,
Expand All @@ -140,17 +140,16 @@ export default class Patch extends SfpCommand {
groupSection.end();
}

private async loadReleaseDefintions(releaseDefinitionPaths: []): Promise<ReleaseDefinitionSchema[]> {
let releaseDefinitions: ReleaseDefinitionSchema[] = [];
private async loadReleaseDefintions(releaseDefinitionPaths: []): Promise<ReleaseDefinition[]> {
let releaseDefinitions: ReleaseDefinition[] = [];
for (const pathToReleaseDefintion of releaseDefinitionPaths) {
let releaseDefinition = (await ReleaseDefinition.loadReleaseDefinition(pathToReleaseDefintion))
.releaseDefinition;
let releaseDefinition = await ReleaseDefinitionLoader.loadReleaseDefinition(pathToReleaseDefintion);
releaseDefinitions.push(releaseDefinition);
}
return releaseDefinitions;
}

private async overwriteModules(releaseDefinitions: ReleaseDefinitionSchema[], git: Git, logger: Logger) {
private async overwriteModules(releaseDefinitions: ReleaseDefinition[], git: Git, logger: Logger) {
let temporaryWorkingDirectory = git.getRepositoryPath();
let revisedProjectConfig = ProjectConfig.getSFDXProjectConfig(temporaryWorkingDirectory);
for (const releaseDefinition of releaseDefinitions) {
Expand Down
27 changes: 16 additions & 11 deletions packages/sfp-cli/src/impl/artifacts/FetchAnArtifactFromNPM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import * as fs from 'fs-extra';
import child_process = require('child_process');
import path = require('path');
import FetchAnArtifact from './FetchAnArtifact';
import SFPLogger, { COLOR_WARNING } from '@flxblio/sfp-logger';
import SFPLogger, { COLOR_WARNING, LoggerLevel } from '@flxblio/sfp-logger';

export class FetchAnArtifactFromNPM implements FetchAnArtifact {
constructor(private scope: string, private npmrcPath: string) {

//Check whether the user has already passed in @, and remove it
this.scope= this.scope.replace(/@/g, '').toLowerCase();

this.scope = this.scope.replace(/@/g, '').toLowerCase();

if (this.npmrcPath) {
try {
Expand Down Expand Up @@ -45,20 +43,27 @@ export class FetchAnArtifactFromNPM implements FetchAnArtifact {

cmd += `@${version}`;

console.log(`Fetching ${packageName} using ${cmd}`);
SFPLogger.log(`Fetching ${packageName} using ${cmd}`,LoggerLevel.INFO);

child_process.execSync(cmd, {
cwd: artifactDirectory,
stdio: 'pipe',
});
} catch (error) {
SFPLogger.log(
COLOR_WARNING(
`Artifact for ${packageName} not found in the NPM Registry provided, This might result in deployment failures, Try running with trace log level for more information`
),
LoggerLevel.INFO
);

SFPLogger.log(
error,
LoggerLevel.TRACE
);


if (!isToContinueOnMissingArtifact) throw error;
else
SFPLogger.log(
COLOR_WARNING(
`Artifact for ${packageName} missing in NPM Registry provided, This might result in deployment failures`
)
);
}
}
}
4 changes: 2 additions & 2 deletions packages/sfp-cli/src/impl/artifacts/FetchImpl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'fs-extra';
import Git from '../../core/git/Git';
import GitTags from '../../core/git/GitTags';
import ReleaseDefinitionSchema from '../release/ReleaseDefinitionSchema';
import ReleaseDefinition from '../release/ReleaseDefinition';
import FetchArtifactsError from './FetchArtifactsError';
import * as rimraf from 'rimraf';
import FetchArtifactSelector from './FetchArtifactSelector';
Expand All @@ -22,7 +22,7 @@ export default class FetchImpl {
}

public async fetchArtifacts(
releaseDefinitions: ReleaseDefinitionSchema[]
releaseDefinitions: ReleaseDefinition[]
): Promise<{
success: ArtifactVersion[];
failed: ArtifactVersion[];
Expand Down
6 changes: 3 additions & 3 deletions packages/sfp-cli/src/impl/deploy/DeployImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import * as _ from 'lodash';
import GroupConsoleLogs from '../../ui/GroupConsoleLogs';
import { ZERO_BORDER_TABLE } from '../../ui/TableConstants';
import convertBuildNumDotDelimToHyphen from '../../core/utils/VersionNumberConverter';
import ReleaseConfig from '../release/ReleaseConfig';
import ReleaseConfigLoader from '../release/ReleaseConfigLoader';
import fs from 'fs-extra';
import { Align, getMarkdownTable } from 'markdown-table-ts';
import FileOutputHandler from '../../outputs/FileOutputHandler';
Expand Down Expand Up @@ -327,8 +327,8 @@ export default class DeployImpl {
else
{
SFPLogger.log(COLOR_KEY_MESSAGE(`Filtering packages to be deployed based on release config ${COLOR_KEY_VALUE(releaseConfigPath)}`),LoggerLevel.INFO,logger);
let releaseConfig:ReleaseConfig = new ReleaseConfig(logger,releaseConfigPath);
let packages = releaseConfig.getPackagesAsPerReleaseConfig();
let releaseConfigLoader:ReleaseConfigLoader = new ReleaseConfigLoader(logger,releaseConfigPath);
let packages = releaseConfigLoader.getPackagesAsPerReleaseConfig();
//Filter artifacts based on packages
let filteredSfPPackages:SfpPackage[] = [];

Expand Down
11 changes: 6 additions & 5 deletions packages/sfp-cli/src/impl/prepare/PrepareImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import SFPStatsSender from '../../core/stats/SFPStatsSender';
import ExternalPackage2DependencyResolver from '../../core/package/dependencies/ExternalPackage2DependencyResolver';
import ExternalDependencyDisplayer from '../../core/display/ExternalDependencyDisplayer';
import ReleaseDefinitionGenerator from '../release/ReleaseDefinitionGenerator';
import ReleaseDefinitionSchema from '../release/ReleaseDefinitionSchema';
import ReleaseDefinition from '../release/ReleaseDefinition';
import { ZERO_BORDER_TABLE } from '../../ui/TableConstants';
import GroupConsoleLogs from '../../ui/GroupConsoleLogs';
import ReleaseConfig from '../release/ReleaseConfig';
import ReleaseConfigLoader from '../release/ReleaseConfigLoader';
import { COLOR_KEY_VALUE } from '@flxblio/sfp-logger';

const Table = require('cli-table');
Expand Down Expand Up @@ -114,11 +114,12 @@ export default class PrepareImpl {
'prepare',
'test',
undefined,
undefined,
true,
false,
true
);
let releaseDefinition = (await releaseDefinitionGenerator.exec()) as ReleaseDefinitionSchema;
let releaseDefinition = (await releaseDefinitionGenerator.exec()) as ReleaseDefinition;
return Object.keys(releaseDefinition.artifacts);
}
}
Expand Down Expand Up @@ -288,8 +289,8 @@ export default class PrepareImpl {

function includeOnlyPackagesAsPerReleaseConfig(releaseConfigFilePath:string,buildProps: BuildProps,logger?:Logger): BuildProps {
if (releaseConfigFilePath) {
let releaseConfig:ReleaseConfig = new ReleaseConfig(logger, releaseConfigFilePath);
buildProps.includeOnlyPackages = releaseConfig.getPackagesAsPerReleaseConfig();
let releaseConfigLoader:ReleaseConfigLoader = new ReleaseConfigLoader(logger, releaseConfigFilePath);
buildProps.includeOnlyPackages = releaseConfigLoader.getPackagesAsPerReleaseConfig();
printIncludeOnlyPackages(buildProps.includeOnlyPackages);
}
return buildProps;
Expand Down
Loading

0 comments on commit 4f33fd4

Please sign in to comment.