Skip to content

Commit

Permalink
feat: fail if promoted flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dieffrei committed May 28, 2024
1 parent ce11b8c commit 8db03f8
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 11 deletions.
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,12 +1,14 @@
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
) {}

public async promote(): Promise<void> {
Expand All @@ -26,7 +28,12 @@ export default class PromoteUnlockedPackageImpl {
result.id = packageVersionData.SubscriberPackageVersionId;
} catch (e) {
if (e.message.includes('previously released')) {
throw new Error(`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.`);
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

0 comments on commit 8db03f8

Please sign in to comment.