From 753df0f30f5a64e9f7464de26dd25653fdb165dd Mon Sep 17 00:00:00 2001 From: azure-sdk Date: Wed, 20 Jan 2021 22:29:57 +0000 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools repository --- .../templates/steps/bypass-local-dns.yml | 7 +- .../templates/steps/verify-agent-os.yml | 2 +- eng/common/scripts/Delete-RemoteTag.ps1 | 33 ++++ eng/common/scripts/Generate-DocIndex.ps1 | 150 ------------------ 4 files changed, 40 insertions(+), 152 deletions(-) create mode 100644 eng/common/scripts/Delete-RemoteTag.ps1 delete mode 100644 eng/common/scripts/Generate-DocIndex.ps1 diff --git a/eng/common/pipelines/templates/steps/bypass-local-dns.yml b/eng/common/pipelines/templates/steps/bypass-local-dns.yml index 54f49c33714b..91b5c4978303 100644 --- a/eng/common/pipelines/templates/steps/bypass-local-dns.yml +++ b/eng/common/pipelines/templates/steps/bypass-local-dns.yml @@ -3,4 +3,9 @@ steps: # https://github.com/actions/virtual-environments/issues/798 - script: sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf displayName: Bypass local DNS server to workaround issue resolving cognitiveservices names - condition: and(succeededOrFailed(), eq(variables['OSVmImage'], 'ubuntu-18.04')) \ No newline at end of file + condition: | + and( + succeededOrFailed(), + eq(variables['OSVmImage'], 'ubuntu-18.04'), + eq(variables['Container'], '') + ) diff --git a/eng/common/pipelines/templates/steps/verify-agent-os.yml b/eng/common/pipelines/templates/steps/verify-agent-os.yml index 4551279e13c0..12eaa0d3e1e1 100644 --- a/eng/common/pipelines/templates/steps/verify-agent-os.yml +++ b/eng/common/pipelines/templates/steps/verify-agent-os.yml @@ -1,4 +1,4 @@ -parameters: +parameters: OSVmImage: $(OSVmImage) steps: diff --git a/eng/common/scripts/Delete-RemoteTag.ps1 b/eng/common/scripts/Delete-RemoteTag.ps1 new file mode 100644 index 000000000000..a3157c7ab4c9 --- /dev/null +++ b/eng/common/scripts/Delete-RemoteTag.ps1 @@ -0,0 +1,33 @@ +param( + $Repository, + $Tag, + $AuthToken +) + +. (Join-Path $PSScriptRoot common.ps1) + +$repositoryParts = $Repository.Split("/") + +if ($repositoryParts.Length -ne 2) +{ + LogError "Repository is not a valid format." +} + +$repositoryOwner = $repositoryParts[0] +LogDebug "Repository owner is: $repositoryOwner" + +$repositoryName = $repositoryParts[1] +LogDebug "Reposiory name is: $repositoryName" + +$ref = "tags/$Tag" +LogDebug "Calculated ref is: $ref" + +try +{ + Remove-GitHubSourceReferences -RepoOwner $repositoryOwner -RepoName $repositoryName -Ref $ref -AuthToken $AuthToken +} +catch +{ + LogError "Remove-GitHubSourceReferences failed with exception:`n$_" + exit 1 +} \ No newline at end of file diff --git a/eng/common/scripts/Generate-DocIndex.ps1 b/eng/common/scripts/Generate-DocIndex.ps1 deleted file mode 100644 index 62196249b24f..000000000000 --- a/eng/common/scripts/Generate-DocIndex.ps1 +++ /dev/null @@ -1,150 +0,0 @@ -# Generates an index page for cataloging different versions of the Docs -[CmdletBinding()] -Param ( - $DocFx, - $RepoRoot, - $DocGenDir -) -. (Join-Path $PSScriptRoot common.ps1) -$GetGithubIoDocIndexFn = "Get-${Language}-GithubIoDocIndex" - -# Given the metadata url under https://github.com/Azure/azure-sdk/tree/master/_data/releases/latest, -# the function will return the csv metadata back as part of response. -function Get-CSVMetadata ([string]$MetadataUri) { - $metadataResponse = Invoke-RestMethod -Uri $MetadataUri -method "GET" -MaximumRetryCount 3 -RetryIntervalSec 10 | ConvertFrom-Csv - return $metadataResponse -} - -# Given the github io blob storage url and language regex, -# the helper function will return a list of artifact names. -function Get-BlobStorage-Artifacts($blobStorageUrl, $blobDirectoryRegex, $blobArtifactsReplacement) { - LogDebug "Reading artifact from storage blob ..." - $returnedArtifacts = @() - $pageToken = "" - Do { - $resp = "" - if (!$pageToken) { - # First page call. - $resp = Invoke-RestMethod -Method Get -Uri $blobStorageUrl - } - else { - # Next page call - $blobStorageUrlPageToken = $blobStorageUrl + "&marker=$pageToken" - $resp = Invoke-RestMethod -Method Get -Uri $blobStorageUrlPageToken - } - # Convert to xml documents. - $xmlDoc = [xml](removeBomFromString $resp) - foreach ($elem in $xmlDoc.EnumerationResults.Blobs.BlobPrefix) { - # What service return like "dotnet/Azure.AI.Anomalydetector/", needs to fetch out "Azure.AI.Anomalydetector" - $artifact = $elem.Name -replace $blobDirectoryRegex, $blobArtifactsReplacement - $returnedArtifacts += $artifact - } - # Fetch page token - $pageToken = $xmlDoc.EnumerationResults.NextMarker - } while ($pageToken) - return $returnedArtifacts - } - -# The sequence of Bom bytes differs by different encoding. -# The helper function here is only to strip the utf-8 encoding system as it is used by blob storage list api. -# Return the original string if not in BOM utf-8 sequence. -function RemoveBomFromString([string]$bomAwareString) { - if ($bomAwareString.length -le 3) { - return $bomAwareString - } - $bomPatternByteArray = [byte[]] (0xef, 0xbb, 0xbf) - # The default encoding for powershell is ISO-8859-1, so converting bytes with the encoding. - $bomAwareBytes = [Text.Encoding]::GetEncoding(28591).GetBytes($bomAwareString.Substring(0, 3)) - if (@(Compare-Object $bomPatternByteArray $bomAwareBytes -SyncWindow 0).Length -eq 0) { - return $bomAwareString.Substring(3) - } - return $bomAwareString -} - -function Get-TocMapping { - Param ( - [Parameter(Mandatory = $true)] [Object[]] $metadata, - [Parameter(Mandatory = $true)] [String[]] $artifacts - ) - # Used for sorting the toc display order - $orderServiceMapping = @{} - - foreach ($artifact in $artifacts) { - $packageInfo = $metadata | ? {$_.Package -eq $artifact} - - if ($packageInfo -and $packageInfo[0].Hide -eq 'true') { - LogDebug "The artifact $artifact set 'Hide' to 'true'." - continue - } - $serviceName = "" - if (!$packageInfo -or !$packageInfo[0].ServiceName) { - LogWarning "There is no service name for artifact $artifact. Please check csv of Azure/azure-sdk/_data/release/latest repo if this is intended. " - # If no service name retrieved, print out warning message, and put it into Other page. - $serviceName = "Other" - } - else { - if ($packageInfo.Length -gt 1) { - LogWarning "There are more than 1 packages fetched out for artifact $artifact. Please check csv of Azure/azure-sdk/_data/release/latest repo if this is intended. " - } - $serviceName = $packageInfo[0].ServiceName.Trim() - } - $orderServiceMapping[$artifact] = $serviceName - } - return $orderServiceMapping -} - -function GenerateDocfxTocContent([Hashtable]$tocContent, [String]$lang) { - LogDebug "Start generating the docfx toc and build docfx site..." - $DocOutDir = "${RepoRoot}/docfx_project" - - LogDebug "Initializing Default DocFx Site..." - & $($DocFx) init -q -o "${DocOutDir}" - # The line below is used for testing in local - # docfx init -q -o "${DocOutDir}" - LogDebug "Copying template and configuration..." - New-Item -Path "${DocOutDir}" -Name "templates" -ItemType "directory" -Force - Copy-Item "${DocGenDir}/templates/*" -Destination "${DocOutDir}/templates" -Force -Recurse - Copy-Item "${DocGenDir}/docfx.json" -Destination "${DocOutDir}/" -Force - $YmlPath = "${DocOutDir}/api" - New-Item -Path $YmlPath -Name "toc.yml" -Force - $visitedService = @{} - # Sort and display toc service name by alphabetical order. - foreach ($serviceMapping in $tocContent.getEnumerator() | Sort Value) { - $artifact = $serviceMapping.Key - $serviceName = $serviceMapping.Value - $fileName = ($serviceName -replace '\s', '').ToLower().Trim() - if ($visitedService.ContainsKey($serviceName)) { - Add-Content -Path "$($YmlPath)/${fileName}.md" -Value "#### $artifact" - } - else { - Add-Content -Path "$($YmlPath)/toc.yml" -Value "- name: ${serviceName}`r`n href: ${fileName}.md" - New-Item -Path $YmlPath -Name "${fileName}.md" -Force - Add-Content -Path "$($YmlPath)/${fileName}.md" -Value "#### $artifact" - $visitedService[$serviceName] = $true - } - } - - # Generate toc homepage. - LogDebug "Creating Site Title and Navigation..." - New-Item -Path "${DocOutDir}" -Name "toc.yml" -Force - Add-Content -Path "${DocOutDir}/toc.yml" -Value "- name: Azure SDK for $lang APIs`r`n href: api/`r`n homepage: api/index.md" - - LogDebug "Copying root markdowns" - Copy-Item "$($RepoRoot)/README.md" -Destination "${DocOutDir}/api/index.md" -Force - Copy-Item "$($RepoRoot)/CONTRIBUTING.md" -Destination "${DocOutDir}/api/CONTRIBUTING.md" -Force - - LogDebug "Building site..." - & $($DocFx) build "${DocOutDir}/docfx.json" - # The line below is used for testing in local - # docfx build "${DocOutDir}/docfx.json" - Copy-Item "${DocGenDir}/assets/logo.svg" -Destination "${DocOutDir}/_site/" -Force -} - -if ((Get-ChildItem -Path Function: | ? { $_.Name -eq $GetGithubIoDocIndexFn }).Count -gt 0) -{ - &$GetGithubIoDocIndexFn -} -else -{ - LogWarning "The function '$GetGithubIoDocIndexFn' was not found." -} \ No newline at end of file