Skip to content

Commit addd8ae

Browse files
authored
Sync eng/common directory with azure-sdk-tools repository for Tools PR 926 (#14610)
1 parent 1e995f0 commit addd8ae

File tree

4 files changed

+98
-33
lines changed

4 files changed

+98
-33
lines changed

eng/common/pipelines/templates/steps/publish-blobs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ parameters:
44
TargetLanguage: ''
55
BlobName: ''
66
ScriptPath: ''
7+
ArtifactLocation: ''
8+
RepoId: $(Build.Repository.Name)
79

810
steps:
911
- pwsh: |
@@ -21,6 +23,8 @@ steps:
2123
-SASKey "${{ parameters.BlobSASKey }}"
2224
-Language "${{ parameters.TargetLanguage }}"
2325
-BlobName "${{ parameters.BlobName }}"
26+
-PublicArtifactLocation "${{ parameters.ArtifactLocation }}"
27+
-RepoReplaceRegex "(https://github.com/${{ parameters.RepoId }}/(?:blob|tree)/)master"
2428
pwsh: true
2529
workingDirectory: $(Pipeline.Workspace)
2630
displayName: Copy Docs to Blob

eng/common/scripts/artifact-metadata-parsing.ps1

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ function ParseMavenPackage($pkg, $workingDirectory) {
6969
PackageId = $pkgId
7070
GroupId = $groupId
7171
PackageVersion = $pkgVersion
72+
ReleaseTag = "$($pkgId)_$($pkgVersion)"
7273
Deployable = $forceCreate -or !(IsMavenPackageVersionPublished -pkgId $pkgId -pkgVersion $pkgVersion -groupId $groupId.Replace(".", "/"))
7374
ReleaseNotes = $releaseNotes
7475
ReadmeContent = $readmeContent
@@ -150,6 +151,7 @@ function ParseNPMPackage($pkg, $workingDirectory) {
150151
$resultObj = New-Object PSObject -Property @{
151152
PackageId = $pkgId
152153
PackageVersion = $pkgVersion
154+
ReleaseTag = "$($pkgId)_$($pkgVersion)"
153155
Deployable = $forceCreate -or !(IsNPMPackageVersionPublished -pkgId $pkgId -pkgVersion $pkgVersion)
154156
ReleaseNotes = $releaseNotes
155157
ReadmeContent = $readmeContent
@@ -208,6 +210,7 @@ function ParseNugetPackage($pkg, $workingDirectory) {
208210
return New-Object PSObject -Property @{
209211
PackageId = $pkgId
210212
PackageVersion = $pkgVersion
213+
ReleaseTag = "$($pkgId)_$($pkgVersion)"
211214
Deployable = $forceCreate -or !(IsNugetPackageVersionPublished -pkgId $pkgId -pkgVersion $pkgVersion)
212215
ReleaseNotes = $releaseNotes
213216
ReadmeContent = $readmeContent
@@ -272,6 +275,7 @@ function ParsePyPIPackage($pkg, $workingDirectory) {
272275
return New-Object PSObject -Property @{
273276
PackageId = $pkgId
274277
PackageVersion = $pkgVersion
278+
ReleaseTag = "$($pkgId)_$($pkgVersion)"
275279
Deployable = $forceCreate -or !(IsPythonPackageVersionPublished -pkgId $pkgId -pkgVersion $pkgVersion)
276280
ReleaseNotes = $releaseNotes
277281
ReadmeContent = $readmeContent
@@ -300,6 +304,7 @@ function ParseCArtifact($pkg, $workingDirectory) {
300304
return New-Object PSObject -Property @{
301305
PackageId = ''
302306
PackageVersion = $pkgVersion
307+
ReleaseTag = $pkgVersion
303308
# Artifact info is always considered deployable for C becasue it is not
304309
# deployed anywhere. Dealing with duplicate tags happens downstream in
305310
# CheckArtifactShaAgainstTagsList
@@ -331,6 +336,7 @@ function ParseCppArtifact($pkg, $workingDirectory) {
331336
return New-Object PSObject -Property @{
332337
PackageId = $pkgName
333338
PackageVersion = $pkgVersion
339+
ReleaseTag = "$($pkgId)_$($pkgVersion)"
334340
# Artifact info is always considered deployable for now becasue it is not
335341
# deployed anywhere. Dealing with duplicate tags happens downstream in
336342
# CheckArtifactShaAgainstTagsList
@@ -387,52 +393,84 @@ function GetExistingTags($apiUrl) {
387393
}
388394
}
389395

390-
# Walk across all build artifacts, check them against the appropriate repository, return a list of tags/releases
391-
function VerifyPackages($pkgRepository, $artifactLocation, $workingDirectory, $apiUrl, $releaseSha, $continueOnError = $false) {
392-
$pkgList = [array]@()
393-
$ParsePkgInfoFn = ""
396+
# Retrieve release tag for artiface package. If multiple packages, then output the first one.
397+
function RetrieveReleaseTag($pkgRepository, $artifactLocation, $continueOnError = $true) {
398+
if (!$artifactLocation) {
399+
return ""
400+
}
401+
try {
402+
$pkgs, $parsePkgInfoFn = RetrievePackages -pkgRepository $pkgRepository -artifactLocation $artifactLocation
403+
if (!$pkgs -or !$pkgs[0]) {
404+
Write-Host "No packages retrieved from artifact location."
405+
return ""
406+
}
407+
if ($pkgs.Count -gt 1) {
408+
Write-Host "There are more than 1 packages retieved from artifact location."
409+
foreach ($pkg in $pkgs) {
410+
Write-Host "The package name is $($pkg.BaseName)"
411+
}
412+
return ""
413+
}
414+
$parsedPackage = &$parsePkgInfoFn -pkg $pkgs[0] -workingDirectory $artifactLocation
415+
return $parsedPackage.ReleaseTag
416+
}
417+
catch {
418+
if ($continueOnError) {
419+
return ""
420+
}
421+
Write-Error "No release tag retrieved from $artifactLocation"
422+
}
423+
}
424+
function RetrievePackages($pkgRepository, $artifactLocation) {
425+
$parsePkgInfoFn = ""
394426
$packagePattern = ""
395-
427+
$pkgRepository = $pkgRepository.Trim()
396428
switch ($pkgRepository) {
397429
"Maven" {
398-
$ParsePkgInfoFn = "ParseMavenPackage"
430+
$parsePkgInfoFn = "ParseMavenPackage"
399431
$packagePattern = "*.pom"
400432
break
401433
}
402434
"Nuget" {
403-
$ParsePkgInfoFn = "ParseNugetPackage"
435+
$parsePkgInfoFn = "ParseNugetPackage"
404436
$packagePattern = "*.nupkg"
405437
break
406438
}
407439
"NPM" {
408-
$ParsePkgInfoFn = "ParseNPMPackage"
440+
$parsePkgInfoFn = "ParseNPMPackage"
409441
$packagePattern = "*.tgz"
410442
break
411443
}
412444
"PyPI" {
413-
$ParsePkgInfoFn = "ParsePyPIPackage"
445+
$parsePkgInfoFn = "ParsePyPIPackage"
414446
$packagePattern = "*.zip"
415447
break
416448
}
417449
"C" {
418-
$ParsePkgInfoFn = "ParseCArtifact"
450+
$parsePkgInfoFn = "ParseCArtifact"
419451
$packagePattern = "*.json"
420452
}
421453
"CPP" {
422-
$ParsePkgInfoFn = "ParseCppArtifact"
454+
$parsePkgInfoFn = "ParseCppArtifact"
423455
$packagePattern = "*.json"
424456
}
425457
default {
426458
Write-Host "Unrecognized Language: $language"
427459
exit(1)
428460
}
429461
}
462+
$pkgs = Get-ChildItem -Path $artifactLocation -Include $packagePattern -Recurse -File
463+
return $pkgs, $parsePkgInfoFn
464+
}
430465

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

433471
foreach ($pkg in $pkgs) {
434472
try {
435-
$parsedPackage = &$ParsePkgInfoFn -pkg $pkg -workingDirectory $workingDirectory
473+
$parsedPackage = &$parsePkgInfoFn -pkg $pkg -workingDirectory $workingDirectory
436474

437475
if ($parsedPackage -eq $null) {
438476
continue
@@ -444,17 +482,11 @@ function VerifyPackages($pkgRepository, $artifactLocation, $workingDirectory, $a
444482
exit(1)
445483
}
446484

447-
$tag = if ($parsedPackage.packageId) {
448-
"$($parsedPackage.packageId)_$($parsedPackage.PackageVersion)"
449-
} else {
450-
$parsedPackage.PackageVersion
451-
}
452-
453485
$pkgList += New-Object PSObject -Property @{
454486
PackageId = $parsedPackage.PackageId
455487
PackageVersion = $parsedPackage.PackageVersion
456488
GroupId = $parsedPackage.GroupId
457-
Tag = $tag
489+
Tag = $parsedPackage.ReleaseTag
458490
ReleaseNotes = $parsedPackage.ReleaseNotes
459491
ReadmeContent = $parsedPackage.ReadmeContent
460492
IsPrerelease = [AzureEngSemanticVersion]::ParseVersionString($parsedPackage.PackageVersion).IsPrerelease
@@ -511,4 +543,4 @@ function CheckArtifactShaAgainstTagsList($priorExistingTagList, $releaseSha, $ap
511543
Write-Host "Tags already existing with different SHA versions. Exiting."
512544
exit(1)
513545
}
514-
}
546+
}

eng/common/scripts/copy-docs-to-blobstorage.ps1

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ param (
77
$Language,
88
$BlobName,
99
$ExitOnError=1,
10-
$UploadLatest=1
10+
$UploadLatest=1,
11+
$PublicArtifactLocation = "",
12+
$RepoReplaceRegex = "(https://github.com/.*/(?:blob|tree)/)master"
1113
)
14+
. (Join-Path $PSScriptRoot artifact-metadata-parsing.ps1)
1215

1316
$Language = $Language.ToLower()
1417

@@ -186,7 +189,8 @@ function Upload-Blobs
186189
Param (
187190
[Parameter(Mandatory=$true)] [String]$DocDir,
188191
[Parameter(Mandatory=$true)] [String]$PkgName,
189-
[Parameter(Mandatory=$true)] [String]$DocVersion
192+
[Parameter(Mandatory=$true)] [String]$DocVersion,
193+
[Parameter(Mandatory=$false)] [String]$ReleaseTag
190194
)
191195
#eg : $BlobName = "https://azuresdkdocs.blob.core.windows.net"
192196
$DocDest = "$($BlobName)/`$web/$($Language)"
@@ -196,7 +200,23 @@ function Upload-Blobs
196200
Write-Host "DocVersion $($DocVersion)"
197201
Write-Host "DocDir $($DocDir)"
198202
Write-Host "Final Dest $($DocDest)/$($PkgName)/$($DocVersion)"
203+
Write-Host "Release Tag $($ReleaseTag)"
199204

205+
# Use the step to replace master link to release tag link
206+
if ($ReleaseTag) {
207+
foreach ($htmlFile in (Get-ChildItem $DocDir -include *.html -r))
208+
{
209+
$fileContent = Get-Content -Path $htmlFile
210+
$updatedFileContent = $fileContent -replace $RepoReplaceRegex, "`${1}$ReleaseTag"
211+
if ($updatedFileContent -ne $fileContent) {
212+
Set-Content -Path $htmlFile -Value $updatedFileContent
213+
}
214+
}
215+
}
216+
else {
217+
Write-Warning "Not able to do the master link replacement, since no release tag found for the release. Please manually check."
218+
}
219+
200220
Write-Host "Uploading $($PkgName)/$($DocVersion) to $($DocDest)..."
201221
& $($AzCopy) cp "$($DocDir)/**" "$($DocDest)/$($PkgName)/$($DocVersion)$($SASKey)" --recursive=true
202222

@@ -213,7 +233,6 @@ function Upload-Blobs
213233
}
214234
}
215235

216-
217236
if ($Language -eq "javascript")
218237
{
219238
$PublishedDocs = Get-ChildItem "$($DocLocation)/documentation" | Where-Object -FilterScript {$_.Name.EndsWith(".zip")}
@@ -227,7 +246,8 @@ if ($Language -eq "javascript")
227246
if($dirList.Length -eq 1){
228247
$DocVersion = $dirList[0].Name
229248
Write-Host "Uploading Doc for $($PkgName) Version:- $($DocVersion)..."
230-
Upload-Blobs -DocDir "$($DocLocation)/documentation/$($Item.BaseName)/$($Item.BaseName)/$($DocVersion)" -PkgName $PkgName -DocVersion $DocVersion
249+
$releaseTag = RetrieveReleaseTag "NPM" $PublicArtifactLocation
250+
Upload-Blobs -DocDir "$($DocLocation)/documentation/$($Item.BaseName)/$($Item.BaseName)/$($DocVersion)" -PkgName $PkgName -DocVersion $DocVersion -ReleaseTag $releaseTag
231251
}
232252
else{
233253
Write-Host "found more than 1 folder under the documentation for package - $($Item.Name)"
@@ -252,7 +272,8 @@ if ($Language -eq "dotnet")
252272
Write-Host "DocDir $($Item)"
253273
Write-Host "PkgName $($PkgName)"
254274
Write-Host "DocVersion $($DocVersion)"
255-
Upload-Blobs -DocDir "$($Item)" -PkgName $PkgName -DocVersion $DocVersion
275+
$releaseTag = RetrieveReleaseTag "Nuget" $PublicArtifactLocation
276+
Upload-Blobs -DocDir "$($Item)" -PkgName $PkgName -DocVersion $DocVersion -ReleaseTag $releaseTag
256277
}
257278
else
258279
{
@@ -279,8 +300,8 @@ if ($Language -eq "python")
279300
Write-Host "Discovered Package Name: $PkgName"
280301
Write-Host "Discovered Package Version: $Version"
281302
Write-Host "Directory for Upload: $UnzippedDocumentationPath"
282-
283-
Upload-Blobs -DocDir $UnzippedDocumentationPath -PkgName $PkgName -DocVersion $Version
303+
$releaseTag = RetrieveReleaseTag "PyPI" $PublicArtifactLocation
304+
Upload-Blobs -DocDir $UnzippedDocumentationPath -PkgName $PkgName -DocVersion $Version -ReleaseTag $releaseTag
284305
}
285306
}
286307

@@ -326,8 +347,8 @@ if ($Language -eq "java")
326347
Write-Host "DocDir $($UnjarredDocumentationPath)"
327348
Write-Host "PkgName $($ArtifactId)"
328349
Write-Host "DocVersion $($Version)"
329-
330-
Upload-Blobs -DocDir $UnjarredDocumentationPath -PkgName $ArtifactId -DocVersion $Version
350+
$releaseTag = RetrieveReleaseTag "Maven" $PublicArtifactLocation
351+
Upload-Blobs -DocDir $UnjarredDocumentationPath -PkgName $ArtifactId -DocVersion $Version -ReleaseTag $releaseTag
331352

332353
} Finally {
333354
if (![string]::IsNullOrEmpty($UnjarredDocumentationPath)) {
@@ -349,11 +370,13 @@ if ($Language -eq "c")
349370
# Those loops are left over from previous versions of this script which were
350371
# used to publish multiple docs packages in a single invocation.
351372
$pkgInfo = Get-Content $DocLocation/package-info.json | ConvertFrom-Json
352-
Upload-Blobs -DocDir $DocLocation -PkgName 'docs' -DocVersion $pkgInfo.version
373+
$releaseTag = RetrieveReleaseTag "C" $PublicArtifactLocation
374+
Upload-Blobs -DocDir $DocLocation -PkgName 'docs' -DocVersion $pkgInfo.version -ReleaseTag $releaseTag
353375
}
354376

355377
if ($Language -eq "cpp")
356378
{
357379
$packageInfo = (Get-Content (Join-Path $DocLocation 'package-info.json') | ConvertFrom-Json)
358-
Upload-Blobs -DocDir $DocLocation -PkgName $packageInfo.name -DocVersion $packageInfo.version
359-
}
380+
$releaseTag = RetrieveReleaseTag "CPP" $PublicArtifactLocation
381+
Upload-Blobs -DocDir $DocLocation -PkgName $packageInfo.name -DocVersion $packageInfo.version -ReleaseTag $releaseTag
382+
}

eng/common/scripts/update-docs-metadata.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ param (
1717
. (Join-Path $PSScriptRoot artifact-metadata-parsing.ps1)
1818
. (Join-Path $PSScriptRoot SemVer.ps1)
1919

20+
$releaseReplaceRegex = "(https://github.com/$RepoId/(?:blob|tree)/)master"
21+
2022
function GetMetaData($lang){
2123
switch ($lang) {
2224
"java" {
@@ -75,6 +77,10 @@ function GetAdjustedReadmeContent($pkgInfo, $lang){
7577
if ($headerContentMatches) {
7678
$foundTitle = $headerContentMatches.Matches[0]
7779
$fileContent = $pkgInfo.ReadmeContent -replace $foundTitle, "$foundTitle - Version $($pkgInfo.PackageVersion) `n"
80+
81+
# Replace github master link with release tag.
82+
$ReplacementPattern = "`${1}$($pkgInfo.Tag)"
83+
$fileContent = $fileContent -replace $releaseReplaceRegex, $ReplacementPattern
7884
}
7985

8086
$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"

0 commit comments

Comments
 (0)