-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync eng/common directory with azure-sdk-tools for PR 4632 (#32473)
* Service readme index table stays the same even the table content needs to update * adjust the edge cases tests * change the helper function to helper folder * add missing files * Fixed the service name Co-authored-by: sima-zhu <[email protected]>
- Loading branch information
Showing
3 changed files
with
122 additions
and
132 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
90 changes: 90 additions & 0 deletions
90
eng/common/scripts/Helpers/Service-Level-Readme-Automation-Helpers.ps1
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,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*(?<metadata>(.*\n?)*?)---\n*(?<content>(.*\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 | ||
} | ||
} |
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