forked from dxatscale/sfpowerscripts
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(validate): only trigger tests from impacted packages (#39)
* feat(validate): only trigger tests for impacted packages Only trigger tests for impacted packages, other packages will be installed for synchronizing the org. If the same org is retried, it will be skipped BREAKING CHANGE: Changes the earlier behaviour across all validation modes fixes #5
- Loading branch information
1 parent
995bdbf
commit 799d26b
Showing
16 changed files
with
1,013 additions
and
989 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Trigger tests only for impacted packages during validate | ||
|
||
* Status: Approved | ||
* Deciders: @azlam-abdulsalam, @nbatterham, @Rocko1204 | ||
* Issue: #5 | ||
|
||
## Context and Problem Statement | ||
|
||
In the context of validating a change in CI/review orgs, sfp currently triggers all Apex tests for changed packages. However, these changes might not always be directly introduced by a developer from a branch. They could also result from syncing an upstream change or the org being a few commits behind. | ||
|
||
See the original issue by @petter-eikeland | ||
|
||
i.e. given that validate orgs were created at midnight, and 2 PRs have been merged to master/main changing package A and package B, respectively, both of which containing Apex classes and tests. When creating a 3rd PR, only changing package C (also with Apex classes and tests), validate would pick up changes in all 3 packages (A, B and C). In this scenario, validate deploys package A, and then executes the corresponding Apex tests. Then the same for package B and then finally package C. Ideally, validate would only deploy the (already validated) changes in package A and B (to update to validate org to what's on master/main), and only execute the Apex tests for package C. | ||
E.g. if 'git diff HEAD origin/master --quiet ' + package["path"] + '/*' --> then run Apex tests. If not, skip Apex tests for the package. | ||
|
||
This additional execution of Apex tests for already validated changes has an especially significant impact on our current cadence given Salesforce's infrastructure issues during release windows. | ||
|
||
This model introduces considerable delay when PRs are synchronized in sfops style `Review` environments, as the | ||
environment has a life cycle till the PR is addressed | ||
|
||
## Decision | ||
|
||
After reviewing multiple orgs, we've determined there's no added value in triggering Apex tests for packages that are synchronized rather than directly impacted. The changes in such packages are minimal since the PR doesn't introduce any new modifications to the out-of-sync packages. Therefore, it's more efficient to only trigger tests for the directly impacted packages. | ||
|
||
Initially, we considered adding a new flag and specific mode for this feature. However, to simplify adoption and because we foresee no significant impacts, we've decided against introducing a new mode. Instead, we will add flags to capture the SHA ref of the head of the incoming branch and the SHA ref of the base branch. It's crucial to ensure these refs are accurate and do not reflect any temporary detached commit IDs created by CI/CD systems such as GitHub. | ||
|
||
This also means the following changes to behavior of how validate works | ||
|
||
- Differentiate between packages that need to be synchronized vs validated | ||
- Allow validate to commit the changed packages in to the target org, reverting earlier change to disableArtifactUpdate,so | ||
users can control the behavior required, Ideally disableArtifactUpdate will be set to false, so retries to the same | ||
review org within a range of commits will save further time | ||
- Only commit the packages to an org, if the test pass for validate packages, however commit packages to org immediately for packages that are to be synchronized, when the deployment is succesful | ||
- Package Diff comparison logic need to be updated to ensure, that if the commit id in the org is incorrect, assume the package is never built | ||
|
||
|
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
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
25 changes: 25 additions & 0 deletions
25
packages/sfp-cli/src/core/display/ImpactedPackagesDisplayer.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,25 @@ | ||
import SFPLogger, { Logger, LoggerLevel } from '@flxbl-io/sfp-logger'; | ||
import { ZERO_BORDER_TABLE } from './TableConstants'; | ||
const Table = require('cli-table'); | ||
|
||
export default class ImpactedPackagesDisplayer { | ||
|
||
public static displayImpactedPackages(packagesToBeBuilt: Map<string, any>,logger:Logger) { | ||
let tableHead = ['Package', 'Reason', 'Last Known Commit Id/Tag']; | ||
let table = new Table({ | ||
head: tableHead, | ||
chars: ZERO_BORDER_TABLE, | ||
}); | ||
for (const pkg of packagesToBeBuilt.keys()) { | ||
let item = [ | ||
pkg, | ||
packagesToBeBuilt.get(pkg).reason, | ||
packagesToBeBuilt.get(pkg).tag ? packagesToBeBuilt.get(pkg).tag : '', | ||
]; | ||
table.push(item); | ||
} | ||
//Log Packages to be built | ||
SFPLogger.log(table.toString(),LoggerLevel.INFO,logger); | ||
} | ||
|
||
} |
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.