Skip to content

Add new GitHub pipeline to pack test builds #997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/upm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: UPM Pack

on:
push:
branches:
- main
- 'feature/*'
pull_request:

jobs:
pack:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Pack dev UPM packages
if: github.event_name == 'pull_request'
run: |
${{ github.workspace }}/Pipelines/Scripts/pack-upm.ps1 -ProjectRoot: ${{ github.workspace }} -OutputDirectory: ${{ github.workspace }}/build/upm/output -PrereleaseTag: dev -Revision: ${{ github.run_number }} -BuildNumber: ${{ github.run_number }}
shell: pwsh

- name: Pack preview UPM packages
if: github.event_name == 'push'
run: |
${{ github.workspace }}/Pipelines/Scripts/pack-upm.ps1 -ProjectRoot: ${{ github.workspace }} -OutputDirectory: ${{ github.workspace }}/build/upm/output -PrereleaseTag: pre -Revision: ${{ github.run_number }} -BuildNumber: ${{ github.run_number }}
shell: pwsh

- uses: actions/upload-artifact@v4
if: github.event_name == 'pull_request'
with:
name: packages
path: ${{ github.workspace }}/build/upm/output
retention-days: 1

- uses: actions/upload-artifact@v4
if: github.event_name == 'push'
with:
name: packages
path: ${{ github.workspace }}/build/upm/output
retention-days: 15
27 changes: 13 additions & 14 deletions Pipelines/Scripts/pack-upm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
.PARAMETER PrereleaseTag
The tag to append after the version (e.g. "build", "internal" or "prerelease"). Leave blank for a release build.
.PARAMETER Revision
The revision number for the build, to append after the release labal and suffix.
The revision number for the build, to append after the release label and suffix.
.PARAMETER BuildNumber
The fourth digit for the full version number for assembly versioning. This is the build number.

#>
param(
[Parameter(Mandatory = $true)]
Expand All @@ -39,16 +38,16 @@ if (-not (Test-Path $OutputDirectory -PathType Container)) {
$OutputDirectory = Resolve-Path -Path $OutputDirectory

Write-Host ""
Write-Host -ForegroundColor Blue "======================================="
Write-Host -ForegroundColor Blue "======================================="
Write-Host -ForegroundColor Blue "Packing All Packages"
Write-Host -ForegroundColor Blue "======================================="
Write-Host -ForegroundColor Blue "======================================="
Write-Host "OutputDirectory: $OutputDirectory"

try {
Push-Location $OutputDirectory

# Update package versions
. $PSScriptRoot\update-versions.ps1 -PackagesRoot $ProjectRoot -PrereleaseTag $PrereleaseTag -Revision $Revision -BuildNumber $BuildNumber
. $PSScriptRoot\update-versions.ps1 -PackagesRoot $ProjectRoot -PrereleaseTag $PrereleaseTag -Revision $Revision -BuildNumber $BuildNumber

# Loop through package directories and copy documentation
Get-ChildItem -Path $ProjectRoot/*/package.json | ForEach-Object {
Expand All @@ -63,32 +62,32 @@ try {
$docFolder = "$packagePath/Documentation~"

Write-Host ""
Write-Host -ForegroundColor Green "======================================="
Write-Host -ForegroundColor Green "======================================="
Write-Host -ForegroundColor Green "Copying Documentation~"
Write-Host -ForegroundColor Green "======================================="
Write-Host -ForegroundColor Green "======================================="
Write-Host "Package name: $packageName"

if (Test-Path -Path $docFolder) {
Copy-Item -Path "$ProjectRoot/Pipelines/UPM/Documentation~/*" -Destination $docFolder -Recurse
}
else {
Copy-Item -Path "$ProjectRoot/Pipelines/UPM/Documentation~" -Destination $docFolder -Recurse
}
}
}

# Package the package directories
Get-ChildItem -Path $ProjectRoot/*/package.json | ForEach-Object {
$currentPackageName = Select-String -Pattern "org\.mixedrealitytoolkit\.\w+(\.\w+)*" -Path $_ | Select-Object -First 1

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

Write-Host ""
Write-Host -ForegroundColor Green "======================================="
Write-Host -ForegroundColor Green "======================================="
Write-Host -ForegroundColor Green "Packing Package"
Write-Host -ForegroundColor Green "======================================="
Write-Host "Package name: $currentPackageName"
Write-Host "Package name: $currentPackageName"

$currentPackageName = $currentPackageName.Matches[0].Value
$packageFriendlyName = (Select-String -Pattern "`"displayName`": `"(.+)`"" -Path $_ | Select-Object -First 1).Matches.Groups[1].Value
Expand All @@ -102,7 +101,7 @@ try {
# clean up
if (Test-Path -Path $docFolder) {
Write-Host "Cleaning up Documentation~ from $packageFriendlyName"
# A documentation folder was created. Remove it.
# A documentation folder was created. Remove it.
Remove-Item -Path $docFolder -Recurse -Force

# But restore anything that's checked-in.
Expand All @@ -118,8 +117,8 @@ try {
}

Write-Host ""
Write-Host -ForegroundColor Blue "======================================="
Write-Host -ForegroundColor Blue "Successfully Packed All Pacakges"
Write-Host -ForegroundColor Blue "======================================="
Write-Host -ForegroundColor Blue "Successfully Packed All Packages"
Write-Host -ForegroundColor Blue "======================================="
Write-Host ""
}
Expand Down
30 changes: 15 additions & 15 deletions Pipelines/Scripts/update-versions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
.SYNOPSIS
Updates the version of the UPM packages in the project with a release label, revision, and build number.
.DESCRIPTION
The script will update the version of the package.json file with the new version label and revision number. This
The script will update the version of the package.json file with the new version label and revision number. This
script will also update the AssemblyInfo.cs file with the new version number and build number. Finally, this
script will update the CHANGELOG.md file with the new version number and release date.
.PARAMETER PackagesRoot
The root folder containing the packages.
.PARAMETER PrereleaseTag
The tag to append after the version (e.g. "build", "internal" or "prerelease"). Leave blank for a release build.
.PARAMETER Revision
The revision number for the build, to append after the release labal.
The revision number for the build, to append after the release label.
.PARAMETER BuildNumber
The fourth digit for the full version number for assembly versioning. This is the build number.
#>
Expand Down Expand Up @@ -44,7 +44,7 @@ if (-not [string]::IsNullOrEmpty($Revision)) {
}

Write-Host ""
Write-Host -ForegroundColor Green "======================================="
Write-Host -ForegroundColor Green "======================================="
Write-Host -ForegroundColor Green "Updating All Package Versions"
Write-Host -ForegroundColor Green "======================================="
Write-Output "Project root: $PackagesRoot"
Expand All @@ -63,7 +63,7 @@ Get-ChildItem -Path $PackagesRoot -Filter "package.json" -Recurse | ForEach-Obje

# Test is package name starts with org.mixedrealitytoolkit to verify it's an MRTK package
if ($packageName -notmatch "^org\.mixedrealitytoolkit\.\w+(\.\w+)*") {
return
return
}

# Read the version value
Expand All @@ -73,24 +73,24 @@ Get-ChildItem -Path $PackagesRoot -Filter "package.json" -Recurse | ForEach-Obje
$packagePath = $_.Directory

Write-Host ""
Write-Host -ForegroundColor Green "======================================="
Write-Host -ForegroundColor Green "======================================="
Write-Host -ForegroundColor Green "Updating Package Version"
Write-Host -ForegroundColor Green "======================================="
Write-Host -ForegroundColor Green "======================================="
Write-Output "Package name: $packageName"

# This regex will match the a valid version is the package.json file. Some examples of valid versions are:
#
# 1.0.0
# 1.0.0-pre.1
# 1.0.0-development.pre.1
# 1.0.0-development
# 1.0.0-development
#
# In these example "development" is the prerelease tag and "pre.1" is the meta tag.
# In these example "development" is the prerelease tag and "pre.1" is the meta tag.
$validVersion = $version -match '(?<version>[0-9.]+)(-((?<prereleaseTag>[a-zA-Z0-9]*)?(?=(|\.[a-zA-Z]*\.[0-9]*)(\.[0-9]{6}\.[0-9]|$))|)((?(?<=-)|\.)(?<metaTag>[a-zA-Z][a-zA-Z0-9]*)\.(?<metaTagVersion>[1-9][0-9]*))?)?'
if (-not $validVersion) {
throw "Failed to parse version out of the package.json file at $($_.FullName)"
}

# Get the version parts from the $Matches variable, and verify that the version key exists.
$versionParts = $Matches
if (-not $versionParts.ContainsKey('version')) {
Expand All @@ -102,14 +102,14 @@ Get-ChildItem -Path $PackagesRoot -Filter "package.json" -Recurse | ForEach-Obje

# Get all tag parts to append to the version
$tagParts = @()

# Add the new version label if it's not empty
if (-not [string]::IsNullOrEmpty($PrereleaseTag)) {
$tagParts += $PrereleaseTag
}

# Add the optional metatag tag and version if found in match
if ($versionParts.ContainsKey('metaTag') -and $versionParts.ContainsKey('metaTagVersion')) {
if ($versionParts.ContainsKey('metaTag') -and $versionParts.ContainsKey('metaTagVersion')) {
$tagParts += $versionParts['metaTag']
$tagParts += $versionParts['metaTagVersion']
}
Expand All @@ -125,7 +125,7 @@ Get-ChildItem -Path $PackagesRoot -Filter "package.json" -Recurse | ForEach-Obje
$tag = "-" + $tag
}

# Update the version with the new tag
# Update the version with the new tag
$jsonContent.version = "$version$tag"

# Write json content back to the file
Expand Down Expand Up @@ -153,18 +153,18 @@ Get-ChildItem -Path $PackagesRoot -Filter "package.json" -Recurse | ForEach-Obje
$assemblyInfo += "[assembly: AssemblyInformationalVersion(`"$version$tag`")]`r`n"
}

Set-Content -Path $_ -Value $assemblyInfo -NoNewline
Set-Content -Path $_ -Value $assemblyInfo -NoNewline
}

# Update the CHANGELOG.md file with the new version and release date
Write-Output "Patching CHANGELOG.md version to [$version$tag] - $year-$month-$day"
Get-ChildItem -Path $packagePath/CHANGELOG.md -Recurse | ForEach-Object {
Get-ChildItem -Path $packagePath/CHANGELOG.md -Recurse | ForEach-Object {
(Get-Content -Path $_ -Raw) -Replace "## \[$version(-[a-zA-Z0-9.]+)?\] - \b\d{4}\b-\b(0[1-9]|1[0-2])\b-\b(0[1-9]|[12][0-9]|3[01])\b", "## [$version$tag] - $year-$month-$day" | Set-Content -Path $_ -NoNewline
}
}

Write-Host ""
Write-Host -ForegroundColor Green "======================================="
Write-Host -ForegroundColor Green "======================================="
Write-Host -ForegroundColor Green "Successfully Updated Package Versions"
Write-Host -ForegroundColor Green "======================================="
Write-Host ""