Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools repository for Tools PR
Browse files Browse the repository at this point in the history
  • Loading branch information
azure-sdk committed Aug 27, 2020
1 parent 80c7724 commit c42e70f
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 5 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: ''
RepoId: ''
ReleaseTag: ''

steps:
- pwsh: |
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion eng/common/scripts/Submit-PullRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ param(

[Parameter(Mandatory = $true)]
[string]$PRTitle,

$PRBody = $PRTitle,

[Parameter(Mandatory = $false)]
Expand Down
4 changes: 2 additions & 2 deletions eng/common/scripts/artifact-metadata-parsing.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ $SDIST_PACKAGE_REGEX = "^(?<package>.*)\-(?<versionstring>$([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
Expand Down Expand Up @@ -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
}
}
Expand Down
10 changes: 9 additions & 1 deletion eng/common/scripts/copy-docs-to-blobstorage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ param (
$Language,
$BlobName,
$ExitOnError=1,
$UploadLatest=1
$UploadLatest=1,
$RepoReplaceRegex,
$Tag
)

$Language = $Language.ToLower()
Expand Down Expand Up @@ -197,6 +199,12 @@ 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

Expand Down
55 changes: 55 additions & 0 deletions eng/common/scripts/link-replacement.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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-Host "Will scan the entire repo"
$fileSuffix = ""
}
$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) <urls>";
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"
10 changes: 9 additions & 1 deletion eng/common/scripts/update-docs-metadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ param (
# arguments necessary to power the docs release
$DocRepoLocation, # the location on disk where we have cloned the documentation repository
$Language, # EG: js, java, dotnet. Used in language for the embedded readme.
$DocRepoContentLocation = "docs-ref-services/" # within the doc repo, where does our readme go?
$DocRepoContentLocation = "docs-ref-services/", # within the doc repo, where does our readme go?
)

. (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,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"
Expand Down

0 comments on commit c42e70f

Please sign in to comment.