Last active
July 31, 2023 17:18
-
-
Save goto-dev-null/573561f5eb3a013cc5954069e403c959 to your computer and use it in GitHub Desktop.
PowerShell script to install latest versions of a package on a certain branch to a target org
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
param( | |
[Parameter(Mandatory = $True)] | |
[string]$BranchName, | |
[Parameter(Mandatory = $True)] | |
[string]$TargetOrg | |
) | |
$ErrorActionPreference = "Stop" | |
Import-Module -Force "$PSScriptRoot\Invoke-Sf.psm1" | |
$PackageNames = Get-PackageNamesInDependencyOrder | |
$AllPackageVersions = Invoke-SfJson package version list | |
$BranchPackagesVersions = $AllPackageVersions | Where-Object Branch -EQ $BranchName | |
function Get-PackageNamesInDependencyOrder { | |
$ProjectJson = Get-Content "./sfdx-project.json" | ConvertFrom-Json | |
return $ProjectJson.packageDirectories | Where-Object package -NE $null | Select-Object -ExpandProperty package | |
} | |
function Get-LatestSubscriberVersionIdForPackage($PackageVersions, $PackageName){ | |
$SubjectPackageVersions = $PackageVersions | Where-Object Package2Name -EQ $PackageName | |
if($SubjectPackageVersions.Count -EQ 0){ | |
Write-Error "No package versions found for package $PackageName" | |
return | |
} | |
$SubscriberVersionId = $SubjectPackageVersions[-1].SubscriberPackageVersionId | |
Write-Host "$($PackageName): $SubscriberVersionId" | |
return $SubscriberVersionId | |
} | |
$PackageVersionsToInstall = @() | |
ForEach($PackageName in $PackageNames){ | |
$PackageVersionsToInstall += Get-LatestSubscriberVersionIdForPackage $BranchPackagesVersions $PackageName | |
} | |
scripts/Install-Package.ps1 -Org $TargetOrg -PackageIds $PackageVersionsToInstall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment