Skip to content

Commit

Permalink
Update packaging scripts to modify the package dependencies with the …
Browse files Browse the repository at this point in the history
…new versions (#11623)

* Keep test output modifying to catch all dependencies

* Update packaging script to handle dependency versions

* Fix ouput logging and clean up

* Update the repackage-for-release script to support dependency versions

* Small fix

* Enable cleanup of the repackTempDirectory again.
  • Loading branch information
shaynie authored Jun 19, 2023
1 parent 8351e18 commit 177e8ac
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 19 deletions.
44 changes: 42 additions & 2 deletions Pipelines/Scripts/pack-upm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ Write-Output "Release packages: $releasePkgs"

try {
Push-Location $OutputDirectory

$parseVersion = -not $Version


# loop through package directories, update package version, assembly version, and build version hash for updating dependencies
Get-ChildItem -Path $ProjectRoot/*/package.json | ForEach-Object {
$packageName = Select-String -Pattern "com\.microsoft\.mrtk\.\w+" -Path $_ | Select-Object -First 1

Expand Down Expand Up @@ -109,7 +110,7 @@ try {
Write-Output "buildTag: $buildTag"


$versionHash[$packageName]=$Version
$versionHash[$packageName]="$Version-$buildTag"

Write-Output " Version: $Version"
Write-Output " suffix: $suffix"
Expand All @@ -124,9 +125,48 @@ try {
Add-Content -Path $_ -Value "[assembly: AssemblyInformationalVersion(`"$Version-$buildTag`")]"
}


}

# update dependencies using the versionHash map
Get-ChildItem -Path $ProjectRoot/*/package.json | ForEach-Object {
$currentPackageName = Select-String -Pattern "com\.microsoft\.mrtk\.\w+" -Path $_ | Select-Object -First 1
if (-not $currentPackageName) {
return # this is not an MRTK package, so skip
}

$currentPackageName = $currentPackageName.Matches[0].Value
$packageFriendlyName = (Select-String -Pattern "`"displayName`": `"(.+)`"" -Path $_ | Select-Object -First 1).Matches.Groups[1].Value

$packagePath = $_.Directory
$docFolder = "$packagePath/Documentation~"


Write-Output "____________________________________________________________________________"
Write-Output " Package: $($currentPackageName)"

foreach ($packageName in $versionHash.Keys) {
if ($currentPackageName -eq $packageName) {
continue
}

$searchRegex = "$($packageName).*:.*""(.*)"""
$searchMatches = Select-String $searchRegex -InputObject (Get-Content -Path $_)
if ($searchMatches.Matches.Groups) {
$newVersion = $versionHash["$($packageName)"]
Write-Output " Patching dependency $($packageName) from $($searchMatches.Matches.Groups[1].Value) to $($newVersion)"
(Get-Content -Path $_ -Raw) -Replace $searchRegex, "$($packageName)"": ""$($newVersion)""" | Set-Content -Path $_ -NoNewline
}
}

Write-Output "____________________________________________________________________________`n"

# build the package
Write-Output "Packing $packageFriendlyName"
npm pack $packagePath


# clean up
if (Test-Path -Path $docFolder) {
Write-Output "Cleaning up Documentation~ from $packageFriendlyName"
# A documentation folder was created. Remove it.
Expand Down
58 changes: 41 additions & 17 deletions Pipelines/Scripts/repackage-for-release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
The root folder of the project.
.PARAMETER OutputDirectory
Where should we place the output? Defaults to ".\artifacts"
.PARAMETER BuildNumber
The fourth digit (revision) for the full version.
.PARAMETER PreviewTag
The tag to append after the version, including the preview number (e.g. "internal.0" or "pre.100")
.PARAMETER Revision
The revision number for the build. (e.g. "230508.3" or "2")
.PARAMETER ReleasePackages
An array of the package names that are approved for release. If the package isn't in this array, it will get labeled -pre
#>
param(
[Parameter(Mandatory = $true)]
Expand Down Expand Up @@ -61,8 +53,6 @@ try {
}

$packageName = $packageName.Matches[0].Value
$packageFriendlyName = (Select-String -Pattern "`"displayName`": `"(.+)`"" -Path $_ | Select-Object -First 1).Matches.Groups[1].Value

$packagePath = $_.Directory

Write-Output ""
Expand All @@ -82,23 +72,57 @@ try {

Write-Output "Version: $version prerelease: $prerelease tag: $tag build: $build"

$versionHash[$packageName]=$version
$newVersion = "$($version)$($tag)"

$versionHash[$packageName]=$newVersion

Write-Output " Version: $version"

Write-Output "Patching package version to $version$tag"
((Get-Content -Path $_ -Raw) -Replace '("version": )"(?:[0-9.]+|%version%)-?[a-zA-Z0-9.]*', "`$1`"$version$tag") | Set-Content -Path $_ -NoNewline
Write-Output "Patching package version to $newVersion"
((Get-Content -Path $_ -Raw) -Replace '("version": )"(?:[0-9.]+|%version%)-?[a-zA-Z0-9.]*', "`$1`"$newVersion") | Set-Content -Path $_ -NoNewline

Write-Output "Patching assembly version to $version$tag"
Write-Output "Patching assembly version to $newVersion"
Get-ChildItem -Path $packagePath/AssemblyInfo.cs -Recurse | ForEach-Object {
(Get-Content -Path $_ -Raw) -Replace '\[assembly:.AssemblyVersion\(.*', "[assembly: AssemblyVersion(`"$version.0`")]`r" | Set-Content -Path $_ -NoNewline
((Get-Content -Path $_ -Raw) -Replace "assembly: AssemblyFileVersion\`(\`".*\`"", "assembly: AssemblyFileVersion(`"$version$tag`"") | Set-Content -Path $_ -NoNewline
((Get-Content -Path $_ -Raw) -Replace "assembly: AssemblyInformationalVersion\`(\`".*\`"", "assembly: AssemblyInformationalVersion(`"$version$tag`"") | Set-Content -Path $_ -NoNewline
((Get-Content -Path $_ -Raw) -Replace "assembly: AssemblyFileVersion\`(\`".*\`"", "assembly: AssemblyFileVersion(`"$newVersion`"") | Set-Content -Path $_ -NoNewline
((Get-Content -Path $_ -Raw) -Replace "assembly: AssemblyInformationalVersion\`(\`".*\`"", "assembly: AssemblyInformationalVersion(`"$newVersion`"") | Set-Content -Path $_ -NoNewline
}

}
# update all dependencies and repackage
Get-ChildItem -Path $packageSearchPath | ForEach-Object {
$currentPackageName = Select-String -Pattern "com\.microsoft\.mrtk\.\w+" -Path $_.FullName | Select-Object -First 1

if (-not $currentPackageName) {
return # this is not an MRTK package, so skip
}

$currentPackageName = $currentPackageName.Matches[0].Value
$packageFriendlyName = (Select-String -Pattern "`"displayName`": `"(.+)`"" -Path $_ | Select-Object -First 1).Matches.Groups[1].Value

$packagePath = $_.Directory

Write-Output "____________________________________________________________________________"
Write-Output " Package: $($currentPackageName)"

foreach ($packageName in $versionHash.Keys) {
if ($currentPackageName -eq $packageName) {
continue
}

$searchRegex = "$($packageName)""\s*:.*""(.*)"""
$searchMatches = Select-String $searchRegex -InputObject (Get-Content -Path $_)
if ($searchMatches.Matches.Groups) {
$newVersion = $versionHash["$($packageName)"]
Write-Output " Patching dependency $($packageName) from $($searchMatches.Matches.Groups[1].Value) to $($newVersion)"
(Get-Content -Path $_ -Raw) -Replace $searchRegex, "$($packageName)"": ""$($newVersion)""" | Set-Content -Path $_ -NoNewline
}
}

Write-Output "____________________________________________________________________________`n"

Write-Output "Packing $packageFriendlyName to $OutputDirectory"
npm pack $packagePath -pack-destination $OutputDirectory

}
}
finally {
Expand Down

0 comments on commit 177e8ac

Please sign in to comment.