Skip to content

Commit

Permalink
fix(validate): validate should use the target org as the baseline
Browse files Browse the repository at this point in the history
validate should use the target org as the baseline as opposed to devhub during validation, as the
org can behind as compared to devhub
  • Loading branch information
azlam-abdulsalam committed Feb 29, 2024
1 parent 9684f81 commit 340a95c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/sfp-cli/src/core/package/SfpPackageBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ export default class SfpPackageBuilder {
export class PackageCreationParams {
breakBuildIfEmpty: boolean = true;
devHub?: string;
baselineOrg?:string;
installationkeybypass?: boolean;
installationkey?: string;
waitTime?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ export default class CreateDiffPackageImp extends CreateSourcePackageImpl {
async preCreatePackage(sfpPackage: SfpPackage) {
const devhubOrg = await SFPOrg.create({ aliasOrUsername: this.packageCreationParams.devHub });

//Fetch Baseline commit from DevHub
let commitsOfPackagesInstalledInDevHub = await this.getCommitsOfPackagesInstalledInDevHub(devhubOrg);
//Fetch Baseline commit from DevHub or the provided org for validation
let commitsOfPackagesInstalled = {};
if (this.packageCreationParams.baselineOrg) {
let baselineOrg = await SFPOrg.create({ aliasOrUsername: this.packageCreationParams.baselineOrg });
commitsOfPackagesInstalled = await this.getCommitsOfPackagesInstalledInOrg(baselineOrg);
} else {
commitsOfPackagesInstalled = await this.getCommitsOfPackagesInstalledInOrg(devhubOrg);
}

if (this.packageCreationParams.revisionFrom) {
this.sfpPackage.commitSHAFrom = this.packageCreationParams.revisionFrom;
} else if (commitsOfPackagesInstalledInDevHub[this.sfpPackage.packageName]) {
this.sfpPackage.commitSHAFrom = commitsOfPackagesInstalledInDevHub[this.sfpPackage.packageName];
} else if (commitsOfPackagesInstalled[this.sfpPackage.packageName]) {
this.sfpPackage.commitSHAFrom = commitsOfPackagesInstalled[this.sfpPackage.packageName];
} else {
this.sfpPackage.commitSHAFrom = this.sfpPackage.sourceVersion;
}
Expand All @@ -59,7 +65,7 @@ export default class CreateDiffPackageImp extends CreateSourcePackageImpl {
}
}

private async getCommitsOfPackagesInstalledInDevHub(diffTargetSfpOrg: SFPOrg) {
private async getCommitsOfPackagesInstalledInOrg(diffTargetSfpOrg: SFPOrg) {
let installedArtifacts = await diffTargetSfpOrg.getInstalledArtifacts();
let packagesInstalledInOrgMappedToCommits = await this.mapInstalledArtifactstoPkgAndCommits(installedArtifacts);
return packagesInstalledInOrgMappedToCommits;
Expand Down
2 changes: 2 additions & 0 deletions packages/sfp-cli/src/impl/parallelBuilder/BuildImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface BuildProps {
configFilePath?: string;
projectDirectory?: string;
devhubAlias?: string;
baselineOrgAlias?:string;
repourl?: string;
waitTime: number;
isQuickBuild: boolean;
Expand Down Expand Up @@ -773,6 +774,7 @@ export default class BuildImpl {
},
{
devHub: this.props.devhubAlias,
baselineOrg: this.props.baselineOrgAlias,
installationkeybypass: true,
installationkey: undefined,
waitTime: this.props.waitTime.toString(),
Expand Down
5 changes: 3 additions & 2 deletions packages/sfp-cli/src/impl/validate/ValidateImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,8 @@ export default class ValidateImpl implements PostDeployHook, PreDeployHook {
isBuildAllAsSourcePackages: !this.props.disableSourcePackageOverride,
currentStage: Stage.VALIDATE,
baseBranch: this.props.baseBranch,
devhubAlias: this.props.hubOrg?.getUsername()
devhubAlias: this.props.hubOrg?.getUsername(),
baselineOrgAlias: this.props.targetOrg
};

//Build DiffOptions
Expand Down Expand Up @@ -577,7 +578,7 @@ export default class ValidateImpl implements PostDeployHook, PreDeployHook {
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
SFPLogger.log(
COLOR_SUCCESS(
`${generatedPackages.length} packages created in ${COLOR_TIME(
`${generatedPackages.length} artifacts created in ${COLOR_TIME(
getFormattedTime(totalElapsedTime),
)} with {${COLOR_ERROR(failedPackages.length)}} errors`,
),
Expand Down

0 comments on commit 340a95c

Please sign in to comment.