diff --git a/eng/common/pipelines/templates/steps/publish-blobs.yml b/eng/common/pipelines/templates/steps/publish-blobs.yml index 682cc4d4f7c8..72f5fef1ab0b 100644 --- a/eng/common/pipelines/templates/steps/publish-blobs.yml +++ b/eng/common/pipelines/templates/steps/publish-blobs.yml @@ -4,6 +4,8 @@ parameters: TargetLanguage: '' BlobName: '' ScriptPath: '' + RepoId: '' + ReleaseTag: '' steps: - pwsh: | @@ -21,6 +23,8 @@ steps: -SASKey "${{ parameters.BlobSASKey }}" -Language "${{ parameters.TargetLanguage }}" -BlobName "${{ parameters.BlobName }}" + -RepoReplaceRegex "(https://github.com/${{ parameters.RepoId }}/(?:blob|tree)/)master(/.*)" + -Tag: "${{ parameters.ReleaseTag }}" pwsh: true workingDirectory: $(Pipeline.Workspace) displayName: Copy Docs to Blob diff --git a/eng/common/scripts/Submit-PullRequest.ps1 b/eng/common/scripts/Submit-PullRequest.ps1 index d0e245004a96..68a4db9c2732 100644 --- a/eng/common/scripts/Submit-PullRequest.ps1 +++ b/eng/common/scripts/Submit-PullRequest.ps1 @@ -42,7 +42,6 @@ param( [Parameter(Mandatory = $true)] [string]$PRTitle, - $PRBody = $PRTitle, [Parameter(Mandatory = $false)] diff --git a/eng/common/scripts/artifact-metadata-parsing.ps1 b/eng/common/scripts/artifact-metadata-parsing.ps1 index f17e59700b69..a6d21e170a43 100644 --- a/eng/common/scripts/artifact-metadata-parsing.ps1 +++ b/eng/common/scripts/artifact-metadata-parsing.ps1 @@ -7,7 +7,7 @@ $SDIST_PACKAGE_REGEX = "^(?.*)\-(?$([AzureEngSemanticVer function CreateReleases($pkgList, $releaseApiUrl, $releaseSha) { foreach ($pkgInfo in $pkgList) { Write-Host "Creating release $($pkgInfo.Tag)" - + echo "##vso[task.setvariable variable=ReleaseTag;isOutput=true]$($pkgInfo.Tag)" $releaseNotes = "" if ($pkgInfo.ReleaseNotes -ne $null) { $releaseNotes = $pkgInfo.ReleaseNotes @@ -502,7 +502,7 @@ function CheckArtifactShaAgainstTagsList($priorExistingTagList, $releaseSha, $ap else { Write-Host "The artifact SHA $releaseSha does not match that of the currently existing tag." Write-Host "Tag with issues is $tag with commit SHA $tagSha" - + echo "##vso[task.setvariable variable=ReleaseTag;isOutput=true]$tag" $unmatchedTags += $tag } } diff --git a/eng/common/scripts/copy-docs-to-blobstorage.ps1 b/eng/common/scripts/copy-docs-to-blobstorage.ps1 index a0893099293a..da53e33bc562 100644 --- a/eng/common/scripts/copy-docs-to-blobstorage.ps1 +++ b/eng/common/scripts/copy-docs-to-blobstorage.ps1 @@ -7,7 +7,9 @@ param ( $Language, $BlobName, $ExitOnError=1, - $UploadLatest=1 + $UploadLatest=1, + $RepoReplaceRegex, + $Tag ) $Language = $Language.ToLower() @@ -197,6 +199,10 @@ function Upload-Blobs Write-Host "DocDir $($DocDir)" Write-Host "Final Dest $($DocDest)/$($PkgName)/$($DocVersion)" + # Use the step to replace master link to release tag link + Write-Host "Replacing all readme master links with release tag $Tag" + ReplaceLink -scanFolder $DocDir -fileSuffix ".html" -replacement $Tag -customRegex $RepoReplaceRegex + Write-Host "Uploading $($PkgName)/$($DocVersion) to $($DocDest)..." & $($AzCopy) cp "$($DocDir)/**" "$($DocDest)/$($PkgName)/$($DocVersion)$($SASKey)" --recursive=true diff --git a/eng/common/scripts/link-replacement.ps1 b/eng/common/scripts/link-replacement.ps1 new file mode 100644 index 000000000000..2b93d38a3ffe --- /dev/null +++ b/eng/common/scripts/link-replacement.ps1 @@ -0,0 +1,54 @@ +param ( + # url list to verify links. Can either be a http address or a local file request. Local file paths support md and html files. + [string] $sourceDir, + # file that contains a set of links to ignore when verifying + [string] $ignoreLinksFile = "$PSScriptRoot/ignore-links.txt", + # switch that will enable devops specific logging for warnings + [switch] $devOpsLogging = $false, + [string] $branchReplaceRegex = "(https://github.com/.*/(?:blob|tree)/)master(/.*)", + # the substitute branch name or SHA commit + [string] $releaseTag = "" +) + +$regexOptions = [System.Text.RegularExpressions.RegexOptions]"Singleline, IgnoreCase"; + +function ReplaceLink ($scanFolder, $fileSuffix, $replacement, $customRegex) { + $regex = new-object System.Text.RegularExpressions.Regex ($branchReplaceRegex, $regexOptions) + if ($customRegex) { + $regex = new-object System.Text.RegularExpressions.Regex ($customRegex, $regexOptions) + } + if (!$fileSuffix) { + Write-Error "Please provide at least one file extension to scan against." + } + $replacementPattern = "`${2}$replacement`$3" + if (!$replacement) { + Write-Error "Please provide the replacement string to replace with." + } + if ($scanFolder) { + $fileSuffixArray = $fileSuffix -split "," + $url = @() + + foreach ($fileExtension in $fileSuffixArray) { + $fileRegex = "*" + $fileSuffix.Trim() + $urls += Get-ChildItem -Path "$scanFolder/*" -Recurse -Include $fileRegex + } + + if ($urls.Count -eq 0) { + Write-Host "Usage $($MyInvocation.MyCommand.Name) "; + return; + } + $needTochange = @{} + foreach ($url in $urls) { + while ((Get-Content -Path $url) -match $regex) { + Write-Verbose "We have master link matches in page $url" + $needTochange[$url] = $true + (Get-Content -Path $url) -replace $regex, $replacementPattern | Set-Content -Path $url + } + } + foreach ($page in $needTochange.Keys) { + Write-Host "There are replacements in page $page" + } + } +} + +#ReplaceLink -scanFolder $sourceDir -replacement $releaseTag -fileSuffix ".html" \ No newline at end of file diff --git a/eng/common/scripts/update-docs-metadata.ps1 b/eng/common/scripts/update-docs-metadata.ps1 index 42ca30894fd6..a490545adc5f 100644 --- a/eng/common/scripts/update-docs-metadata.ps1 +++ b/eng/common/scripts/update-docs-metadata.ps1 @@ -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" { @@ -75,6 +77,12 @@ 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. + $regex = new-object System.Text.RegularExpressions.Regex ($releaseReplaceRegex, + [System.Text.RegularExpressions.RegexOptions]"Singleline, IgnoreCase") + + $ReplacementPattern = "`${1}$($pkgInfo.Tag)`$2" + $fileContent = $fileContent -replace $regex, $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"