Skip to content

Commit 85fe164

Browse files
Fix BOM issue Generate-DocIndex.ps1 (#34135)
Co-authored-by: Daniel Jurek <[email protected]>
1 parent b9e7829 commit 85fe164

File tree

2 files changed

+27
-44
lines changed

2 files changed

+27
-44
lines changed

eng/common/docgeneration/Generate-DocIndex.ps1

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,33 @@ Param (
1010
)
1111
. "${PSScriptRoot}\..\scripts\common.ps1"
1212

13-
# Given the github io blob storage url and language regex,
14-
# the helper function will return a list of artifact names.
15-
function Get-BlobStorage-Artifacts($blobStorageUrl, $blobDirectoryRegex, $blobArtifactsReplacement) {
13+
# Fetch a list of "artifacts" from blob storage corresponding to the given
14+
# language (-storagePrefix). Remove the prefix from the path names to arrive at
15+
# an "artifact" name.
16+
function Get-BlobStorage-Artifacts(
17+
$blobDirectoryRegex,
18+
$blobArtifactsReplacement,
19+
$storageAccountName,
20+
$storageContainerName,
21+
$storagePrefix
22+
) {
1623
LogDebug "Reading artifact from storage blob ..."
17-
$returnedArtifacts = @()
18-
$pageToken = ""
19-
Do {
20-
$resp = ""
21-
if (!$pageToken) {
22-
# First page call.
23-
$resp = Invoke-RestMethod -Method Get -Uri $blobStorageUrl
24-
}
25-
else {
26-
# Next page call
27-
$blobStorageUrlPageToken = $blobStorageUrl + "&marker=$pageToken"
28-
$resp = Invoke-RestMethod -Method Get -Uri $blobStorageUrlPageToken
29-
}
30-
# Convert to xml documents.
31-
$xmlDoc = [xml](removeBomFromString $resp)
32-
foreach ($elem in $xmlDoc.EnumerationResults.Blobs.BlobPrefix) {
33-
# What service return like "dotnet/Azure.AI.Anomalydetector/", needs to fetch out "Azure.AI.Anomalydetector"
34-
$artifact = $elem.Name -replace $blobDirectoryRegex, $blobArtifactsReplacement
35-
$returnedArtifacts += $artifact
36-
}
37-
# Fetch page token
38-
$pageToken = $xmlDoc.EnumerationResults.NextMarker
39-
} while ($pageToken)
40-
return $returnedArtifacts
41-
}
42-
43-
# The sequence of Bom bytes differs by different encoding.
44-
# The helper function here is only to strip the utf-8 encoding system as it is used by blob storage list api.
45-
# Return the original string if not in BOM utf-8 sequence.
46-
function RemoveBomFromString([string]$bomAwareString) {
47-
if ($bomAwareString.length -le 3) {
48-
return $bomAwareString
49-
}
50-
$bomPatternByteArray = [byte[]] (0xef, 0xbb, 0xbf)
51-
# The default encoding for powershell is ISO-8859-1, so converting bytes with the encoding.
52-
$bomAwareBytes = [Text.Encoding]::GetEncoding(28591).GetBytes($bomAwareString.Substring(0, 3))
53-
if (@(Compare-Object $bomPatternByteArray $bomAwareBytes -SyncWindow 0).Length -eq 0) {
54-
return $bomAwareString.Substring(3)
55-
}
56-
return $bomAwareString
24+
# "--only-show-errors" suppresses warnings about the fact that the az CLI is not authenticated
25+
# "--query '[].name'" returns a list of only blob names
26+
# "--num-results *" handles pagination so the caller does not have to
27+
$artifacts = az storage blob list `
28+
--account-name $storageAccountName `
29+
--container-name $storageContainerName `
30+
--prefix $storagePrefix `
31+
--delimiter / `
32+
--only-show-errors `
33+
--query '[].name' `
34+
--num-results * | ConvertFrom-Json
35+
LogDebug "Number of artifacts found: $($artifacts.Length)"
36+
37+
# example: "python/azure-storage-blob" -> "azure-storage-blob"
38+
$artifacts = $artifacts.ForEach({ $_ -replace $blobDirectoryRegex, $blobArtifactsReplacement })
39+
return $artifacts
5740
}
5841

5942
function Get-TocMapping {

eng/common/pipelines/templates/jobs/docindex.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
jobs:
22
- job: CreateDocIndex
33
pool:
4-
vmImage: windows-2022
4+
name: azsdk-pool-mms-win-2022-general
55
steps:
66
- task: UsePythonVersion@0
77
displayName: 'Use Python 3.9'

0 commit comments

Comments
 (0)