Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools repository for Tools P…
Browse files Browse the repository at this point in the history
…R 926
  • Loading branch information
azure-sdk committed Sep 2, 2020
1 parent d32cfe4 commit 0ff5be8
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 24 deletions.
4 changes: 4 additions & 0 deletions eng/common/pipelines/templates/steps/publish-blobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ parameters:
TargetLanguage: ''
BlobName: ''
ScriptPath: ''
ArtifactLocation: ''
RepoId: $(Build.Repository.Name)

steps:
- pwsh: |
Expand All @@ -21,6 +23,8 @@ steps:
-SASKey "${{ parameters.BlobSASKey }}"
-Language "${{ parameters.TargetLanguage }}"
-BlobName "${{ parameters.BlobName }}"
-PublicArtifactLocation "${{ parameters.ArtifactLocation}}""
-RepoReplaceRegex "(https://github.com/${{ parameters.RepoId }}/(?:blob|tree)/)master(/.*)"
pwsh: true
workingDirectory: $(Pipeline.Workspace)
displayName: Copy Docs to Blob
Expand Down
48 changes: 36 additions & 12 deletions eng/common/scripts/artifact-metadata-parsing.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function ParseMavenPackage($pkg, $workingDirectory) {
PackageId = $pkgId
GroupId = $groupId
PackageVersion = $pkgVersion
ReleaseTag = "$pkgId_$pkgVersion"
Deployable = $forceCreate -or !(IsMavenPackageVersionPublished -pkgId $pkgId -pkgVersion $pkgVersion -groupId $groupId.Replace(".", "/"))
ReleaseNotes = $releaseNotes
ReadmeContent = $readmeContent
Expand Down Expand Up @@ -150,6 +151,7 @@ function ParseNPMPackage($pkg, $workingDirectory) {
$resultObj = New-Object PSObject -Property @{
PackageId = $pkgId
PackageVersion = $pkgVersion
ReleaseTag = "$pkgId_$pkgVersion"
Deployable = $forceCreate -or !(IsNPMPackageVersionPublished -pkgId $pkgId -pkgVersion $pkgVersion)
ReleaseNotes = $releaseNotes
ReadmeContent = $readmeContent
Expand Down Expand Up @@ -208,6 +210,7 @@ function ParseNugetPackage($pkg, $workingDirectory) {
return New-Object PSObject -Property @{
PackageId = $pkgId
PackageVersion = $pkgVersion
ReleaseTag = "$pkgId_$pkgVersion"
Deployable = $forceCreate -or !(IsNugetPackageVersionPublished -pkgId $pkgId -pkgVersion $pkgVersion)
ReleaseNotes = $releaseNotes
ReadmeContent = $readmeContent
Expand Down Expand Up @@ -272,6 +275,7 @@ function ParsePyPIPackage($pkg, $workingDirectory) {
return New-Object PSObject -Property @{
PackageId = $pkgId
PackageVersion = $pkgVersion
ReleaseTag = "$pkgId_$pkgVersion"
Deployable = $forceCreate -or !(IsPythonPackageVersionPublished -pkgId $pkgId -pkgVersion $pkgVersion)
ReleaseNotes = $releaseNotes
ReadmeContent = $readmeContent
Expand Down Expand Up @@ -300,6 +304,7 @@ function ParseCArtifact($pkg, $workingDirectory) {
return New-Object PSObject -Property @{
PackageId = ''
PackageVersion = $pkgVersion
ReleaseTag = $pkgVersion
# Artifact info is always considered deployable for C becasue it is not
# deployed anywhere. Dealing with duplicate tags happens downstream in
# CheckArtifactShaAgainstTagsList
Expand Down Expand Up @@ -331,6 +336,7 @@ function ParseCppArtifact($pkg, $workingDirectory) {
return New-Object PSObject -Property @{
PackageId = $pkgName
PackageVersion = $pkgVersion
ReleaseTag = "$pkgId_$pkgVersion"
# Artifact info is always considered deployable for now becasue it is not
# deployed anywhere. Dealing with duplicate tags happens downstream in
# CheckArtifactShaAgainstTagsList
Expand Down Expand Up @@ -387,12 +393,30 @@ function GetExistingTags($apiUrl) {
}
}

# Walk across all build artifacts, check them against the appropriate repository, return a list of tags/releases
function VerifyPackages($pkgRepository, $artifactLocation, $workingDirectory, $apiUrl, $releaseSha, $continueOnError = $false) {
$pkgList = [array]@()
# Retrieve release tag for artiface package. If multiple packages, then output the first one.
function RetrieveReleaseTag($pkgRepository, $artifactLocation, $continueOnError = $true) {
if (!$artifactLocation) {
return ""
}
try {
$pkgs, $ParsePkgInfoFn = RetrivePackages -pkgRepository $pkgRepository -artifactLocation $artifactLocation
if (!$pkgs -or !$pkgs[0]) {
return ""
}
$parsedPackage = &$ParsePkgInfoFn -pkg $pkgs[0]
return $parsedPackage.ReleaseTag
}
catch {
if ($continueOnError) {
return ""
}
Write-Error "No release tag retrieved from $artifactLocation"
}
}
function RetrivePackages($pkgRepository, $artifactLocation) {
$ParsePkgInfoFn = ""
$packagePattern = ""

$pkgRepository = $pkgRepository.Trim()
switch ($pkgRepository) {
"Maven" {
$ParsePkgInfoFn = "ParseMavenPackage"
Expand Down Expand Up @@ -427,8 +451,14 @@ function VerifyPackages($pkgRepository, $artifactLocation, $workingDirectory, $a
exit(1)
}
}
$pkgs = Get-ChildItem -Path $artifactLocation -Include $packagePattern -Recurse -File
return $pkgs, $ParsePkgInfoFn
}

$pkgs = (Get-ChildItem -Path $artifactLocation -Include $packagePattern -Recurse -File)
# Walk across all build artifacts, check them against the appropriate repository, return a list of tags/releases
function VerifyPackages($pkgRepository, $artifactLocation, $workingDirectory, $apiUrl, $releaseSha, $continueOnError = $false) {
$pkgList = [array]@()
$pkgs, $ParsePkgInfoFn = RetrivePackages -pkgRepository $pkgRepository -artifactLocation $artifactLocation

foreach ($pkg in $pkgs) {
try {
Expand All @@ -444,17 +474,11 @@ 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
GroupId = $parsedPackage.GroupId
Tag = $tag
Tag = $parsedPackage.ReleaseTag
ReleaseNotes = $parsedPackage.ReleaseNotes
ReadmeContent = $parsedPackage.ReadmeContent
IsPrerelease = [AzureEngSemanticVersion]::ParseVersionString($parsedPackage.PackageVersion).IsPrerelease
Expand Down
49 changes: 37 additions & 12 deletions eng/common/scripts/copy-docs-to-blobstorage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ param (
$Language,
$BlobName,
$ExitOnError=1,
$UploadLatest=1
$UploadLatest=1,
$PublicArtifactLocation = "",
$RepoReplaceRegex = "(https://github.com/.*/(?:blob|tree)/)master(/.*)"
)

. (Join-Path $PSScriptRoot artifact-metadata-parsing.ps1)

$Language = $Language.ToLower()

# Regex inspired but simplified from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
Expand Down Expand Up @@ -186,7 +190,8 @@ function Upload-Blobs
Param (
[Parameter(Mandatory=$true)] [String]$DocDir,
[Parameter(Mandatory=$true)] [String]$PkgName,
[Parameter(Mandatory=$true)] [String]$DocVersion
[Parameter(Mandatory=$true)] [String]$DocVersion,
[Parameter(Mandatory=$false)] [String]$ReleaseTag
)
#eg : $BlobName = "https://azuresdkdocs.blob.core.windows.net"
$DocDest = "$($BlobName)/`$web/$($Language)"
Expand All @@ -196,7 +201,24 @@ function Upload-Blobs
Write-Host "DocVersion $($DocVersion)"
Write-Host "DocDir $($DocDir)"
Write-Host "Final Dest $($DocDest)/$($PkgName)/$($DocVersion)"
Write-Host "Release Tag $($ReleaseTag)"

# Use the step to replace master link to release tag link
if ($ReleaseTag) {
foreach ($htmlFile in (Get-ChildItem $DocDir -include *.html -r))
{
$fileContent = Get-Content -Path $htmlFile
$checkPattern = $false
while ($fileContent -match $RepoReplaceRegex) {
$fileContent = $fileContent -replace $RepoReplaceRegex, "`${1}$ReleaseTag`$2"
$checkPattern = $true
}
if ($checkPattern) {
Set-Content -Path $htmlFile -Value $fileContent
}
}
}

Write-Host "Uploading $($PkgName)/$($DocVersion) to $($DocDest)..."
& $($AzCopy) cp "$($DocDir)/**" "$($DocDest)/$($PkgName)/$($DocVersion)$($SASKey)" --recursive=true

Expand All @@ -213,7 +235,6 @@ function Upload-Blobs
}
}


if ($Language -eq "javascript")
{
$PublishedDocs = Get-ChildItem "$($DocLocation)/documentation" | Where-Object -FilterScript {$_.Name.EndsWith(".zip")}
Expand All @@ -227,7 +248,8 @@ if ($Language -eq "javascript")
if($dirList.Length -eq 1){
$DocVersion = $dirList[0].Name
Write-Host "Uploading Doc for $($PkgName) Version:- $($DocVersion)..."
Upload-Blobs -DocDir "$($DocLocation)/documentation/$($Item.BaseName)/$($Item.BaseName)/$($DocVersion)" -PkgName $PkgName -DocVersion $DocVersion
$releaseTag = RetrieveReleaseTag "NPM" $PublicArtifactLocation
Upload-Blobs -DocDir "$($DocLocation)/documentation/$($Item.BaseName)/$($Item.BaseName)/$($DocVersion)" -PkgName $PkgName -DocVersion $DocVersion -ReleaseTag $releaseTag
}
else{
Write-Host "found more than 1 folder under the documentation for package - $($Item.Name)"
Expand All @@ -252,7 +274,8 @@ if ($Language -eq "dotnet")
Write-Host "DocDir $($Item)"
Write-Host "PkgName $($PkgName)"
Write-Host "DocVersion $($DocVersion)"
Upload-Blobs -DocDir "$($Item)" -PkgName $PkgName -DocVersion $DocVersion
$releaseTag = RetrieveReleaseTag "Nuget" $PublicArtifactLocation
Upload-Blobs -DocDir "$($Item)" -PkgName $PkgName -DocVersion $DocVersion -ReleaseTag $releaseTag
}
else
{
Expand All @@ -279,8 +302,8 @@ if ($Language -eq "python")
Write-Host "Discovered Package Name: $PkgName"
Write-Host "Discovered Package Version: $Version"
Write-Host "Directory for Upload: $UnzippedDocumentationPath"

Upload-Blobs -DocDir $UnzippedDocumentationPath -PkgName $PkgName -DocVersion $Version
$releaseTag = RetrieveReleaseTag "PyPI" $PublicArtifactLocation
Upload-Blobs -DocDir $UnzippedDocumentationPath -PkgName $PkgName -DocVersion $Version -ReleaseTag $releaseTag
}
}

Expand Down Expand Up @@ -326,8 +349,8 @@ if ($Language -eq "java")
Write-Host "DocDir $($UnjarredDocumentationPath)"
Write-Host "PkgName $($ArtifactId)"
Write-Host "DocVersion $($Version)"

Upload-Blobs -DocDir $UnjarredDocumentationPath -PkgName $ArtifactId -DocVersion $Version
$releaseTag = RetrieveReleaseTag "Maven" $PublicArtifactLocation
Upload-Blobs -DocDir $UnjarredDocumentationPath -PkgName $ArtifactId -DocVersion $Version -ReleaseTag $releaseTag

} Finally {
if (![string]::IsNullOrEmpty($UnjarredDocumentationPath)) {
Expand All @@ -349,11 +372,13 @@ if ($Language -eq "c")
# 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
Upload-Blobs -DocDir $DocLocation -PkgName 'docs' -DocVersion $pkgInfo.version
$releaseTag = RetrieveReleaseTag "C" $PublicArtifactLocation
Upload-Blobs -DocDir $DocLocation -PkgName 'docs' -DocVersion $pkgInfo.version -ReleaseTag $releaseTag
}

if ($Language -eq "cpp")
{
$packageInfo = (Get-Content (Join-Path $DocLocation 'package-info.json') | ConvertFrom-Json)
Upload-Blobs -DocDir $DocLocation -PkgName $packageInfo.name -DocVersion $packageInfo.version
}
$releaseTag = RetrieveReleaseTag "CPP" $PublicArtifactLocation
Upload-Blobs -DocDir $DocLocation -PkgName $packageInfo.name -DocVersion $packageInfo.version -ReleaseTag $releaseTag
}
6 changes: 6 additions & 0 deletions eng/common/scripts/update-docs-metadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ param (
. (Join-Path $PSScriptRoot artifact-metadata-parsing.ps1)
. (Join-Path $PSScriptRoot SemVer.ps1)

$releaseReplaceRegex = "(https://github.com/$RepoId/(?:blob|tree)/)master(/.*)"

function GetMetaData($lang){
switch ($lang) {
"java" {
Expand Down Expand Up @@ -75,6 +77,10 @@ function GetAdjustedReadmeContent($pkgInfo, $lang){
if ($headerContentMatches) {
$foundTitle = $headerContentMatches.Matches[0]
$fileContent = $pkgInfo.ReadmeContent -replace $foundTitle, "$foundTitle - Version $($pkgInfo.PackageVersion) `n"

# Replace github master link with release tag.
$ReplacementPattern = "`${1}$($pkgInfo.Tag)`$2"
$fileContent = $fileContent -replace $releaseReplaceRegex, $ReplacementPattern
}

$header = "---`ntitle: $foundTitle`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"
Expand Down

0 comments on commit 0ff5be8

Please sign in to comment.