From 8d467b329e0c15563acbe04d373c16a963d51545 Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 11 Nov 2022 09:31:54 -0800 Subject: [PATCH 1/5] Service readme index table stays the same even the table content needs to update --- .../scripts/Helpers/Metadata-Helpers.ps1 | 21 +-- ...vice-Level-Readme-Automation-Functions.ps1 | 90 +++++++++++ .../Service-Level-Readme-Automation.ps1 | 143 ++++-------------- 3 files changed, 122 insertions(+), 132 deletions(-) create mode 100644 eng/common/scripts/Service-Level-Readme-Automation-Functions.ps1 diff --git a/eng/common/scripts/Helpers/Metadata-Helpers.ps1 b/eng/common/scripts/Helpers/Metadata-Helpers.ps1 index ba6f32b7d725f..ed6d1bd76c63d 100644 --- a/eng/common/scripts/Helpers/Metadata-Helpers.ps1 +++ b/eng/common/scripts/Helpers/Metadata-Helpers.ps1 @@ -101,7 +101,7 @@ function compare-and-merge-metadata ($original, $updated) { } $originalTable = ConvertFrom-StringData -StringData $original -Delimiter ":" foreach ($key in $originalTable.Keys) { - if (!($updated.ContainsKey($key))) { + if (!($updated.Contains($key))) { Write-Warning "New metadata missed the entry: $key. Adding back." $updateMetdata += "$key`: $($originalTable[$key])`r`n" } @@ -109,28 +109,13 @@ function compare-and-merge-metadata ($original, $updated) { return $updateMetdata } -function GenerateDocsMsMetadata($originalMetadata, $language, $languageDisplayName, $serviceName, $tenantId, $clientId, $clientSecret, $msService) +function GenerateDocsMsMetadata($originalMetadata, $language, $languageDisplayName, $serviceName, $author, $msAuthor, $msService) { $langTitle = "Azure $serviceName SDK for $languageDisplayName" $langDescription = "Reference for Azure $serviceName SDK for $languageDisplayName" - # Github url for source code: e.g. https://github.com/Azure/azure-sdk-for-js - $serviceBaseName = $serviceName.ToLower().Replace(' ', '').Replace('/', '-') - $author = GetPrimaryCodeOwner -TargetDirectory "/sdk/$serviceBaseName/" - $msauthor = "" - if (!$author) { - LogError "Cannot fetch the author from CODEOWNER file." - } - 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 - } $date = Get-Date -Format "MM/dd/yyyy" - $metadataTable = @{ + $metadataTable = [ordered]@{ "title"= $langTitle "description"= $langDescription "author"= $author diff --git a/eng/common/scripts/Service-Level-Readme-Automation-Functions.ps1 b/eng/common/scripts/Service-Level-Readme-Automation-Functions.ps1 new file mode 100644 index 0000000000000..efc817c71b8f7 --- /dev/null +++ b/eng/common/scripts/Service-Level-Readme-Automation-Functions.ps1 @@ -0,0 +1,90 @@ + +function create-service-readme($readmeFolder, $readmeName, $moniker, $msService, $indexTableLink, $serviceName, $author, $msAuthor) +{ + $readmePath = Join-Path $readmeFolder -ChildPath $readmeName + $content = "" + if (Test-Path (Join-Path $readmeFolder -ChildPath $indexTableLink)) { + $content = "## Packages - $moniker`r`n" + $content += "[!INCLUDE [packages]($indexTableLink)]" + } + if (!$content) { + LogError "There are no packages under service '$serviceName'. " + return + } + # Generate the front-matter for docs needs + # $Language, $LanguageDisplayName are the variables globally defined in Language-Settings.ps1 + $metadataString = GenerateDocsMsMetadata -language $Language -languageDisplayName $LanguageDisplayName -serviceName $serviceName ` + -author $author -msAuthor $msAuthor -msService $msService + Add-Content -Path $readmePath -Value $metadataString -NoNewline + + # Add tables, conbined client and mgmt together. + $readmeHeader = "# Azure $serviceName SDK for $languageDisplayName - $moniker`r`n" + Set-Content -Path $readmePath -Value "$metadataString$readmeHeader$content" -NoNewline +} + +# Update the metadata table. +function update-metadata-table($readmeFolder, $readmeName, $serviceName, $msService, $author, $msAuthor) +{ + $readmePath = Join-Path $readmeFolder -ChildPath $readmeName + $readmeContent = Get-Content -Path $readmePath -Raw + $match = $readmeContent -match "^---\n*(?(.*\n?)*?)---\n*(?(.*\n?)*)" + $restContent = $readmeContent + $metadata = "" + if ($match) { + $restContent = $Matches["content"].trim() + $metadata = $Matches["metadata"].trim() + } + # $Language, $LanguageDisplayName are the variables globally defined in Language-Settings.ps1 + $metadataString = GenerateDocsMsMetadata -originalMetadata $metadata -language $Language -languageDisplayName $LanguageDisplayName -serviceName $serviceName ` + -author $author -msAuthor $msAuthor -msService $msService + Set-Content -Path $readmePath -Value "$metadataString$restContent" -NoNewline +} + +function generate-markdown-table($readmeFolder, $readmeName, $packageInfos, $moniker) { + $tableHeader = "| Reference | Package | Source |`r`n|---|---|---|`r`n" + $tableContent = "" + $packageInfos = $packageInfos | Sort-Object -Property Type,Package + # Here is the table, the versioned value will + foreach ($pkg in $packageInfos) { + $repositoryLink = "$PackageRepositoryUri/$($pkg.Package)" + if (Test-Path "Function:$GetRepositoryLinkFn") { + $repositoryLink = &$GetRepositoryLinkFn -packageInfo $pkg + } + $packageLevelReadme = "" + if (Test-Path "Function:$GetPackageLevelReadmeFn") { + $packageLevelReadme = &$GetPackageLevelReadmeFn -packageMetadata $pkg + } + + $referenceLink = "[$($pkg.DisplayName)]($packageLevelReadme-readme.md)" + if (!(Test-Path (Join-Path $readmeFolder -ChildPath "$packageLevelReadme-readme.md"))) { + $referenceLink = $pkg.DisplayName + } + $githubLink = $GithubUri + if ($pkg.PSObject.Members.Name -contains "DirectoryPath") { + $githubLink = "$GithubUri/blob/main/$($pkg.DirectoryPath)" + } + $line = "|$referenceLink|[$($pkg.Package)]($repositoryLink)|[Github]($githubLink)|`r`n" + $tableContent += $line + } + $readmePath = Join-Path $readmeFolder -ChildPath $readmeName + if($tableContent) { + Set-Content -Path $readmePath -Value "$tableHeader$tableContent" -NoNewline -Force + } +} + +function generate-service-level-readme($docRepoLocation, $readmeBaseName, $pathPrefix, $packageInfos, $serviceName, $moniker, $author, $msAuthor, $msService) { + $readmeFolder = "$docRepoLocation/$pathPrefix/$moniker/" + $serviceReadme = "$readmeBaseName.md" + $indexReadme = "$readmeBaseName-index.md" + if ($packageInfos) { + generate-markdown-table -readmeFolder $readmeFolder -readmeName $indexReadme -packageInfos $packageInfos -moniker $moniker + } + if (!(Test-Path "$readmeFolder$serviceReadme")) { + create-service-readme -readmeFolder $readmeFolder -readmeName $serviceReadme -moniker $moniker -msService $msService ` + -indexTableLink $indexReadme -serviceName $serviceName -author $author -msAuthor $msAuthor + } + else { + update-metadata-table -readmeFolder $readmeFolder -readmeName $serviceReadme -serviceName $serviceName ` + -msService $msService -author $author -msAuthor $msAuthor + } +} \ No newline at end of file diff --git a/eng/common/scripts/Service-Level-Readme-Automation.ps1 b/eng/common/scripts/Service-Level-Readme-Automation.ps1 index 1bef0122935b4..096407af3eb5c 100644 --- a/eng/common/scripts/Service-Level-Readme-Automation.ps1 +++ b/eng/common/scripts/Service-Level-Readme-Automation.ps1 @@ -21,6 +21,9 @@ 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( @@ -34,122 +37,18 @@ param( [string]$ClientId, [Parameter(Mandatory = $false)] - [string]$ClientSecret + [string]$ClientSecret, + + [Parameter(Mandatory = $false)] + [string]$ReadmeFolderRoot = "docs-ref-services" ) . $PSScriptRoot/common.ps1 +. $PSScriptRoot/Service-Level-Readme-Automation-Functions.ps1 . $PSScriptRoot/Helpers/Metadata-Helpers.ps1 . $PSScriptRoot/Helpers/Package-Helpers.ps1 Set-StrictMode -Version 3 -function create-metadata-table($readmeFolder, $readmeName, $moniker, $msService, $clientTableLink, $mgmtTableLink, $serviceName) -{ - $readmePath = Join-Path $readmeFolder -ChildPath $readmeName - $content = "" - if (Test-Path (Join-Path $readmeFolder -ChildPath $clientTableLink)) { - $content = "## Client packages - $moniker`r`n" - $content += "[!INCLUDE [client-packages]($clientTableLink)]`r`n" - } - if (Test-Path (Join-Path $readmeFolder -ChildPath $mgmtTableLink)) { - $content += "## Management packages - $moniker`r`n" - $content += "[!INCLUDE [mgmt-packages]($mgmtTableLink)]`r`n" - } - if (!$content) { - return - } - # Generate the front-matter for docs needs - # $Language, $LanguageDisplayName are the variables globally defined in Language-Settings.ps1 - $metadataString = GenerateDocsMsMetadata -language $Language -languageDisplayName $LanguageDisplayName -serviceName $serviceName ` - -tenantId $TenantId -clientId $ClientId -clientSecret $ClientSecret ` - -msService $msService - Add-Content -Path $readmePath -Value $metadataString -NoNewline - - # Add tables, seperate client and mgmt. - $readmeHeader = "# Azure $serviceName SDK for $languageDisplayName - $moniker`r`n" - Add-Content -Path $readmePath -Value $readmeHeader - Add-Content -Path $readmePath -Value $content -NoNewline -} - -# Update the metadata table. -function update-metadata-table($readmeFolder, $readmeName, $serviceName, $msService) -{ - $readmePath = Join-Path $readmeFolder -ChildPath $readmeName - $readmeContent = Get-Content -Path $readmePath -Raw - $match = $readmeContent -match "^---\n*(?(.*\n?)*?)---\n*(?(.*\n?)*)" - $restContent = $readmeContent - $metadata = "" - if ($match) { - $restContent = $Matches["content"].trim() - $metadata = $Matches["metadata"].trim() - } - # $Language, $LanguageDisplayName are the variables globally defined in Language-Settings.ps1 - $metadataString = GenerateDocsMsMetadata -originalMetadata $metadata -language $Language -languageDisplayName $LanguageDisplayName -serviceName $serviceName ` - -tenantId $TenantId -clientId $ClientId -clientSecret $ClientSecret ` - -msService $msService - Set-Content -Path $readmePath -Value "$metadataString$restContent" -NoNewline -} - -function generate-markdown-table($readmeFolder, $readmeName, $packageInfo, $moniker) { - $tableHeader = "| Reference | Package | Source |`r`n|---|---|---|`r`n" - $tableContent = "" - # Here is the table, the versioned value will - foreach ($pkg in $packageInfo) { - $repositoryLink = "$PackageRepositoryUri/$($pkg.Package)" - if (Test-Path "Function:$GetRepositoryLinkFn") { - $repositoryLink = &$GetRepositoryLinkFn -packageInfo $pkg - } - $packageLevelReadme = "" - if (Test-Path "Function:$GetPackageLevelReadmeFn") { - $packageLevelReadme = &$GetPackageLevelReadmeFn -packageMetadata $pkg - } - - $referenceLink = "[$($pkg.DisplayName)]($packageLevelReadme-readme.md)" - if (!(Test-Path (Join-Path $readmeFolder -ChildPath "$packageLevelReadme-readme.md"))) { - $referenceLink = $pkg.DisplayName - } - $githubLink = $GithubUri - if ($pkg.PSObject.Members.Name -contains "DirectoryPath") { - $githubLink = "$GithubUri/blob/main/$($pkg.DirectoryPath)" - } - $line = "|$referenceLink|[$($pkg.Package)]($repositoryLink)|[Github]($githubLink)|`r`n" - $tableContent += $line - } - $readmePath = Join-Path $readmeFolder -ChildPath $readmeName - if($tableContent) { - $null = New-Item -Path $readmePath -ItemType File -Force - Add-Content -Path $readmePath -Value $tableHeader -NoNewline - Add-Content -Path $readmePath -Value $tableContent -NoNewline - } -} - -function generate-service-level-readme($readmeBaseName, $pathPrefix, $packageInfos, $serviceName, $moniker) { - # Add ability to override - # Fetch the service readme name - $msService = GetDocsMsService -packageInfo $packageInfos[0] -serviceName $serviceName - - $readmeFolder = "$DocRepoLocation/$pathPrefix/$moniker/" - $serviceReadme = "$readmeBaseName.md" - $clientIndexReadme = "$readmeBaseName-client-index.md" - $mgmtIndexReadme = "$readmeBaseName-mgmt-index.md" - $clientPackageInfo = $packageInfos.Where({ 'client' -eq $_.Type }) | Sort-Object -Property Package - if ($clientPackageInfo) { - generate-markdown-table -readmeFolder $readmeFolder -readmeName $clientIndexReadme -packageInfo $clientPackageInfo -moniker $moniker - } - - $mgmtPackageInfo = $packageInfos.Where({ 'mgmt' -eq $_.Type }) | Sort-Object -Property Package - if ($mgmtPackageInfo) { - generate-markdown-table -readmeFolder $readmeFolder -readmeName $mgmtIndexReadme -packageInfo $mgmtPackageInfo -moniker $moniker - } - if (!(Test-Path (Join-Path $readmeFolder -ChildPath $serviceReadme))) { - create-metadata-table -readmeFolder $readmeFolder -readmeName $serviceReadme -moniker $moniker -msService $msService ` - -clientTableLink $clientIndexReadme -mgmtTableLink $mgmtIndexReadme ` - -serviceName $serviceName - } - else { - update-metadata-table -readmeFolder $readmeFolder -readmeName $serviceReadme -serviceName $serviceName -msService $msService - } -} - $fullMetadata = Get-CSVMetadata $monikers = @("latest", "preview") foreach($moniker in $monikers) { @@ -213,12 +112,28 @@ foreach($moniker in $monikers) { } foreach ($service in $services.Keys) { Write-Host "Building service: $service" - $servicePackages = $packagesForService.Values.Where({ $_.ServiceName -eq $service }) $serviceReadmeBaseName = ServiceLevelReadmeNameStyle -serviceName $service - $hrefPrefix = "docs-ref-services" - - generate-service-level-readme -readmeBaseName $serviceReadmeBaseName -pathPrefix $hrefPrefix ` - -packageInfos $servicePackages -serviceName $service -moniker $moniker + # Github url for source code: e.g. https://github.com/Azure/azure-sdk-for-js + $serviceBaseName = ServiceLevelReadmeNameStyle $serviceName + $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 $serviceName + generate-service-level-readme -docRepoLocation $DocRepoLocation -readmeBaseName $serviceReadmeBaseName -pathPrefix $ReadmeFolderRoot ` + -packageInfos $servicePackages -serviceName $service -moniker $moniker -author $author -msAuthor $msauthor -msService $msService } } From 25d43bcb784c19d597611fb5e309fe48a82ae8ef Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 11 Nov 2022 11:06:30 -0800 Subject: [PATCH 2/5] adjust the edge cases tests --- .../scripts/Service-Level-Readme-Automation-Functions.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/common/scripts/Service-Level-Readme-Automation-Functions.ps1 b/eng/common/scripts/Service-Level-Readme-Automation-Functions.ps1 index efc817c71b8f7..f6452bdd5b3cc 100644 --- a/eng/common/scripts/Service-Level-Readme-Automation-Functions.ps1 +++ b/eng/common/scripts/Service-Level-Readme-Automation-Functions.ps1 @@ -79,11 +79,11 @@ function generate-service-level-readme($docRepoLocation, $readmeBaseName, $pathP if ($packageInfos) { generate-markdown-table -readmeFolder $readmeFolder -readmeName $indexReadme -packageInfos $packageInfos -moniker $moniker } - if (!(Test-Path "$readmeFolder$serviceReadme")) { + if (!(Test-Path "$readmeFolder$serviceReadme") -and $packageInfos) { create-service-readme -readmeFolder $readmeFolder -readmeName $serviceReadme -moniker $moniker -msService $msService ` -indexTableLink $indexReadme -serviceName $serviceName -author $author -msAuthor $msAuthor } - else { + elseif (Test-Path "$readmeFolder$serviceReadme") { update-metadata-table -readmeFolder $readmeFolder -readmeName $serviceReadme -serviceName $serviceName ` -msService $msService -author $author -msAuthor $msAuthor } From c62a24270d28d4626c9fe0da9f5119275a89977c Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Mon, 14 Nov 2022 11:48:18 -0800 Subject: [PATCH 3/5] change the helper function to helper folder --- ...vice-Level-Readme-Automation-Functions.ps1 | 90 ------------------- .../Service-Level-Readme-Automation.ps1 | 2 +- 2 files changed, 1 insertion(+), 91 deletions(-) delete mode 100644 eng/common/scripts/Service-Level-Readme-Automation-Functions.ps1 diff --git a/eng/common/scripts/Service-Level-Readme-Automation-Functions.ps1 b/eng/common/scripts/Service-Level-Readme-Automation-Functions.ps1 deleted file mode 100644 index f6452bdd5b3cc..0000000000000 --- a/eng/common/scripts/Service-Level-Readme-Automation-Functions.ps1 +++ /dev/null @@ -1,90 +0,0 @@ - -function create-service-readme($readmeFolder, $readmeName, $moniker, $msService, $indexTableLink, $serviceName, $author, $msAuthor) -{ - $readmePath = Join-Path $readmeFolder -ChildPath $readmeName - $content = "" - if (Test-Path (Join-Path $readmeFolder -ChildPath $indexTableLink)) { - $content = "## Packages - $moniker`r`n" - $content += "[!INCLUDE [packages]($indexTableLink)]" - } - if (!$content) { - LogError "There are no packages under service '$serviceName'. " - return - } - # Generate the front-matter for docs needs - # $Language, $LanguageDisplayName are the variables globally defined in Language-Settings.ps1 - $metadataString = GenerateDocsMsMetadata -language $Language -languageDisplayName $LanguageDisplayName -serviceName $serviceName ` - -author $author -msAuthor $msAuthor -msService $msService - Add-Content -Path $readmePath -Value $metadataString -NoNewline - - # Add tables, conbined client and mgmt together. - $readmeHeader = "# Azure $serviceName SDK for $languageDisplayName - $moniker`r`n" - Set-Content -Path $readmePath -Value "$metadataString$readmeHeader$content" -NoNewline -} - -# Update the metadata table. -function update-metadata-table($readmeFolder, $readmeName, $serviceName, $msService, $author, $msAuthor) -{ - $readmePath = Join-Path $readmeFolder -ChildPath $readmeName - $readmeContent = Get-Content -Path $readmePath -Raw - $match = $readmeContent -match "^---\n*(?(.*\n?)*?)---\n*(?(.*\n?)*)" - $restContent = $readmeContent - $metadata = "" - if ($match) { - $restContent = $Matches["content"].trim() - $metadata = $Matches["metadata"].trim() - } - # $Language, $LanguageDisplayName are the variables globally defined in Language-Settings.ps1 - $metadataString = GenerateDocsMsMetadata -originalMetadata $metadata -language $Language -languageDisplayName $LanguageDisplayName -serviceName $serviceName ` - -author $author -msAuthor $msAuthor -msService $msService - Set-Content -Path $readmePath -Value "$metadataString$restContent" -NoNewline -} - -function generate-markdown-table($readmeFolder, $readmeName, $packageInfos, $moniker) { - $tableHeader = "| Reference | Package | Source |`r`n|---|---|---|`r`n" - $tableContent = "" - $packageInfos = $packageInfos | Sort-Object -Property Type,Package - # Here is the table, the versioned value will - foreach ($pkg in $packageInfos) { - $repositoryLink = "$PackageRepositoryUri/$($pkg.Package)" - if (Test-Path "Function:$GetRepositoryLinkFn") { - $repositoryLink = &$GetRepositoryLinkFn -packageInfo $pkg - } - $packageLevelReadme = "" - if (Test-Path "Function:$GetPackageLevelReadmeFn") { - $packageLevelReadme = &$GetPackageLevelReadmeFn -packageMetadata $pkg - } - - $referenceLink = "[$($pkg.DisplayName)]($packageLevelReadme-readme.md)" - if (!(Test-Path (Join-Path $readmeFolder -ChildPath "$packageLevelReadme-readme.md"))) { - $referenceLink = $pkg.DisplayName - } - $githubLink = $GithubUri - if ($pkg.PSObject.Members.Name -contains "DirectoryPath") { - $githubLink = "$GithubUri/blob/main/$($pkg.DirectoryPath)" - } - $line = "|$referenceLink|[$($pkg.Package)]($repositoryLink)|[Github]($githubLink)|`r`n" - $tableContent += $line - } - $readmePath = Join-Path $readmeFolder -ChildPath $readmeName - if($tableContent) { - Set-Content -Path $readmePath -Value "$tableHeader$tableContent" -NoNewline -Force - } -} - -function generate-service-level-readme($docRepoLocation, $readmeBaseName, $pathPrefix, $packageInfos, $serviceName, $moniker, $author, $msAuthor, $msService) { - $readmeFolder = "$docRepoLocation/$pathPrefix/$moniker/" - $serviceReadme = "$readmeBaseName.md" - $indexReadme = "$readmeBaseName-index.md" - if ($packageInfos) { - generate-markdown-table -readmeFolder $readmeFolder -readmeName $indexReadme -packageInfos $packageInfos -moniker $moniker - } - if (!(Test-Path "$readmeFolder$serviceReadme") -and $packageInfos) { - create-service-readme -readmeFolder $readmeFolder -readmeName $serviceReadme -moniker $moniker -msService $msService ` - -indexTableLink $indexReadme -serviceName $serviceName -author $author -msAuthor $msAuthor - } - elseif (Test-Path "$readmeFolder$serviceReadme") { - update-metadata-table -readmeFolder $readmeFolder -readmeName $serviceReadme -serviceName $serviceName ` - -msService $msService -author $author -msAuthor $msAuthor - } -} \ No newline at end of file diff --git a/eng/common/scripts/Service-Level-Readme-Automation.ps1 b/eng/common/scripts/Service-Level-Readme-Automation.ps1 index 096407af3eb5c..7250187cd3fb6 100644 --- a/eng/common/scripts/Service-Level-Readme-Automation.ps1 +++ b/eng/common/scripts/Service-Level-Readme-Automation.ps1 @@ -43,7 +43,7 @@ param( [string]$ReadmeFolderRoot = "docs-ref-services" ) . $PSScriptRoot/common.ps1 -. $PSScriptRoot/Service-Level-Readme-Automation-Functions.ps1 +. $PSScriptRoot/Helpers/Service-Level-Readme-Automation-Helpers.ps1 . $PSScriptRoot/Helpers/Metadata-Helpers.ps1 . $PSScriptRoot/Helpers/Package-Helpers.ps1 From 9cf1dc4abde3783d926c12ed0006498eb81981fe Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Mon, 14 Nov 2022 11:52:08 -0800 Subject: [PATCH 4/5] add missing files --- ...ervice-Level-Readme-Automation-Helpers.ps1 | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 eng/common/scripts/Helpers/Service-Level-Readme-Automation-Helpers.ps1 diff --git a/eng/common/scripts/Helpers/Service-Level-Readme-Automation-Helpers.ps1 b/eng/common/scripts/Helpers/Service-Level-Readme-Automation-Helpers.ps1 new file mode 100644 index 0000000000000..f6452bdd5b3cc --- /dev/null +++ b/eng/common/scripts/Helpers/Service-Level-Readme-Automation-Helpers.ps1 @@ -0,0 +1,90 @@ + +function create-service-readme($readmeFolder, $readmeName, $moniker, $msService, $indexTableLink, $serviceName, $author, $msAuthor) +{ + $readmePath = Join-Path $readmeFolder -ChildPath $readmeName + $content = "" + if (Test-Path (Join-Path $readmeFolder -ChildPath $indexTableLink)) { + $content = "## Packages - $moniker`r`n" + $content += "[!INCLUDE [packages]($indexTableLink)]" + } + if (!$content) { + LogError "There are no packages under service '$serviceName'. " + return + } + # Generate the front-matter for docs needs + # $Language, $LanguageDisplayName are the variables globally defined in Language-Settings.ps1 + $metadataString = GenerateDocsMsMetadata -language $Language -languageDisplayName $LanguageDisplayName -serviceName $serviceName ` + -author $author -msAuthor $msAuthor -msService $msService + Add-Content -Path $readmePath -Value $metadataString -NoNewline + + # Add tables, conbined client and mgmt together. + $readmeHeader = "# Azure $serviceName SDK for $languageDisplayName - $moniker`r`n" + Set-Content -Path $readmePath -Value "$metadataString$readmeHeader$content" -NoNewline +} + +# Update the metadata table. +function update-metadata-table($readmeFolder, $readmeName, $serviceName, $msService, $author, $msAuthor) +{ + $readmePath = Join-Path $readmeFolder -ChildPath $readmeName + $readmeContent = Get-Content -Path $readmePath -Raw + $match = $readmeContent -match "^---\n*(?(.*\n?)*?)---\n*(?(.*\n?)*)" + $restContent = $readmeContent + $metadata = "" + if ($match) { + $restContent = $Matches["content"].trim() + $metadata = $Matches["metadata"].trim() + } + # $Language, $LanguageDisplayName are the variables globally defined in Language-Settings.ps1 + $metadataString = GenerateDocsMsMetadata -originalMetadata $metadata -language $Language -languageDisplayName $LanguageDisplayName -serviceName $serviceName ` + -author $author -msAuthor $msAuthor -msService $msService + Set-Content -Path $readmePath -Value "$metadataString$restContent" -NoNewline +} + +function generate-markdown-table($readmeFolder, $readmeName, $packageInfos, $moniker) { + $tableHeader = "| Reference | Package | Source |`r`n|---|---|---|`r`n" + $tableContent = "" + $packageInfos = $packageInfos | Sort-Object -Property Type,Package + # Here is the table, the versioned value will + foreach ($pkg in $packageInfos) { + $repositoryLink = "$PackageRepositoryUri/$($pkg.Package)" + if (Test-Path "Function:$GetRepositoryLinkFn") { + $repositoryLink = &$GetRepositoryLinkFn -packageInfo $pkg + } + $packageLevelReadme = "" + if (Test-Path "Function:$GetPackageLevelReadmeFn") { + $packageLevelReadme = &$GetPackageLevelReadmeFn -packageMetadata $pkg + } + + $referenceLink = "[$($pkg.DisplayName)]($packageLevelReadme-readme.md)" + if (!(Test-Path (Join-Path $readmeFolder -ChildPath "$packageLevelReadme-readme.md"))) { + $referenceLink = $pkg.DisplayName + } + $githubLink = $GithubUri + if ($pkg.PSObject.Members.Name -contains "DirectoryPath") { + $githubLink = "$GithubUri/blob/main/$($pkg.DirectoryPath)" + } + $line = "|$referenceLink|[$($pkg.Package)]($repositoryLink)|[Github]($githubLink)|`r`n" + $tableContent += $line + } + $readmePath = Join-Path $readmeFolder -ChildPath $readmeName + if($tableContent) { + Set-Content -Path $readmePath -Value "$tableHeader$tableContent" -NoNewline -Force + } +} + +function generate-service-level-readme($docRepoLocation, $readmeBaseName, $pathPrefix, $packageInfos, $serviceName, $moniker, $author, $msAuthor, $msService) { + $readmeFolder = "$docRepoLocation/$pathPrefix/$moniker/" + $serviceReadme = "$readmeBaseName.md" + $indexReadme = "$readmeBaseName-index.md" + if ($packageInfos) { + generate-markdown-table -readmeFolder $readmeFolder -readmeName $indexReadme -packageInfos $packageInfos -moniker $moniker + } + if (!(Test-Path "$readmeFolder$serviceReadme") -and $packageInfos) { + create-service-readme -readmeFolder $readmeFolder -readmeName $serviceReadme -moniker $moniker -msService $msService ` + -indexTableLink $indexReadme -serviceName $serviceName -author $author -msAuthor $msAuthor + } + elseif (Test-Path "$readmeFolder$serviceReadme") { + update-metadata-table -readmeFolder $readmeFolder -readmeName $serviceReadme -serviceName $serviceName ` + -msService $msService -author $author -msAuthor $msAuthor + } +} \ No newline at end of file From 915d13d0f127886b7b9a24d8032c001d9cb7da8e Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Mon, 14 Nov 2022 14:15:14 -0800 Subject: [PATCH 5/5] Fixed the service name --- eng/common/scripts/Service-Level-Readme-Automation.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/common/scripts/Service-Level-Readme-Automation.ps1 b/eng/common/scripts/Service-Level-Readme-Automation.ps1 index 7250187cd3fb6..2d0e5c67920a9 100644 --- a/eng/common/scripts/Service-Level-Readme-Automation.ps1 +++ b/eng/common/scripts/Service-Level-Readme-Automation.ps1 @@ -115,7 +115,7 @@ foreach($moniker in $monikers) { $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 $serviceName + $serviceBaseName = ServiceLevelReadmeNameStyle $service $author = GetPrimaryCodeOwner -TargetDirectory "/sdk/$serviceBaseName/" $msauthor = "" if (!$author) { @@ -132,7 +132,7 @@ foreach($moniker in $monikers) { } # Add ability to override # Fetch the service readme name - $msService = GetDocsMsService -packageInfo $servicePackages[0] -serviceName $serviceName + $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 }