diff --git a/.github/workflows/upm.yaml b/.github/workflows/upm.yaml new file mode 100644 index 000000000..d6d94b3b9 --- /dev/null +++ b/.github/workflows/upm.yaml @@ -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 diff --git a/Pipelines/Scripts/pack-upm.ps1 b/Pipelines/Scripts/pack-upm.ps1 index 890d68e0d..51c2b581f 100644 --- a/Pipelines/Scripts/pack-upm.ps1 +++ b/Pipelines/Scripts/pack-upm.ps1 @@ -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)] @@ -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 { @@ -63,9 +62,9 @@ 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) { @@ -73,22 +72,22 @@ try { } 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 @@ -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. @@ -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 "" } diff --git a/Pipelines/Scripts/update-versions.ps1 b/Pipelines/Scripts/update-versions.ps1 index 904ecf16e..8982b3c3a 100644 --- a/Pipelines/Scripts/update-versions.ps1 +++ b/Pipelines/Scripts/update-versions.ps1 @@ -5,7 +5,7 @@ .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 @@ -13,7 +13,7 @@ .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. #> @@ -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" @@ -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 @@ -73,9 +73,9 @@ 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: @@ -83,14 +83,14 @@ Get-ChildItem -Path $PackagesRoot -Filter "package.json" -Recurse | ForEach-Obje # 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 '(?[0-9.]+)(-((?[a-zA-Z0-9]*)?(?=(|\.[a-zA-Z]*\.[0-9]*)(\.[0-9]{6}\.[0-9]|$))|)((?(?<=-)|\.)(?[a-zA-Z][a-zA-Z0-9]*)\.(?[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')) { @@ -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'] } @@ -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 @@ -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 "" \ No newline at end of file