From 1c2e8c4573c4b833e8a47283339266e6c47b1252 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu <31145988+chidozieononiwu@users.noreply.github.com> Date: Wed, 18 Nov 2020 14:49:54 -0800 Subject: [PATCH] Updates to Language Settings file (#12589) * Add Update-javascript-CIConfig * Add Update-javascript-CIConfig * Switch from using BuildNumber to BuildID for test versions --- .../templates/stages/archetype-js-release.yml | 2 +- eng/pipelines/templates/steps/build.yml | 2 +- eng/scripts/Language-Settings.ps1 | 57 ++++++++++++++++++- eng/scripts/SetTestPipelineVersion.ps1 | 4 +- 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/eng/pipelines/templates/stages/archetype-js-release.yml b/eng/pipelines/templates/stages/archetype-js-release.yml index 9e6ea2a91e24..bd83a6ab7c60 100644 --- a/eng/pipelines/templates/stages/archetype-js-release.yml +++ b/eng/pipelines/templates/stages/archetype-js-release.yml @@ -38,7 +38,7 @@ stages: pwsh: true workingDirectory: $(Build.SourcesDirectory) filePath: eng/scripts/SetTestPipelineVersion.ps1 - arguments: '-BuildNumber $(Build.BuildNumber)' + arguments: '-BuildID $(Build.BuildId)' - template: /eng/common/pipelines/templates/steps/verify-changelog.yml parameters: PackageName: ${{artifact.name}} diff --git a/eng/pipelines/templates/steps/build.yml b/eng/pipelines/templates/steps/build.yml index 0b5b8ee6f2ad..177531b2c516 100644 --- a/eng/pipelines/templates/steps/build.yml +++ b/eng/pipelines/templates/steps/build.yml @@ -12,7 +12,7 @@ steps: pwsh: true workingDirectory: $(Build.SourcesDirectory) filePath: eng/scripts/SetTestPipelineVersion.ps1 - arguments: '-BuildNumber $(Build.BuildNumber)' + arguments: '-BuildID $(Build.BuildId)' - pwsh: | $folder = "${{parameters.ServiceDirectory}}" diff --git a/eng/scripts/Language-Settings.ps1 b/eng/scripts/Language-Settings.ps1 index 6f1c4be076cc..370955640918 100644 --- a/eng/scripts/Language-Settings.ps1 +++ b/eng/scripts/Language-Settings.ps1 @@ -119,7 +119,8 @@ function Publish-javascript-GithubIODocs ($DocLocation, $PublicArtifactLocation) $parsedPackage = Get-javascript-PackageInfoFromPackageFile $pkgs[0] $PublicArtifactLocation $PkgName = $parsedPackage.PackageId.Replace("@", "").Replace("/", "-") } - else{ + else + { Write-Host "Package info is not available from artifact. Assuming package is in default scope @azure." } Write-Host "Uploading Doc for $($PkgName) Version:- $($DocVersion)..." @@ -144,3 +145,57 @@ function Get-javascript-GithubIoDocIndex() # Generate yml/md toc files and build site. GenerateDocfxTocContent -tocContent $tocContent -lang "JavaScript" } + +# Updates a js CI configuration json. +# For "latest", we simply set a target package name +# For "preview", we add @next to the target package name +function Update-javascript-CIConfig($pkgs, $ciRepo, $locationInDocRepo, $monikerId = $null) +{ + $pkgJsonLoc = (Join-Path -Path $ciRepo -ChildPath $locationInDocRepo) + + if (-not (Test-Path $pkgJsonLoc)) + { + Write-Error "Unable to locate package json at location $pkgJsonLoc, exiting." + exit(1) + } + + $allJson = Get-Content $pkgJsonLoc | ConvertFrom-Json + + $visibleInCI = @{} + + for ($i = 0; $i -lt $allJson.npm_package_sources.Length; $i++) + { + $pkgDef = $allJson.npm_package_sources[$i] + $accessor = ($pkgDef.name).Replace("`@next", "") + $visibleInCI[$accessor] = $i + } + + foreach ($releasingPkg in $pkgs) + { + $name = $releasingPkg.PackageId + + if ($releasingPkg.IsPrerelease) + { + $name += "`@next" + } + + if ($visibleInCI.ContainsKey($releasingPkg.PackageId)) + { + $packagesIndex = $visibleInCI[$releasingPkg.PackageId] + $existingPackageDef = $allJson.npm_package_sources[$packagesIndex] + $existingPackageDef.name = $name + } + else + { + $newItem = New-Object PSObject -Property @{ + name = $name + } + + if ($newItem) { $allJson.npm_package_sources += $newItem } + } + } + + $jsonContent = $allJson | ConvertTo-Json -Depth 10 | ForEach-Object { $_ -replace "(?m) (?<=^(?: )*)", " " } + + Set-Content -Path $pkgJsonLoc -Value $jsonContent +} diff --git a/eng/scripts/SetTestPipelineVersion.ps1 b/eng/scripts/SetTestPipelineVersion.ps1 index 70d7445bbf25..9a36861780be 100644 --- a/eng/scripts/SetTestPipelineVersion.ps1 +++ b/eng/scripts/SetTestPipelineVersion.ps1 @@ -3,7 +3,7 @@ param ( [Parameter(mandatory = $true)] - $BuildNumber + $BuildID ) . "${PSScriptRoot}\..\common\scripts\common.ps1" @@ -24,7 +24,7 @@ LogDebug "Last Published Version $($semVarsSorted[0])" $newVersion = [AzureEngSemanticVersion]::ParseVersionString($semVarsSorted[0]) $newVersion.PrereleaseLabel = "beta" -$newVersion.PrereleaseNumber = $BuildNumber +$newVersion.PrereleaseNumber = $BuildID $packageFileContent = Get-Content -Path $templatePackageFile | ConvertFrom-Json LogDebug "Version in Source $($packageFileContent.version)"