Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

53 - Package promotion enhancement #61

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ packages/apexlink/coverage
packages/sfp-cli/oclif.manifest.json
packages/apexlink/tests/resources/core-crm/apexlink.json
packages/apexlink/tests/resources/feature-mgmt/apexlink.json
.nx
.nx
.idea/
3 changes: 2 additions & 1 deletion packages/sfp-cli/messages/promote.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"artifactDirectoryFlagDescription": "The directory where artifacts are located",
"outputDirectoryFlagDescription": "Output directory where promoted artifacts are written",
"devhubAliasFlagDescription": "Provide the alias of the devhub previously authenticated, default value is HubOrg if using the Authenticate Devhub task",
"logsGroupSymbolFlagDescription": "Symbol used by CICD platform to group/collapse logs in the console. Provide an opening group, and an optional closing group symbol."
"logsGroupSymbolFlagDescription": "Symbol used by CICD platform to group/collapse logs in the console. Provide an opening group, and an optional closing group symbol.",
"failifalreadypromotedFlagDescription": "Fail if version: \"major.minor.patch\" was already promoted"
}
3 changes: 2 additions & 1 deletion packages/sfp-cli/messages/release.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"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",
"changelogByDomainsFlagDescription":"Create changelog files by domains or name mentioned in release config"
"changelogByDomainsFlagDescription":"Create changelog files by domains or name mentioned in release config",
"failifalreadypromotedFlagDescription": "Fail if version: \"major.minor.patch\" was already promoted"
}
11 changes: 9 additions & 2 deletions packages/sfp-cli/src/commands/artifacts/promote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const messages = Messages.loadMessages('@flxbl-io/sfp', 'promote');
export default class Promote extends SfpCommand {
public static description = messages.getMessage('commandDescription');
static aliases = ['orchestrator:promote']


public static examples = [`$ sfp promote -d path/to/artifacts -v <org>`];

Expand All @@ -31,6 +31,12 @@ export default class Promote extends SfpCommand {
description: messages.getMessage('artifactDirectoryFlagDescription'),
default: 'artifacts',
}),
failifalreadypromoted: Flags.boolean({
required: true,
char: 'x',
description: messages.getMessage('failifalreadypromotedFlagDescription'),
default: false,
}),
loglevel
};

Expand Down Expand Up @@ -59,7 +65,8 @@ export default class Promote extends SfpCommand {
let promoteUnlockedPackageImpl = new PromoteUnlockedPackageImpl(
artifact.sourceDirectoryPath,
sfpPackage.package_version_id,
this.hubOrg.getUsername()
this.hubOrg.getUsername(),
this.flags.failifalreadypromoted
);
await promoteUnlockedPackageImpl.promote();
}
Expand Down
7 changes: 7 additions & 0 deletions packages/sfp-cli/src/commands/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ export default class Release extends SfpCommand {
description: messages.getMessage('changelogByDomainsFlagDescription'),
hidden: true,
}),
failifalreadypromoted: Flags.boolean({
required: true,
char: 'x',
description: messages.getMessage('failifalreadypromotedFlagDescription'),
default: false,
}),
devhubalias: optionalDevHubFlag,
loglevel,
};
Expand Down Expand Up @@ -171,6 +177,7 @@ export default class Release extends SfpCommand {
devhubUserName: this.flags.devhubalias,
branch: this.flags.branchname,
directory: this.flags.directory,
failifalreadypromoted: this.flags.failifalreadypromoted
};

let releaseImpl: ReleaseImpl = new ReleaseImpl(props, new ConsoleLogger());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import SFPLogger from '@flxbl-io/sfp-logger';
import { SfProject } from '@salesforce/core';
import { PackageSaveResult, PackageVersion } from '@salesforce/packaging';
import SFPOrg from '../../org/SFPOrg';
import SFPLogger, {COLOR_HEADER} from "@flxbl-io/sfp-logger";

export default class PromoteUnlockedPackageImpl {
public constructor(
private project_directory: string,
private package_version_id: string,
private devhub_alias: string
private devhub_alias: string,
private fail_if_is_alreadyPromoted: boolean
) {}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why variable name in the constructor have this different naming convention?
Can I use always camel case?
@azlam-abdulsalam


public async promote(): Promise<void> {
Expand All @@ -27,7 +28,12 @@ export default class PromoteUnlockedPackageImpl {
result.id = packageVersionData.SubscriberPackageVersionId;
} catch (e) {
if (e.message.includes('previously released')) {
SFPLogger.log(`Package ${this.package_version_id} is already promoted, Ignoring`);
let errorMessage:string = `The package version ${packageVersionData.MajorVersion}.${packageVersionData.MinorVersion}.${packageVersionData.PatchVersion} was already promoted in a previous build. For a given this version number, you can promote only one version.`;
if (this.fail_if_is_alreadyPromoted) {
throw new Error(errorMessage);
} else {
SFPLogger.log(COLOR_HEADER(errorMessage));
}
} else throw e;
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/sfp-cli/src/impl/deploy/DeployImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface DeployProps {
releaseConfigPath?: string;
filterByProvidedArtifacts?: string[];
impactedPackagesAsPerBranch?: Map<string, string[]>;
failifalreadypromoted?: boolean;
}

export default class DeployImpl {
Expand Down Expand Up @@ -409,7 +410,8 @@ export default class DeployImpl {
let promoteUnlockedPackageImpl: PromoteUnlockedPackageImpl = new PromoteUnlockedPackageImpl(
sourceDirectory,
sfpPackage.package_version_id,
this.props.devhubUserName
this.props.devhubUserName,
this.props.failifalreadypromoted
);
await promoteUnlockedPackageImpl.promote();
}
Expand Down
10 changes: 6 additions & 4 deletions packages/sfp-cli/src/impl/release/ReleaseImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface ReleaseProps {
devhubUserName: string;
branch: string;
directory: string;
failifalreadypromoted: boolean
}

type DeploymentStatus = {
Expand All @@ -46,7 +47,7 @@ type DeploymentStatus = {

export default class ReleaseImpl {



constructor(private props: ReleaseProps, private logger?: Logger) {}

Expand Down Expand Up @@ -81,7 +82,7 @@ export default class ReleaseImpl {
SFPLogger.log(`Clearing installation output`, LoggerLevel.TRACE, this.logger);
FileOutputHandler.getInstance().deleteOutputFile(`deployment-breakdown.md`);
FileOutputHandler.getInstance().deleteOutputFile(`release-changelog.md`);

let deploymentResults = await this.deployArtifacts(sortedReleaseDefns);

//Get all suceeded deploys
Expand Down Expand Up @@ -229,7 +230,7 @@ export default class ReleaseImpl {
return numberOfCommits;
}



private async deployArtifacts(releaseDefinitions: ReleaseDefinition[]): Promise<DeploymentStatus[]> {
let deploymentResults: { releaseDefinition: ReleaseDefinition; result: DeploymentResult }[] = [];
Expand Down Expand Up @@ -257,6 +258,7 @@ export default class ReleaseImpl {
: false,
promotePackagesBeforeDeploymentToOrg: releaseDefinition.promotePackagesBeforeDeploymentToOrg,
devhubUserName: this.props.devhubUserName,
failifalreadypromoted: this.props.failifalreadypromoted
};

FileOutputHandler.getInstance().appendOutput(`deployment-breakdown.md`,`## ReleaseConfig: ${releaseDefinition.releaseConfigName?releaseDefinition.releaseConfigName:""}\n`);
Expand All @@ -281,7 +283,7 @@ export default class ReleaseImpl {

let sfpPackageInquirer: SfpPackageInquirer = new SfpPackageInquirer(sfpPackages, logger);
let sfdxProjectConfig = sfpPackageInquirer.getLatestProjectConfig();

let releaseDefinitionSorter = new ReleaseDefinitionSorter();
return releaseDefinitionSorter.sortReleaseDefinitions(releaseDefns, sfdxProjectConfig, logger);
}
Expand Down
Loading