-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathService-Level-Readme-Automation.ps1
157 lines (134 loc) · 5.24 KB
/
Service-Level-Readme-Automation.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<#
.SYNOPSIS
The script is to generate service level readme if it is missing.
For exist ones, we do 2 things here:
1. Generate the client but not import to the existing service level readme.
2. Update the metadata of service level readme
.DESCRIPTION
Given a doc repo location, and the credential for fetching the ms.author.
Generate missing service level readme and updating metadata of the existing ones.
.PARAMETER DocRepoLocation
Location of the documentation repo. This repo may be sparsely checked out
depending on the requirements for the domain
.PARAMETER TenantId
The aad tenant id/object id for ms.author.
.PARAMETER ClientId
The add client id/application id for ms.author.
.PARAMETER ClientSecret
The client secret of add app for ms.author.
.PARAMETER ReadmeFolderRoot
The readme folder root path, use default value here for backward compability. E.g. docs-ref-services in Java, JS, Python, api/overview/azure
#>
param(
[Parameter(Mandatory = $true)]
[string] $DocRepoLocation,
[Parameter(Mandatory = $false)]
[string]$TenantId,
[Parameter(Mandatory = $false)]
[string]$ClientId,
[Parameter(Mandatory = $false)]
[string]$ClientSecret,
[Parameter(Mandatory = $false)]
[string]$ReadmeFolderRoot = "docs-ref-services",
[Parameter(Mandatory = $false)]
[array]$Monikers = @('latest', 'preview', 'legacy')
)
. $PSScriptRoot/common.ps1
. $PSScriptRoot/Helpers/Service-Level-Readme-Automation-Helpers.ps1
. $PSScriptRoot/Helpers/Metadata-Helpers.ps1
. $PSScriptRoot/Helpers/Package-Helpers.ps1
Set-StrictMode -Version 3
$fullMetadata = Get-CSVMetadata
foreach($moniker in $Monikers) {
# The onboarded packages return is key-value pair, which key is the package index, and value is the package info from {metadata}.json
# E.g.
# Key as: @azure/storage-blob
# Value as:
# {
# "Name": "@azure/storage-blob",
# "Version": "12.10.0-beta.1",
# "DevVersion": null,
# "DirectoryPath": "sdk/storage/storage-blob",
# "ServiceDirectory": "storage",
# "ReadMePath": "sdk/storage/storage-blob/README.md",
# "ChangeLogPath": "sdk/storage/storage-blob/CHANGELOG.md",
# "Group": null,
# "SdkType": "client",
# "IsNewSdk": true,
# "ArtifactName": "azure-storage-blob",
# "ReleaseStatus": "2022-04-19"
# }
$onboardedPackages = &$GetOnboardedDocsMsPackagesForMonikerFn `
-DocRepoLocation $DocRepoLocation -moniker $moniker
$csvMetadata = @()
foreach($metadataEntry in $fullMetadata) {
if ($metadataEntry.Package -and $metadataEntry.Hide -ne 'true') {
$pkgKey = GetPackageKey $metadataEntry
if (!$onboardedPackages.ContainsKey($pkgKey)) {
continue
}
$package = $onboardedPackages[$pkgKey]
if (!$package) {
$csvMetadata += $metadataEntry
continue
}
# If the metadata JSON entry has a DirectoryPath, but the CSV entry
# does not, add the DirectoryPath to the CSV entry
if (($package.PSObject.Members.Name -contains 'DirectoryPath') `
-and !($metadataEntry.PSObject.Members.Name -contains "DirectoryPath") ) {
Add-Member -InputObject $metadataEntry `
-MemberType NoteProperty `
-Name DirectoryPath `
-Value $package.DirectoryPath
}
$csvMetadata += $metadataEntry
}
}
$packagesForService = @{}
$allPackages = GetPackageLookup $csvMetadata
foreach ($metadataKey in $allPackages.Keys) {
$metadataEntry = $allPackages[$metadataKey]
if (!$metadataEntry.ServiceName) {
LogWarning "Empty ServiceName for package `"$metadataKey`". Skipping."
continue
}
$packagesForService[$metadataKey] = $metadataEntry
}
$services = @{}
foreach ($package in $packagesForService.Values) {
if ($package.ServiceName -eq 'Other') {
# Skip packages under the service category "Other". Those will be handled
# later
continue
}
if (!$services.ContainsKey($package.ServiceName)) {
$services[$package.ServiceName] = $true
}
}
foreach ($service in $services.Keys) {
Write-Host "Building service: $service"
$servicePackages = $packagesForService.Values.Where({ $_.ServiceName -eq $service })
$serviceReadmeBaseName = ServiceLevelReadmeNameStyle -serviceName $service
# Github url for source code: e.g. https://github.com/Azure/azure-sdk-for-js
$serviceBaseName = ServiceLevelReadmeNameStyle $service
$author = GetPrimaryCodeOwner -TargetDirectory "/sdk/$serviceBaseName/"
$msauthor = ""
if (!$author) {
LogError "Cannot fetch the author from CODEOWNER file."
$author = ""
}
elseif ($TenantId -and $ClientId -and $ClientSecret) {
$msauthor = GetMsAliasFromGithub -TenantId $tenantId -ClientId $clientId -ClientSecret $clientSecret -GithubUser $author
}
# Default value
if (!$msauthor) {
LogError "No ms.author found for $author. "
$msauthor = $author
}
# Add ability to override
# Fetch the service readme name
$msService = GetDocsMsService -packageInfo $servicePackages[0] -serviceName $service
generate-service-level-readme -docRepoLocation $DocRepoLocation -readmeBaseName $serviceReadmeBaseName -pathPrefix $ReadmeFolderRoot `
-packageInfos $servicePackages -serviceName $service -moniker $moniker -author $author -msAuthor $msauthor -msService $msService
}
}