This repository has been archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(package): Resolve dependencies for Build (#1019)
* Resolve package dependencies in build Resolve package dependencies at the start of build and also dynamically, as dependencies are built. Take last validated package version created from the same branch, for packages from the same repo. Save resolved dependencies in artifact metadata and sfdx-project.json Fixes #496
- Loading branch information
Showing
16 changed files
with
691 additions
and
99 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
decision records/001-package-dependency-version-resolution.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Package dependency version resolution | ||
• Status: Accepted | ||
• Issue: #496 | ||
|
||
## Context and Problem Statement | ||
The Build command resolves package dependency versions, using `sfpowerkit:package:dependencies:list`, but there are several shortcomings with the current implementation: | ||
|
||
1. Executing sfpowerkit CLI in a node process | ||
1. The package versions are not filtered to the branch | ||
1. Dependencies on packages that are part of the same build are not guaranteed to pick up the version created in the build; it just fetches the LATEST version | ||
1. The resolved dependencies are not reflected in the artifact metadata or sfdx-project.json | ||
|
||
## Solution | ||
|
||
To address the first issue, the sfpowerkit command will be replaced with a direct API call and implementation within sfpowerscripts. This includes a fetcher for the Package2Version sObject. | ||
At the start of a build, the package dependencies will be resolved in one go, leaving dependencies on packages that are part of the same build to be resolved dynamically, as they are created. | ||
For dependencies on packages that are part of the same repo, the validated package versions are filtered to the current branch using git tags created by Publish. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 12 additions & 15 deletions
27
packages/core/src/package/coverage/PackageVersionCoverage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
packages/core/src/package/version/Package2VersionFetcher.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { Connection } from '@salesforce/core'; | ||
import QueryHelper from '../../queryHelper/QueryHelper'; | ||
import semver from 'semver'; | ||
|
||
/** | ||
* Fetcher for second-generation package version in Dev Hub | ||
*/ | ||
export default class Package2VersionFetcher { | ||
|
||
private readonly query: string = | ||
'Select SubscriberPackageVersionId, Package2Id, Package2.Name, IsPasswordProtected, IsReleased, MajorVersion, MinorVersion, PatchVersion, BuildNumber, CodeCoverage, HasPassedCodeCoverageCheck from Package2Version '; | ||
|
||
constructor(private conn: Connection) {} | ||
|
||
/** | ||
* Fetch Package2 versions by Package2 Id | ||
* Sorts by semantic version, in descending order | ||
* @param package2Id | ||
* @param versionNumber | ||
* @param isValidatedPackages | ||
* @returns | ||
*/ | ||
async fetchByPackage2Id(package2Id: string, versionNumber?: string, isValidatedPackages?: boolean): Promise<Package2Version[]> { | ||
let query = this.query; | ||
|
||
let whereClause: string = `where Package2Id='${package2Id}' `; | ||
|
||
if (versionNumber) { | ||
// TODO: validate version number | ||
const versions = versionNumber.split("."); | ||
|
||
if (versions[0]) whereClause += `and MajorVersion=${versions[0]} `; | ||
if (versions[1]) whereClause += `and MinorVersion=${versions[1]} `; | ||
if (versions[2]) whereClause += `and PatchVersion=${versions[2]} `; | ||
if (versions[3]) whereClause += `and BuildNumber=${versions[3]} `; | ||
} | ||
|
||
if (isValidatedPackages) whereClause += `and ValidationSkipped = false `; | ||
|
||
whereClause += `and IsDeprecated = false `; | ||
query += whereClause | ||
|
||
const records = await QueryHelper.query<Package2Version>(query, this.conn, true); | ||
return records.sort((a,b) => { | ||
const v1 = `${a.MajorVersion}.${a.MinorVersion}.${a.PatchVersion}-${a.BuildNumber}`; | ||
const v2 = `${b.MajorVersion}.${b.MinorVersion}.${b.PatchVersion}-${b.BuildNumber}`; | ||
return semver.rcompare(v1, v2); | ||
}); | ||
} | ||
|
||
async fetchBySubscriberPackageVersionId(subscriberPackageVersionId: string): Promise<Package2Version> { | ||
let query = this.query; | ||
|
||
let whereClause: string = `where SubscriberPackageVersionId='${subscriberPackageVersionId}'`; | ||
query += whereClause; | ||
|
||
const records = await QueryHelper.query<Package2Version>(query, this.conn, true); | ||
return records[0]; | ||
} | ||
} | ||
|
||
export interface Package2Version { | ||
SubscriberPackageVersionId: string; | ||
Package2Id: string; | ||
Package2: { Name: string }; | ||
IsPasswordProtected: boolean; | ||
IsReleased: boolean; | ||
MajorVersion: number; | ||
MinorVersion: number; | ||
PatchVersion: number; | ||
BuildNumber: number; | ||
CodeCoverage: { apexCodeCoveragePercentage: number }; | ||
HasPassedCodeCoverageCheck: boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.