Skip to content

Commit c50ce60

Browse files
authored
Docs onboarding v2 (Azure#37997)
* 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
1 parent 482a2b6 commit c50ce60

File tree

2 files changed

+189
-0
lines changed

2 files changed

+189
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
. "$PSScriptRoot/../../common/scripts/common.ps1"
2+
3+
Set-StrictMode -Version 3
4+
5+
function GetPropertyString($docsCiConfigProperties) {
6+
$propertyArray = @()
7+
foreach ($key in $docsCiConfigProperties.Keys) {
8+
$propertyArray += "$key=$($docsCiConfigProperties[$key])"
9+
}
10+
return $propertyArray -join ';'
11+
}
12+
13+
function Get-DocsCiLine2($item) {
14+
$line = ''
15+
if ($item.ContainsKey('DocsCiConfigProperties') -and $item['DocsCiConfigProperties'].Count -gt 0) {
16+
$line = "$($item['Id']),[$(GetPropertyString $item['DocsCiConfigProperties'])]$($item['Name'])"
17+
} else {
18+
$line = "$($item['Id']),$($item['Name'])"
19+
}
20+
21+
if ($item.ContainsKey('Version') -and $item['Version']) {
22+
$line += ",$($item['Version'])"
23+
}
24+
25+
return $line
26+
}
27+
28+
function SetDocsCiConfigProperties($item, $moniker, $packageSourceOverride) {
29+
# Order properties so that output is deterministic (more simple diffs)
30+
$properties = [ordered]@{}
31+
if ($item.ContainsKey('DocsCiConfigProperties')) {
32+
$properties = $item['DocsCiConfigProperties']
33+
}
34+
35+
# Set tfm to netstandard2.0 if not already set
36+
if ('tfm' -notin $properties.Keys) {
37+
$properties['tfm'] = 'netstandard2.0'
38+
}
39+
40+
# When in the preview moniker, always set isPrerelease to true
41+
if ($moniker -eq 'preview') {
42+
$properties['isPrerelease'] = 'true'
43+
}
44+
45+
# Handle dev version overrides for daily docs
46+
if ($item['DevVersion'] -and $packageSourceOverride) {
47+
$properties['isPrerelease'] = 'true'
48+
$properties['customSource'] = $packageSourceOverride
49+
}
50+
51+
$item['DocsCiConfigProperties'] = $properties
52+
53+
return $item
54+
}
55+
56+
function GetCiConfigPath($docRepoLocation, $moniker) {
57+
$csvPath = Join-Path $docRepoLocation "bundlepackages/azure-dotnet.csv"
58+
if ($moniker -eq 'preview') {
59+
$csvPath = Join-Path $docRepoLocation "bundlepackages/azure-dotnet-preview.csv"
60+
} elseif ($moniker -eq 'legacy') {
61+
$csvPath = Join-Path $docRepoLocation "bundlepackages/azure-dotnet-legacy.csv"
62+
}
63+
return $csvPath
64+
}
65+
66+
function GetPackageId($packageName) {
67+
return $packageName.Replace('.', '').ToLower()
68+
}
69+
70+
# $SetDocsPackageOnboarding = "Set-${Language}-DocsPackageOnboarding"
71+
function Set-dotnet-DocsPackageOnboarding($moniker, $metadata, $docRepoLocation, $packageSourceOverride) {
72+
$lines = @()
73+
foreach ($package in $metadata) {
74+
$package.Id = GetPackageId $package.Name
75+
$package = SetDocsCiConfigProperties $package $moniker $packageSourceOverride
76+
77+
$line = Get-DocsCiLine2 $package
78+
$lines += $line
79+
}
80+
81+
Set-Content -Path (GetCiConfigPath $docRepoLocation $moniker) -Value $lines
82+
}
83+
84+
# $GetDocsPackagesAlreadyOnboarded = "Get-${Language}-DocsPackagesAlreadyOnboarded"
85+
function Get-dotnet-DocsPackagesAlreadyOnboarded($docRepoLocation, $moniker) {
86+
$onboardedPackages = Get-DocsCiConfig (GetCiConfigPath $docRepoLocation $moniker)
87+
88+
$onboardedPackageHash = @{}
89+
foreach ($package in $onboardedPackages) {
90+
$packageProperties = @{
91+
Name = $package.Name
92+
}
93+
94+
if ($package.Versions -is [array]) {
95+
if ($package.Versions.Count -gt 1) {
96+
throw "Too many versions supplied for package: $(package.Name) in moniker: $moniker"
97+
}
98+
99+
if ($package.Versions.Count -eq 1) {
100+
$packageProperties['Version'] = $package.Versions[0]
101+
} else {
102+
# Versions is an empty array, set to an empty string
103+
$packageProperties['Version'] = ''
104+
}
105+
}
106+
107+
$onboardedPackageHash[$package.Name] = $packageProperties
108+
}
109+
return $onboardedPackageHash
110+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
Import-Module Pester
2+
3+
BeforeAll {
4+
. $PSScriptRoot/../Docs-Onboarding.ps1
5+
}
6+
7+
Describe 'GetPropertyString' {
8+
It 'returns <expected> when given (<inputValue>)' -ForEach @(
9+
@{ inputValue = @{}; expected = '' },
10+
@{ inputValue = @{ test = 'value' }; expected = 'test=value' },
11+
@{ inputValue = [ordered]@{ test = 'value'; test2 = 'value2' }; expected = 'test=value;test2=value2' }
12+
) {
13+
$result = GetPropertyString $inputValue
14+
$result | Should -Be $expected
15+
}
16+
}
17+
18+
Describe 'Get-DocsCiLine2' {
19+
It 'returns <expected> when given <inputValue>' -ForEach @(
20+
@{ inputValue = @{ Id = 'id'; Name = 'name' }; expected = 'id,name' },
21+
@{ inputValue = @{ Id = 'id'; Name = 'name'; Version = 'version' }; expected = 'id,name,version' },
22+
@{ inputValue = @{ Id = 'id'; Name = 'name'; DocsCiConfigProperties = @{ test = 'value' } }; expected = 'id,[test=value]name' },
23+
@{ inputValue = @{ Id = 'id'; Name = 'name'; DocsCiConfigProperties = @{ test = 'value' }; Version = 'version' }; expected = 'id,[test=value]name,version' }
24+
) {
25+
$result = Get-DocsCiLine2 $inputValue
26+
$result | Should -Be $expected
27+
}
28+
}
29+
30+
Describe 'SetDocsCiConfigProperties' {
31+
It 'sets isPrerelease=true when moniker is preview' {
32+
$package = @{ Id = 'id'; Name = 'name'; Version = 'version' }
33+
$result = SetDocsCiConfigProperties $package 'preview'
34+
35+
$result.DocsCiConfigProperties['isPrerelease'] | Should -Be 'true'
36+
}
37+
38+
It 'sets custom source when there is DevVersion and packageSourceOverride' {
39+
$package = @{ Id = 'id'; Name = 'name'; Version = 'version'; DevVersion = 'DevVersionIsSet' }
40+
$result = SetDocsCiConfigProperties $package 'preview' 'https://packageSourceOverride/'
41+
42+
$result.DocsCiConfigProperties['isPrerelease'] | Should -Be 'true'
43+
$result.DocsCiConfigProperties['customSource'] | Should -Be 'https://packageSourceOverride/'
44+
}
45+
46+
It 'combines existing properties with with isPrerelease when moniker is preview' {
47+
$package = @{ Id = 'id'; Name = 'name'; Version = 'version'; DocsCiConfigProperties = @{ test = 'value' } }
48+
$result = SetDocsCiConfigProperties $package 'preview'
49+
50+
$result.DocsCiConfigProperties['isPrerelease'] | Should -Be 'true'
51+
$result.DocsCiConfigProperties['test'] | Should -Be 'value'
52+
}
53+
}
54+
55+
Describe 'GetCiConfigPath' {
56+
It 'returns <expected> when given <inputValue>' -ForEach @(
57+
@{ inputValue = 'preview'; expected = './bundlepackages/azure-dotnet-preview.csv' },
58+
@{ inputValue = 'legacy'; expected = './bundlepackages/azure-dotnet-legacy.csv' },
59+
@{ inputValue = 'default'; expected = './bundlepackages/azure-dotnet.csv' }
60+
) {
61+
$result = GetCiConfigPath '.' $inputValue
62+
$result | Should -Be $expected
63+
}
64+
65+
It 'returns latest by default' {
66+
$result = GetCiConfigPath '.' 'some random value'
67+
$result | Should -Be './bundlepackages/azure-dotnet.csv'
68+
}
69+
}
70+
71+
Describe 'GetPackageId' {
72+
It 'returns <expected> when given <inputValue>' -ForEach @(
73+
@{ inputValue = 'Name.With.Dot.Separators'; expected = 'namewithdotseparators' },
74+
@{ inputValue = 'Name.With.Dots-and-dashes'; expected = 'namewithdots-and-dashes' }
75+
) {
76+
$result = GetPackageId $inputValue
77+
$result | Should -Be $expected
78+
}
79+
}

0 commit comments

Comments
 (0)