Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools repository
Browse files Browse the repository at this point in the history
  • Loading branch information
azure-sdk committed May 27, 2020
1 parent 369e411 commit 6a64cf3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 32 deletions.
42 changes: 29 additions & 13 deletions eng/common/scripts/artifact-metadata-parsing.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ function ParseMavenPackage($pkg, $workingDirectory) {
$pkgVersion = $contentXML.project.version
$groupId = if ($contentXML.project.groupId -eq $null) { $contentXML.project.parent.groupId } else { $contentXML.project.groupId }
$releaseNotes = ""
$readmeContent = ""

# if it's a snapshot. return $null (as we don't want to create tags for this, but we also don't want to fail)
if ($pkgVersion.Contains("SNAPSHOT")) {
return $null
}

if (@(Get-ChildItem -Path $pkg.DirectoryName -Recurse -Include "$($pkg.Basename)-changelog.md")[0]) {
$releaseNotes = &"${PSScriptRoot}/../Extract-ReleaseNotes.ps1" -ChangeLogLocation @(Get-ChildItem -Path $pkg.DirectoryName -Recurse -Include "$($pkg.Basename)-changelog.md")[0]
$changeLogLoc = @(Get-ChildItem -Path $pkg.DirectoryName -Recurse -Include "$($pkg.Basename)-changelog.md")[0]
if ($changeLogLoc) {
$releaseNotes = &"${PSScriptRoot}/../Extract-ReleaseNotes.ps1" -ChangeLogLocation $changeLogLoc
}

$readmeContentLoc = @(Get-ChildItem -Path $pkg.DirectoryName -Recurse -Include "$($pkg.Basename)-readme.md")[0]
Expand Down Expand Up @@ -159,6 +161,7 @@ function ParseNPMPackage($pkg, $workingDirectory) {
$workFolder = "$workingDirectory$($pkg.Basename)"
$origFolder = Get-Location
$releaseNotes = ""
$readmeContent = ""

New-Item -ItemType Directory -Force -Path $workFolder
cd $workFolder
Expand All @@ -167,8 +170,9 @@ function ParseNPMPackage($pkg, $workingDirectory) {

$packageJSON = ResolvePkgJson -workFolder $workFolder | Get-Content | ConvertFrom-Json

if (@(Get-ChildItem -Path $workFolder -Recurse -Include "CHANGELOG.md")[0]) {
$releaseNotes = &"${PSScriptRoot}/../Extract-ReleaseNotes.ps1" -ChangeLogLocation @(Get-ChildItem -Path $workFolder -Recurse -Include "CHANGELOG.md")[0]
$changeLogLoc = @(Get-ChildItem -Path $workFolder -Recurse -Include "CHANGELOG.md")[0]
if ($changeLogLoc) {
$releaseNotes = &"${PSScriptRoot}/../Extract-ReleaseNotes.ps1" -ChangeLogLocation $changeLogLoc
}

$readmeContentLoc = @(Get-ChildItem -Path $workFolder -Recurse -Include "README.md")[0]
Expand Down Expand Up @@ -218,14 +222,17 @@ function ParseNugetPackage($pkg, $workingDirectory) {
$origFolder = Get-Location
$zipFileLocation = "$workFolder/$($pkg.Basename).zip"
$releaseNotes = ""
$readmeContent = ""

New-Item -ItemType Directory -Force -Path $workFolder

Copy-Item -Path $pkg -Destination $zipFileLocation
Expand-Archive -Path $zipFileLocation -DestinationPath $workFolder
[xml] $packageXML = Get-ChildItem -Path "$workFolder/*.nuspec" | Get-Content

if (@(Get-ChildItem -Path $workFolder -Recurse -Include "CHANGELOG.md")[0]) {
$releaseNotes = &"${PSScriptRoot}/../Extract-ReleaseNotes.ps1" -ChangeLogLocation @(Get-ChildItem -Path $workFolder -Recurse -Include "CHANGELOG.md")[0]
$changeLogLoc = @(Get-ChildItem -Path $workFolder -Recurse -Include "CHANGELOG.md")[0]
if ($changeLogLoc) {
$releaseNotes = &"${PSScriptRoot}/../Extract-ReleaseNotes.ps1" -ChangeLogLocation $changeLogLoc
}

$readmeContentLoc = @(Get-ChildItem -Path $workFolder -Recurse -Include "README.md")[0]
Expand Down Expand Up @@ -283,12 +290,14 @@ function ParsePyPIPackage($pkg, $workingDirectory) {
$workFolder = "$workingDirectory$($pkg.Basename)"
$origFolder = Get-Location
$releaseNotes = ""
$readmeContent = ""

New-Item -ItemType Directory -Force -Path $workFolder
Expand-Archive -Path $pkg -DestinationPath $workFolder

if (@(Get-ChildItem -Path $workFolder -Recurse -Include "CHANGELOG.md")[0]) {
$releaseNotes = &"${PSScriptRoot}/../Extract-ReleaseNotes.ps1" -ChangeLogLocation @(Get-ChildItem -Path $workFolder -Recurse -Include "CHANGELOG.md")[0]
$changeLogLoc = @(Get-ChildItem -Path $workFolder -Recurse -Include "CHANGELOG.md")[0]
if ($changeLogLoc) {
$releaseNotes = &"${PSScriptRoot}/../Extract-ReleaseNotes.ps1" -ChangeLogLocation $changeLogLoc
}

$readmeContentLoc = @(Get-ChildItem -Path $workFolder -Recurse -Include "README.md")[0]
Expand All @@ -310,10 +319,12 @@ function ParseCArtifact($pkg, $workingDirectory) {
$packageInfo = Get-Content -Raw -Path $pkg | ConvertFrom-JSON
$packageArtifactLocation = (Get-ItemProperty $pkg).Directory.FullName
$releaseNotes = ""
$readmeContent = ""

if (@(Get-ChildItem -Path $packageArtifactLocation -Recurse -Include "CHANGELOG.md")[0])
$changeLogLoc = @(Get-ChildItem -Path $packageArtifactLocation -Recurse -Include "CHANGELOG.md")[0]
if ($changeLogLoc)
{
$releaseNotes = &"${PSScriptRoot}/../Extract-ReleaseNotes.ps1" -changeLogLocation @(Get-ChildItem -Path $packageArtifactLocation -Recurse -Include "CHANGELOG.md")[0]
$releaseNotes = &"${PSScriptRoot}/../Extract-ReleaseNotes.ps1" -ChangeLogLocation $changeLogLoc
}

$readmeContentLoc = @(Get-ChildItem -Path $packageArtifactLocation -Recurse -Include "README.md")[0]
Expand All @@ -322,14 +333,13 @@ function ParseCArtifact($pkg, $workingDirectory) {
}

return New-Object PSObject -Property @{
PackageId = $packageInfo.name
PackageId = ''
PackageVersion = $packageInfo.version
# Artifact info is always considered deployable for C becasue it is not
# deployed anywhere. Dealing with duplicate tags happens downstream in
# CheckArtifactShaAgainstTagsList
Deployable = $true
ReleaseNotes = $releaseNotes
ReadmeContent = $readmeContent
}
}

Expand Down Expand Up @@ -432,10 +442,16 @@ function VerifyPackages($pkgRepository, $artifactLocation, $workingDirectory, $a
exit(1)
}

$tag = if ($parsedPackage.packageId) {
"$($parsedPackage.packageId)_$($parsedPackage.PackageVersion)"
} else {
$parsedPackage.PackageVersion
}

$pkgList += New-Object PSObject -Property @{
PackageId = $parsedPackage.PackageId
PackageVersion = $parsedPackage.PackageVersion
Tag = ($parsedPackage.PackageId + "_" + $parsedPackage.PackageVersion)
Tag = $tag
ReleaseNotes = $parsedPackage.ReleaseNotes
ReadmeContent = $parsedPackage.ReadmeContent
}
Expand Down
13 changes: 5 additions & 8 deletions eng/common/scripts/copy-docs-to-blobstorage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,11 @@ if ($Language -eq "java")
if ($Language -eq "c")
{
# The documentation publishing process for C differs from the other
# langauges in this file because this script is invoked once per library
# langauges in this file because this script is invoked for the whole SDK
# publishing. It is not, for example, invoked once per service publishing.
# This is also the case for other langauge publishing steps above... Those
# loops are left over from previous versions of this script which were used
# to publish multiple docs packages in a single invocation.
# There is a similar situation for other langauge publishing steps above...
# Those loops are left over from previous versions of this script which were
# used to publish multiple docs packages in a single invocation.
$pkgInfo = Get-Content $DocLocation/package-info.json | ConvertFrom-Json
$pkgName = $pkgInfo.name
$pkgVersion = $pkgInfo.version

Upload-Blobs -DocDir $DocLocation -PkgName $pkgName -DocVersion $pkgVersion
Upload-Blobs -DocDir $DocLocation -PkgName 'docs' -DocVersion $pkgInfo.version
}
34 changes: 23 additions & 11 deletions eng/common/scripts/update-docs-metadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ Write-Host "> $PSCommandPath $args"
function GetMetaData($lang){
switch ($lang) {
"java" {
$metadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/master/_data/releases/latest/java-packages.csv"
$metadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/master/_data/allpackages/java-packages.csv"
break
}
".net" {
$metadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/master/_data/releases/latest/dotnet-packages.csv"
$metadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/master/_data/allpackages/dotnet-packages.csv"
break
}
"python" {
$metadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/master/_data/releases/latest/python-packages.csv"
$metadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/master/_data/allpackages/python-packages.csv"
break
}
"javascript" {
$metadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/master/_data/releases/latest/js-packages.csv"
$metadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/master/_data/allpackages/js-packages.csv"
break
}
default {
Expand All @@ -46,6 +46,8 @@ function GetMetaData($lang){
}

$metadataResponse = Invoke-WebRequest-WithHandling -url $metadataUri -method "GET" | ConvertFrom-Csv

return $metadataResponse
}

function GetAdjustedReadmeContent($pkgInfo, $lang){
Expand All @@ -57,23 +59,30 @@ function GetAdjustedReadmeContent($pkgInfo, $lang){

try {
$metadata = GetMetaData -lang $lang

$service = $metadata | ? { $_.Package -eq $pkgId }

if ($service) {
$service = "$service,"
$service = "$($service.Service)"
}
}
catch {
Write-Host $_
Write-Host "Unable to retrieve service metadata for packageId $($pkgInfo.PackageId)"
}

$headerContentMatch = (Select-String -InputObject $pkgInfo.ReadmeContent -Pattern 'Azure .+? (client|plugin|shared) library for (JavaScript|Java|Python|\.NET|C)').Matches[0]
$fileContent = $pkgInfo.ReadmeContent

# only replace the version if the formatted header can be found
$headerContentMatches = (Select-String -InputObject $pkgInfo.ReadmeContent -Pattern 'Azure .+? (client|plugin|shared) library for (JavaScript|Java|Python|\.NET|C)')
if ($headerContentMatches) {
$headerContentMatch = $headerContentMatches.Matches[0]
$header = "---`ntitle: $headerContentMatch`nkeywords: Azure, $lang, SDK, API, $($pkgInfo.PackageId), $service`nauthor: maggiepint`nms.author: magpint`nms.date: $date`nms.topic: article`nms.prod: azure`nms.technology: azure`nms.devlang: $lang`nms.service: $service`n---`n"
$fileContent = $pkgInfo.ReadmeContent -replace $headerContentMatch, "$headerContentMatch - Version $($pkgInfo.PackageVersion) `n"
}

if ($headerContentMatch){
$header = "---`r`ntitle: $headerContentMatch`r`nkeywords: Azure, $lang, SDK, API, $service $($pkgInfo.PackageId)`r`nauthor: maggiepint`r`nms.author: magpint`r`nms.date: $date`r`nms.topic: article`r`nms.prod: azure`r`nms.technology: azure`r`nms.devlang: $lang`r`nms.service: $service`r`n---`r`n"
$fileContent = $pkgInfo.ReadmeContent -replace $headerContentMatch, "$headerContentMatch - Version $($pkgInfo.PackageVersion) `r`n"
return "$header $fileContent"
if ($fileContent) {
return "$header`n$fileContent"
}
else {
return ""
Expand Down Expand Up @@ -102,7 +111,10 @@ if ($pkgs) {

$readmeName = "$($packageInfo.PackageId.Replace('azure-','').Replace('Azure.', '').Replace('@azure/', '').ToLower())-readme$rdSuffix.md"
$readmeLocation = Join-Path $DocRepoLocation $DocRepoContentLocation $readmeName
$adjustedContent = GetAdjustedReadmeContent -pkgInfo $packageInfo -lang $Language

if ($packageInfo.ReadmeContent) {
$adjustedContent = GetAdjustedReadmeContent -pkgInfo $packageInfo -lang $Language
}

if ($adjustedContent) {
try {
Expand Down

0 comments on commit 6a64cf3

Please sign in to comment.