Skip to content

Commit 432ccff

Browse files
authored
Merge pull request #9928 from microsoft/fix-pipeline
Add ability to repack in the packaging pipeline
2 parents dfd16de + 22b22d6 commit 432ccff

File tree

3 files changed

+165
-125
lines changed

3 files changed

+165
-125
lines changed

pipelines/packageupmpublic.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ variables:
44
- template: config/settings.yml
55

66
parameters:
7+
- name: SourcePipeline
8+
type: string
9+
default: stabilization_ci
10+
values:
11+
- stabilization_ci
12+
- mrtk_ci
713
- name: PreviewNumber
814
type: number
915
default: -1
@@ -14,9 +20,25 @@ jobs:
1420
pool:
1521
vmImage: windows-2019
1622
steps:
23+
- task: DownloadPipelineArtifact@2
24+
displayName: Download tarballs
25+
inputs:
26+
source: specific
27+
project: $(System.TeamProjectId)
28+
${{ if eq(parameters.SourcePipeline, 'stabilization_ci') }}:
29+
pipeline: 32
30+
${{ if eq(parameters.SourcePipeline, 'mrtk_ci') }}:
31+
pipeline: 15
32+
runVersion: latestFromBranch
33+
runBranch: $(Build.SourceBranch)
34+
artifactName: mrtk-upm
35+
path: $(Agent.TempDirectory)
36+
1737
- template: templates/tasks/pack-upm.yml
1838
parameters:
1939
${{ if ge(parameters.PreviewNumber, 0) }}:
2040
previewNumber: ${{ parameters.PreviewNumber }}
2141
${{ if lt(parameters.PreviewNumber, 0) }}:
2242
previewNumber: ""
43+
projectRoot: $(Agent.TempDirectory)
44+
repack: true

pipelines/templates/tasks/pack-upm.yml

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,47 @@ parameters:
55
outputDirectory: $(Build.ArtifactStagingDirectory)\build\upm\output
66
version: $(MRTKVersion)
77
previewNumber: $(Build.BuildNumber)
8+
repack: false
89

910
steps:
1011
- task: NodeTool@0
1112
inputs:
1213
versionSpec: '12.18.0'
1314

14-
- ${{ if not(eq(parameters.previewNumber, '')) }}:
15-
- task: PowerShell@2
15+
- task: PowerShell@2
16+
${{ if not(eq(parameters.previewNumber, '')) }}:
1617
displayName: 'Build PREVIEW UPM packages'
17-
inputs:
18-
targetType: filePath
19-
filePath: ./scripts/packaging/createupmpackages.ps1
20-
arguments: >
21-
-ProjectRoot ${{ parameters.projectRoot }}
22-
-OutputDirectory ${{ parameters.outputDirectory }}
23-
-Version ${{ parameters.version }}
24-
-PreviewNumber ${{ parameters.previewNumber }}
25-
26-
- ${{ if eq(parameters.previewNumber, '') }}:
27-
- task: PowerShell@2
18+
${{ if eq(parameters.previewNumber, '') }}:
2819
displayName: 'Build OFFICIAL UPM packages'
29-
inputs:
30-
targetType: filePath
31-
filePath: ./scripts/packaging/createupmpackages.ps1
32-
arguments: >
33-
-ProjectRoot ${{ parameters.projectRoot }}
34-
-OutputDirectory ${{ parameters.outputDirectory }}
35-
-Version ${{ parameters.version }}
20+
inputs:
21+
targetType: filePath
22+
filePath: ./scripts/packaging/createupmpackages.ps1
23+
${{ if not(eq(parameters.previewNumber, '')) }}:
24+
${{ if eq(parameters.repack, true) }}:
25+
arguments: >
26+
-ProjectRoot ${{ parameters.projectRoot }}
27+
-OutputDirectory ${{ parameters.outputDirectory }}
28+
-Version ${{ parameters.version }}
29+
-PreviewNumber ${{ parameters.previewNumber }}
30+
-Repack
31+
${{ if eq(parameters.repack, false) }}:
32+
arguments: >
33+
-ProjectRoot ${{ parameters.projectRoot }}
34+
-OutputDirectory ${{ parameters.outputDirectory }}
35+
-Version ${{ parameters.version }}
36+
-PreviewNumber ${{ parameters.previewNumber }}
37+
${{ if eq(parameters.previewNumber, '') }}:
38+
${{ if eq(parameters.repack, true) }}:
39+
arguments: >
40+
-ProjectRoot ${{ parameters.projectRoot }}
41+
-OutputDirectory ${{ parameters.outputDirectory }}
42+
-Version ${{ parameters.version }}
43+
-Repack
44+
${{ if eq(parameters.repack, false) }}:
45+
arguments: >
46+
-ProjectRoot ${{ parameters.projectRoot }}
47+
-OutputDirectory ${{ parameters.outputDirectory }}
48+
-Version ${{ parameters.version }}
3649
3750
- task: PublishBuildArtifacts@1
3851
displayName: 'Publish UPM artifacts'

scripts/packaging/createupmpackages.ps1

Lines changed: 110 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@
1414
What version of the artifacts should we build?
1515
.PARAMETER PreviewNumber
1616
The preview number to append to the version. Note: Exclude this parameter to create non-preview packages.
17+
.PARAMETER Repack
18+
Add this switch if ProjectRoot represents a folder with existing tarballs to be patched and repacked.
1719
#>
1820
param(
1921
[string]$ProjectRoot,
2022
[string]$OutputDirectory = "./artifacts/upm",
2123
[ValidatePattern("^\d+\.\d+\.\d+-?[a-zA-Z0-9\.]*$")]
2224
[string]$Version,
2325
[ValidatePattern("^\d+?[\.\d+]*$")]
24-
[string]$PreviewNumber
26+
[string]$PreviewNumber,
27+
[switch]$Repack
2528
)
2629

27-
[string]$startPath = $(Get-Location)
28-
2930
if (-not $ProjectRoot) {
3031
throw "Missing required parameter: -ProjectRoot."
3132
}
@@ -47,8 +48,6 @@ if (-not (Test-Path $OutputDirectory -PathType Container)) {
4748
$OutputDirectory = Resolve-Path -Path $OutputDirectory
4849
Write-Output "OutputDirectory: $OutputDirectory"
4950

50-
$scriptPath = "$ProjectRoot/scripts/packaging"
51-
5251
$scope = "com.microsoft.mixedreality"
5352
$product = "toolkit"
5453

@@ -66,13 +65,9 @@ $product = "toolkit"
6665
$packages = [ordered]@{
6766
"foundation" = "Assets/MRTK";
6867
"standardassets" = "Assets/MRTK/StandardAssets";
69-
# extensions
7068
"extensions" = "Assets/MRTK/Extensions";
71-
# tools
7269
"tools" = "Assets/MRTK/Tools";
73-
# tests
7470
"testutilities" = "Assets/MRTK/Tests/TestUtilities";
75-
# examples
7671
"examples" = "Assets/MRTK/Examples";
7772
}
7873

@@ -87,124 +82,134 @@ $packages = [ordered]@{
8782

8883
# Create and publish the packages
8984
foreach ($entry in $packages.GetEnumerator()) {
90-
$packageFolder = $entry.Value
91-
$packagePath = Resolve-Path -Path "$ProjectRoot/$packageFolder"
92-
93-
# Switch to the folder containing the package.json file
94-
Set-Location $packagePath
95-
96-
# The package manifest files what we use are actually templates,
97-
# rename the files so that npm can consume them.
98-
Rename-Item -Path "$packagePath/packagetemplate.json" -NewName "$packagePath/package.json"
99-
Rename-Item -Path "$packagePath/packagetemplate.json.meta" -NewName "$packagePath/package.json.meta"
100-
101-
# Apply the version number to the package json file
102-
$packageJsonPath = "$packagePath/package.json"
103-
$packageJson = [System.IO.File]::ReadAllText($packageJsonPath)
104-
$packageJson = ($packageJson -replace "%version%", $Version)
105-
[System.IO.File]::WriteAllText($packageJsonPath, $packageJson)
106-
10785
# Create and publish the package
10886
$packageName = $entry.Name
10987

110-
$docFolder = "$packagePath/Documentation~"
111-
112-
# Copy files used by UPM to display license, change log, etc.
113-
Copy-Item -Path "$ProjectRoot/LICENSE.md" -Destination "$packagePath"
114-
Copy-Item -Path "$ProjectRoot/UPM/UnityMetaFiles/LICENSE.md.meta.$packageName" -Destination "$packagePath/LICENSE.md.meta"
115-
Copy-Item -Path "$ProjectRoot/NOTICE.md" -Destination "$packagePath"
116-
Copy-Item -Path "$ProjectRoot/UPM/UnityMetaFiles/NOTICE.md.meta.$packageName" -Destination "$packagePath/NOTICE.md.meta"
117-
Copy-Item -Path "$ProjectRoot/CHANGELOG.md" -Destination "$packagePath"
118-
Copy-Item -Path "$ProjectRoot/UPM/UnityMetaFiles/CHANGELOG.md.meta.$packageName" -Destination "$packagePath/CHANGELOG.md.meta"
119-
Copy-Item -Path "$ProjectRoot/UPM/Documentation~" -Destination "$docFolder" -Recurse
120-
Copy-Item -Path "$ProjectRoot/Authors.md" -Destination "$docFolder"
121-
122-
$samplesFolder = "$packagePath/Samples~"
123-
124-
if ($packageName -eq "foundation") {
125-
# The foundation package contains files that are required to be copied into the Assets folder to be used.
126-
# In order to perform the necessary preparation, without overly complicating this script, we will use a
127-
# helper script to prepare the folder.
128-
Start-Process -FilePath "$PSHOME/powershell.exe" -ArgumentList "$scriptPath/foundationpreupm.ps1 -PackageRoot $packagePath" -NoNewWindow -Wait
129-
}
130-
elseif ($packageName -eq "standardassets") {
131-
# The standard assets package contains shaders that need to be imported into the Assets folder so that they
132-
# can be modified if the render pipeline is changed. To avoid duplicate resources (in library and assets)
133-
# we rename the Shaders folder to Shaders~, which makes it hidden to the Unity Editor.
134-
Rename-Item -Path "$packagePath/Shaders" -NewName "$packagePath/Shaders~"
135-
Remove-Item -Path "$packagePath/Shaders.meta"
136-
}
137-
elseif ($packageName -eq "examples") {
138-
# The examples folder is a collection of sample projects. In order to perform the necessary
139-
# preparation, without overly complicating this script, we will use a helper script to prepare
140-
# the folder.
141-
Start-Process -FilePath "$PSHOME/powershell.exe" -ArgumentList "$scriptPath/examplesfolderpreupm.ps1 -PackageRoot $packagePath" -NoNewWindow -Wait
142-
}
143-
elseif ($packageName -eq "extensions") {
144-
# The extensions folder contains one or more folders that provide their own examples. In order
145-
# to perform the necessary preparation, without overly complicating this script, we will use a
146-
# helper script to prepare the folder.
147-
Start-Process -FilePath "$PSHOME/powershell.exe" -ArgumentList "$scriptPath/extensionsfolderpreupm.ps1 -PackageRoot $packagePath" -NoNewWindow -Wait
88+
if ($Repack) {
89+
$packageTarball = "$scope.$product.$packageName"
90+
$tarballPath = Get-ChildItem -Path $ProjectRoot -Filter $packageTarball* -Name | Select-Object -First 1
91+
tar -xzf (Join-Path $ProjectRoot $tarballPath)
92+
$packagePath = Resolve-Path -Path "package"
14893
}
14994
else {
150-
# Some other folders have localized examples that need to be prepared. Intentionally skip the foundation as those samples
151-
$exampleFolder = "$packagePath/Examples"
152-
if (($PackageName -ne "foundation") -and (Test-Path -Path $exampleFolder)) {
153-
# Ensure the required samples exists
154-
if (-not (Test-Path -Path $samplesFolder)) {
155-
New-Item $samplesFolder -ItemType Directory | Out-Null
156-
}
95+
$packagePath = Resolve-Path -Path "$ProjectRoot/$($entry.Value)"
96+
}
15797

158-
# Copy the examples
159-
Write-Output "Copying $exampleFolder to $samplesFolder"
160-
Copy-Item -Path $exampleFolder -Destination $samplesFolder -Recurse -Force
98+
if (-not $Repack) {
99+
# The package manifest files what we use are actually templates,
100+
# rename the files so that npm can consume them.
101+
Rename-Item -Path "$packagePath/packagetemplate.json" -NewName "$packagePath/package.json"
102+
Rename-Item -Path "$packagePath/packagetemplate.json.meta" -NewName "$packagePath/package.json.meta"
103+
104+
$docFolder = "$packagePath/Documentation~"
105+
106+
# Copy files used by UPM to display license, change log, etc.
107+
Copy-Item -Path "$ProjectRoot/LICENSE.md" -Destination "$packagePath"
108+
Copy-Item -Path "$ProjectRoot/UPM/UnityMetaFiles/LICENSE.md.meta.$packageName" -Destination "$packagePath/LICENSE.md.meta"
109+
Copy-Item -Path "$ProjectRoot/NOTICE.md" -Destination "$packagePath"
110+
Copy-Item -Path "$ProjectRoot/UPM/UnityMetaFiles/NOTICE.md.meta.$packageName" -Destination "$packagePath/NOTICE.md.meta"
111+
Copy-Item -Path "$ProjectRoot/CHANGELOG.md" -Destination "$packagePath"
112+
Copy-Item -Path "$ProjectRoot/UPM/UnityMetaFiles/CHANGELOG.md.meta.$packageName" -Destination "$packagePath/CHANGELOG.md.meta"
113+
Copy-Item -Path "$ProjectRoot/UPM/Documentation~" -Destination "$docFolder" -Recurse
114+
Copy-Item -Path "$ProjectRoot/Authors.md" -Destination "$docFolder"
115+
116+
$scriptPath = "$ProjectRoot/scripts/packaging"
117+
$samplesFolder = "$packagePath/Samples~"
118+
119+
if ($packageName -eq "foundation") {
120+
# The foundation package contains files that are required to be copied into the Assets folder to be used.
121+
# In order to perform the necessary preparation, without overly complicating this script, we will use a
122+
# helper script to prepare the folder.
123+
Start-Process -FilePath "$PSHOME/powershell.exe" -ArgumentList "$scriptPath/foundationpreupm.ps1 -PackageRoot $packagePath" -NoNewWindow -Wait
124+
}
125+
elseif ($packageName -eq "standardassets") {
126+
# The standard assets package contains shaders that need to be imported into the Assets folder so that they
127+
# can be modified if the render pipeline is changed. To avoid duplicate resources (in library and assets)
128+
# we rename the Shaders folder to Shaders~, which makes it hidden to the Unity Editor.
129+
Rename-Item -Path "$packagePath/Shaders" -NewName "$packagePath/Shaders~"
130+
Remove-Item -Path "$packagePath/Shaders.meta"
131+
}
132+
elseif ($packageName -eq "examples") {
133+
# The examples folder is a collection of sample projects. In order to perform the necessary
134+
# preparation, without overly complicating this script, we will use a helper script to prepare
135+
# the folder.
136+
Start-Process -FilePath "$PSHOME/powershell.exe" -ArgumentList "$scriptPath/examplesfolderpreupm.ps1 -PackageRoot $packagePath" -NoNewWindow -Wait
137+
}
138+
elseif ($packageName -eq "extensions") {
139+
# The extensions folder contains one or more folders that provide their own examples. In order
140+
# to perform the necessary preparation, without overly complicating this script, we will use a
141+
# helper script to prepare the folder.
142+
Start-Process -FilePath "$PSHOME/powershell.exe" -ArgumentList "$scriptPath/extensionsfolderpreupm.ps1 -PackageRoot $packagePath" -NoNewWindow -Wait
143+
}
144+
else {
145+
# Some other folders have localized examples that need to be prepared. Intentionally skip the foundation as those samples
146+
$exampleFolder = "$packagePath/Examples"
147+
if (($PackageName -ne "foundation") -and (Test-Path -Path $exampleFolder)) {
148+
# Ensure the required samples exists
149+
if (-not (Test-Path -Path $samplesFolder)) {
150+
New-Item $samplesFolder -ItemType Directory | Out-Null
151+
}
152+
153+
# Copy the examples
154+
Write-Output "Copying $exampleFolder to $samplesFolder"
155+
Copy-Item -Path $exampleFolder -Destination $samplesFolder -Recurse -Force
156+
}
161157
}
162158
}
163159

160+
# Apply the version number to the package json file
161+
$packageJsonPath = "$packagePath/package.json"
162+
((Get-Content -Path $packageJsonPath -Raw) -Replace '("version\": )"([0-9.]+-?[a-zA-Z0-9.]*|%version%)', "`$1`"$Version") | Set-Content -Path $packageJsonPath -NoNewline
163+
164164
Write-Output "======================="
165165
Write-Output "Creating $scope.$product.$packageName"
166166
Write-Output "======================="
167-
npm pack
167+
npm pack $packagePath
168168

169169
# Move package file to OutputFolder
170-
Move-Item -Path "./*.tgz" $OutputDirectory -Force
170+
Move-Item -Path "./$scope.$product.$packageName-$Version.tgz" $OutputDirectory -Force
171171

172172
# ======================
173173
# Cleanup the changes we have made
174174
# ======================
175175
Write-Output "Cleaning up temporary changes"
176176

177-
if (Test-Path -Path $samplesFolder) {
178-
# A samples folder was created. Remove it.
179-
Remove-Item -Path $samplesFolder -Recurse -Force
180-
}
181-
182-
if ($packageName -eq "foundation") {
183-
# The foundation package MOVES some content around. This restores the moved files.
184-
Start-Process -FilePath "git" -ArgumentList "checkout Services/SceneSystem/SceneSystemResources*" -NoNewWindow -Wait
185-
}
186-
elseif ($packageName -eq "standardassets") {
187-
# The standard assets package RENAMES and DELETES some content. This restores the original files.
188-
Rename-Item -Path "$packagePath/Shaders~" -NewName "$packagePath/Shaders"
189-
Start-Process -FilePath "git" -ArgumentList "checkout Shaders.meta" -NoNewWindow -Wait
177+
if ($Repack) {
178+
# Clean up the unpacked tarball folder
179+
if (Test-Path -Path $packagePath) {
180+
Remove-Item -Path $packagePath -Recurse -Force
181+
}
190182
}
183+
else {
184+
if (Test-Path -Path $samplesFolder) {
185+
# A samples folder was created. Remove it.
186+
Remove-Item -Path $samplesFolder -Recurse -Force
187+
}
188+
189+
if ($packageName -eq "foundation") {
190+
# The foundation package MOVES some content around. This restores the moved files.
191+
Start-Process -FilePath "git" -ArgumentList "checkout Services/SceneSystem/SceneSystemResources*" -NoNewWindow -Wait
192+
}
193+
elseif ($packageName -eq "standardassets") {
194+
# The standard assets package RENAMES and DELETES some content. This restores the original files.
195+
Rename-Item -Path "$packagePath/Shaders~" -NewName "$packagePath/Shaders"
196+
Start-Process -FilePath "git" -ArgumentList "checkout Shaders.meta" -NoNewWindow -Wait
197+
}
191198

192-
# Delete the files copied in previously
193-
Remove-Item -Path "$packagePath/LICENSE.md*"
194-
Remove-Item -Path "$packagePath/NOTICE.md*"
195-
Remove-Item -Path "$packagePath/CHANGELOG.md*"
196-
if (Test-Path -Path $docFolder) {
197-
# A documentation folder was created. Remove it.
198-
Remove-Item -Path $docFolder -Recurse -Force
199-
}
199+
# Delete the files copied in previously
200+
Remove-Item -Path "$packagePath/LICENSE.md*"
201+
Remove-Item -Path "$packagePath/NOTICE.md*"
202+
Remove-Item -Path "$packagePath/CHANGELOG.md*"
203+
if (Test-Path -Path $docFolder) {
204+
# A documentation folder was created. Remove it.
205+
Remove-Item -Path $docFolder -Recurse -Force
206+
}
200207

201-
# Delete the renamed package.json.* files
202-
Remove-Item -Path "$packagePath/package.json"
203-
Remove-Item -Path "$packagePath/package.json.meta"
208+
# Delete the renamed package.json.* files
209+
Remove-Item -Path "$packagePath/package.json"
210+
Remove-Item -Path "$packagePath/package.json.meta"
204211

205-
# Restore original files
206-
Start-Process -FilePath "git" -ArgumentList "checkout packagetemplate.*" -NoNewWindow -Wait
212+
# Restore original files
213+
Start-Process -FilePath "git" -ArgumentList "checkout packagetemplate.*" -NoNewWindow -Wait
214+
}
207215
}
208-
209-
# Return to the starting path
210-
Set-Location $startPath

0 commit comments

Comments
 (0)