forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Some progress * Add logic for docs onboarding * Output stacktrace * Formatting, tiny refactor * Add "DocsCiConfigConfigProperties" to metadata JSON * More up to date eng/common * Update eng/common * Revert Update-DocsMsMetadata.ps1 * Add tfm=netstandard2.0 handler to a different location * docindex for testing * Keys instead of ContainsKey * -notin * Branch naming * Revert eng/common demonstration * Use new script in docindex.yml * Remove TODO, tests pass on Windows * Use Update-DocsMsPackages.ps1
- Loading branch information
1 parent
482a2b6
commit c50ce60
Showing
2 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
. "$PSScriptRoot/../../common/scripts/common.ps1" | ||
|
||
Set-StrictMode -Version 3 | ||
|
||
function GetPropertyString($docsCiConfigProperties) { | ||
$propertyArray = @() | ||
foreach ($key in $docsCiConfigProperties.Keys) { | ||
$propertyArray += "$key=$($docsCiConfigProperties[$key])" | ||
} | ||
return $propertyArray -join ';' | ||
} | ||
|
||
function Get-DocsCiLine2($item) { | ||
$line = '' | ||
if ($item.ContainsKey('DocsCiConfigProperties') -and $item['DocsCiConfigProperties'].Count -gt 0) { | ||
$line = "$($item['Id']),[$(GetPropertyString $item['DocsCiConfigProperties'])]$($item['Name'])" | ||
} else { | ||
$line = "$($item['Id']),$($item['Name'])" | ||
} | ||
|
||
if ($item.ContainsKey('Version') -and $item['Version']) { | ||
$line += ",$($item['Version'])" | ||
} | ||
|
||
return $line | ||
} | ||
|
||
function SetDocsCiConfigProperties($item, $moniker, $packageSourceOverride) { | ||
# Order properties so that output is deterministic (more simple diffs) | ||
$properties = [ordered]@{} | ||
if ($item.ContainsKey('DocsCiConfigProperties')) { | ||
$properties = $item['DocsCiConfigProperties'] | ||
} | ||
|
||
# Set tfm to netstandard2.0 if not already set | ||
if ('tfm' -notin $properties.Keys) { | ||
$properties['tfm'] = 'netstandard2.0' | ||
} | ||
|
||
# When in the preview moniker, always set isPrerelease to true | ||
if ($moniker -eq 'preview') { | ||
$properties['isPrerelease'] = 'true' | ||
} | ||
|
||
# Handle dev version overrides for daily docs | ||
if ($item['DevVersion'] -and $packageSourceOverride) { | ||
$properties['isPrerelease'] = 'true' | ||
$properties['customSource'] = $packageSourceOverride | ||
} | ||
|
||
$item['DocsCiConfigProperties'] = $properties | ||
|
||
return $item | ||
} | ||
|
||
function GetCiConfigPath($docRepoLocation, $moniker) { | ||
$csvPath = Join-Path $docRepoLocation "bundlepackages/azure-dotnet.csv" | ||
if ($moniker -eq 'preview') { | ||
$csvPath = Join-Path $docRepoLocation "bundlepackages/azure-dotnet-preview.csv" | ||
} elseif ($moniker -eq 'legacy') { | ||
$csvPath = Join-Path $docRepoLocation "bundlepackages/azure-dotnet-legacy.csv" | ||
} | ||
return $csvPath | ||
} | ||
|
||
function GetPackageId($packageName) { | ||
return $packageName.Replace('.', '').ToLower() | ||
} | ||
|
||
# $SetDocsPackageOnboarding = "Set-${Language}-DocsPackageOnboarding" | ||
function Set-dotnet-DocsPackageOnboarding($moniker, $metadata, $docRepoLocation, $packageSourceOverride) { | ||
$lines = @() | ||
foreach ($package in $metadata) { | ||
$package.Id = GetPackageId $package.Name | ||
$package = SetDocsCiConfigProperties $package $moniker $packageSourceOverride | ||
|
||
$line = Get-DocsCiLine2 $package | ||
$lines += $line | ||
} | ||
|
||
Set-Content -Path (GetCiConfigPath $docRepoLocation $moniker) -Value $lines | ||
} | ||
|
||
# $GetDocsPackagesAlreadyOnboarded = "Get-${Language}-DocsPackagesAlreadyOnboarded" | ||
function Get-dotnet-DocsPackagesAlreadyOnboarded($docRepoLocation, $moniker) { | ||
$onboardedPackages = Get-DocsCiConfig (GetCiConfigPath $docRepoLocation $moniker) | ||
|
||
$onboardedPackageHash = @{} | ||
foreach ($package in $onboardedPackages) { | ||
$packageProperties = @{ | ||
Name = $package.Name | ||
} | ||
|
||
if ($package.Versions -is [array]) { | ||
if ($package.Versions.Count -gt 1) { | ||
throw "Too many versions supplied for package: $(package.Name) in moniker: $moniker" | ||
} | ||
|
||
if ($package.Versions.Count -eq 1) { | ||
$packageProperties['Version'] = $package.Versions[0] | ||
} else { | ||
# Versions is an empty array, set to an empty string | ||
$packageProperties['Version'] = '' | ||
} | ||
} | ||
|
||
$onboardedPackageHash[$package.Name] = $packageProperties | ||
} | ||
return $onboardedPackageHash | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
Import-Module Pester | ||
|
||
BeforeAll { | ||
. $PSScriptRoot/../Docs-Onboarding.ps1 | ||
} | ||
|
||
Describe 'GetPropertyString' { | ||
It 'returns <expected> when given (<inputValue>)' -ForEach @( | ||
@{ inputValue = @{}; expected = '' }, | ||
@{ inputValue = @{ test = 'value' }; expected = 'test=value' }, | ||
@{ inputValue = [ordered]@{ test = 'value'; test2 = 'value2' }; expected = 'test=value;test2=value2' } | ||
) { | ||
$result = GetPropertyString $inputValue | ||
$result | Should -Be $expected | ||
} | ||
} | ||
|
||
Describe 'Get-DocsCiLine2' { | ||
It 'returns <expected> when given <inputValue>' -ForEach @( | ||
@{ inputValue = @{ Id = 'id'; Name = 'name' }; expected = 'id,name' }, | ||
@{ inputValue = @{ Id = 'id'; Name = 'name'; Version = 'version' }; expected = 'id,name,version' }, | ||
@{ inputValue = @{ Id = 'id'; Name = 'name'; DocsCiConfigProperties = @{ test = 'value' } }; expected = 'id,[test=value]name' }, | ||
@{ inputValue = @{ Id = 'id'; Name = 'name'; DocsCiConfigProperties = @{ test = 'value' }; Version = 'version' }; expected = 'id,[test=value]name,version' } | ||
) { | ||
$result = Get-DocsCiLine2 $inputValue | ||
$result | Should -Be $expected | ||
} | ||
} | ||
|
||
Describe 'SetDocsCiConfigProperties' { | ||
It 'sets isPrerelease=true when moniker is preview' { | ||
$package = @{ Id = 'id'; Name = 'name'; Version = 'version' } | ||
$result = SetDocsCiConfigProperties $package 'preview' | ||
|
||
$result.DocsCiConfigProperties['isPrerelease'] | Should -Be 'true' | ||
} | ||
|
||
It 'sets custom source when there is DevVersion and packageSourceOverride' { | ||
$package = @{ Id = 'id'; Name = 'name'; Version = 'version'; DevVersion = 'DevVersionIsSet' } | ||
$result = SetDocsCiConfigProperties $package 'preview' 'https://packageSourceOverride/' | ||
|
||
$result.DocsCiConfigProperties['isPrerelease'] | Should -Be 'true' | ||
$result.DocsCiConfigProperties['customSource'] | Should -Be 'https://packageSourceOverride/' | ||
} | ||
|
||
It 'combines existing properties with with isPrerelease when moniker is preview' { | ||
$package = @{ Id = 'id'; Name = 'name'; Version = 'version'; DocsCiConfigProperties = @{ test = 'value' } } | ||
$result = SetDocsCiConfigProperties $package 'preview' | ||
|
||
$result.DocsCiConfigProperties['isPrerelease'] | Should -Be 'true' | ||
$result.DocsCiConfigProperties['test'] | Should -Be 'value' | ||
} | ||
} | ||
|
||
Describe 'GetCiConfigPath' { | ||
It 'returns <expected> when given <inputValue>' -ForEach @( | ||
@{ inputValue = 'preview'; expected = './bundlepackages/azure-dotnet-preview.csv' }, | ||
@{ inputValue = 'legacy'; expected = './bundlepackages/azure-dotnet-legacy.csv' }, | ||
@{ inputValue = 'default'; expected = './bundlepackages/azure-dotnet.csv' } | ||
) { | ||
$result = GetCiConfigPath '.' $inputValue | ||
$result | Should -Be $expected | ||
} | ||
|
||
It 'returns latest by default' { | ||
$result = GetCiConfigPath '.' 'some random value' | ||
$result | Should -Be './bundlepackages/azure-dotnet.csv' | ||
} | ||
} | ||
|
||
Describe 'GetPackageId' { | ||
It 'returns <expected> when given <inputValue>' -ForEach @( | ||
@{ inputValue = 'Name.With.Dot.Separators'; expected = 'namewithdotseparators' }, | ||
@{ inputValue = 'Name.With.Dots-and-dashes'; expected = 'namewithdots-and-dashes' } | ||
) { | ||
$result = GetPackageId $inputValue | ||
$result | Should -Be $expected | ||
} | ||
} |