Skip to content

Commit

Permalink
feat(install): install to support installation of single artifact
Browse files Browse the repository at this point in the history
allow install command to install a single artifact, this is required as individual install command
was deprecated
  • Loading branch information
azlam-abdulsalam committed Mar 6, 2024
1 parent 61f68a2 commit 85f440c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/sfp-cli/messages/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"tagFlagDescription": "Tag the build with a label, useful to identify in metrics",
"logsGroupSymbolFlagDescription": "Symbol used by CICD platform to group/collapse logs in the console. Provide an opening group, and an optional closing group symbol.",
"releaseConfigFileFlagDescription":"Path to the release config file(s) to limit packages built by domains",
"buildOnlyFlagDescription": "Only build artifacts for the provided packages, comma separated list of package names"
"buildOnlyFlagDescription": "Only build artifacts for the provided package names,use comma separated list of package names if there are multiple packages"
}
3 changes: 2 additions & 1 deletion packages/sfp-cli/messages/install.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"allowUnpromotedPackagesFlagDescription": "Allow un-promoted packages to be installed in production",
"retryOnFailureFlagDescription": "Retry on a failed deployment of a package",
"configFileFlagDescription":"Path to the config file which determines how the packages are deployed based on the filters in release config",
"enableSourceTrackingFlagDescription": "Enable source tracking on the packages being deployed to an org"
"enableSourceTrackingFlagDescription": "Enable source tracking on the packages being deployed to an org",
"artifactsOnlyFlagDescription": "Only install artifacts for the provided packages, use comma separated list of package names if there are multiple packages"
}
9 changes: 8 additions & 1 deletion packages/sfp-cli/src/commands/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class Install extends SfpCommand {
public static description = messages.getMessage('commandDescription');
static aliases = ['orchestrator:deploy','deploy']

public static examples = [`$ sfp install -u <username>`];
public static examples = [`$ sfp install -o <username>`];

protected static requiresUsername = false;
protected static requiresDevhubUsername = false;
Expand Down Expand Up @@ -64,6 +64,10 @@ export default class Install extends SfpCommand {
},
hidden: true,
}),
artifacts: arrayFlagSfdxStyle({
char: 'p',
description: messages.getMessage('artifactsOnlyFlagDescription'),
}),
retryonfailure: Flags.boolean({
description: messages.getMessage('retryOnFailureFlagDescription'),
hidden: true,
Expand All @@ -84,6 +88,8 @@ export default class Install extends SfpCommand {
SFPLogger.log(COLOR_HEADER(`command: ${COLOR_KEY_MESSAGE(`install`)}`));
SFPLogger.log(COLOR_HEADER(`Skip artifacts if already installed: ${this.flags.skipifalreadyinstalled}`));
SFPLogger.log(COLOR_HEADER(`Artifact Directory: ${this.flags.artifactdir}`));
if(this.flags.artifacts)
SFPLogger.log(COLOR_HEADER(`Artifacts to be installed: ${this.flags.artifacts }`));
SFPLogger.log(COLOR_HEADER(`Target Environment: ${this.flags.targetorg}`));
if(this.flags.releaseconfig) SFPLogger.log(COLOR_HEADER(`Filter according to: ${this.flags.releaseconfig}`));
if (this.flags.baselineorg) SFPLogger.log(COLOR_HEADER(`Baselined Against Org: ${this.flags.baselineorg}`));
Expand Down Expand Up @@ -112,6 +118,7 @@ export default class Install extends SfpCommand {
baselineOrg: this.flags.baselineorg,
isRetryOnFailure: this.flags.retryonfailure,
releaseConfigPath: this.flags.releaseconfig,
filterByProvidedArtifacts: this.flags.artifacts
};

try {
Expand Down
8 changes: 4 additions & 4 deletions packages/sfp-cli/src/flags/sfdxflags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ const userNameFlag = Flags.custom({
});

export const optionalUserNameFlag = userNameFlag({
aliases: ['targetusername', 'u'],
char: 'u',
aliases: ['targetusername', 'u','o'],
char: 'o',
});

export const requiredUserNameFlag = userNameFlag({
aliases: ['targetusername', 'u'],
char: 'u',
aliases: ['targetusername', 'u','o'],
char: 'o',
required: true,
});

Expand Down
28 changes: 25 additions & 3 deletions packages/sfp-cli/src/impl/deploy/DeployImpl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ArtifactFetcher, { Artifact } from '../../core/artifacts/ArtifactFetcher';
import SFPLogger, { COLOR_ERROR, COLOR_SUCCESS, FileLogger, Logger, LoggerLevel } from '@flxblio/sfp-logger';
import { EOL } from 'os';
import { Stage } from '../Stage';
import ProjectConfig from '../../core/project/ProjectConfig';
import semver = require('semver');
Expand Down Expand Up @@ -58,6 +57,7 @@ export interface DeployProps {
selectiveComponentDeployment?: boolean;
maxRetryCount?:number;
releaseConfigPath?:string;
filterByProvidedArtifacts?:string[];
}

export default class DeployImpl {
Expand Down Expand Up @@ -99,8 +99,11 @@ export default class DeployImpl {


//Filter artifacts based on release config
sfpPackages = this.filterSfPPackagesBasedOnReleaseConfig(sfpPackages,this.props.releaseConfigPath,this.props.logger);

if(this.props.releaseConfigPath)
sfpPackages = this.filterSfPPackagesBasedOnReleaseConfig(sfpPackages,this.props.releaseConfigPath,this.props.logger);
else if(this.props.filterByProvidedArtifacts)
sfpPackages = this.filterSfPPackagesBasedOnArtifacts(sfpPackages,this.props.filterByProvidedArtifacts,this.props.logger);

//Grab the latest projectConfig from Packages
let sfpPackageInquirer: SfpPackageInquirer = new SfpPackageInquirer(sfpPackages, this.props.logger);
let sfdxProjectConfig = sfpPackageInquirer.getLatestProjectConfig();
Expand Down Expand Up @@ -342,6 +345,25 @@ export default class DeployImpl {

}

private filterSfPPackagesBasedOnArtifacts(sfpPackages: SfpPackage[], artifacts:string[],logger:Logger): SfpPackage[] {
if(!artifacts || artifacts.length==0)
return sfpPackages;
else
{
SFPLogger.log(COLOR_KEY_MESSAGE(`Filtering packages to be deployed based on provided artifacts ${COLOR_KEY_VALUE(artifacts)}`),LoggerLevel.INFO,logger);
//Filter artifacts based on packages
let filteredSfPPackages:SfpPackage[] = [];

for (const sfpPackage of sfpPackages) {
if (artifacts.includes(sfpPackage.packageName)) {
filteredSfPPackages.push(sfpPackage);
}
}
return filteredSfPPackages;
}

}


private async generateSfpPackageFromArtifacts(artifacts: Artifact[]): Promise<SfpPackage[]> {
let sfpPackages: SfpPackage[] = [];
Expand Down

0 comments on commit 85f440c

Please sign in to comment.