Skip to content

Commit 8e87775

Browse files
Address hostile review: input validation, error handling, logging
- Trim version.txt on read (Set-ExtensionVersionVariable, Set-ExtensionVersionInBuild) - Validate empty version.txt in Set-ExtensionVersionInBuild - Make BuildReason/BuildId mandatory params - Wrap Get-FileHash in try/catch - Validate required YAML fields (namespace, displayName, description) after parsing - Log parsed extension metadata for pipeline diagnostics - Fix upload error handling (don't set ErrorActionPreference=Continue before upload) - Guard CreateGitHubRelease against empty TagPrefix/TagVersion Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent fbfb793 commit 8e87775

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

eng/pipelines/templates/steps/publish-extension.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ parameters:
1515
default: true
1616

1717
steps:
18-
- ${{ if eq(parameters.CreateGitHubRelease, true) }}:
18+
- ${{ if and(eq(parameters.CreateGitHubRelease, true), ne(parameters.TagPrefix, ''), ne(parameters.TagVersion, '')) }}:
1919
# This step must run first because a duplicated tag means we don't need to
2020
# continue with any of the subsequent steps.
2121
- pwsh: |

eng/scripts/Set-ExtensionVersionInBuild.ps1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#>
1515
param(
1616
[Parameter(Mandatory)] [string] $ExtensionDirectory,
17-
[string] $BuildReason,
18-
[string] $BuildId
17+
[Parameter(Mandatory)] [string] $BuildReason,
18+
[Parameter(Mandatory)] [string] $BuildId
1919
)
2020

2121
Write-Host "Build reason: $BuildReason"
@@ -34,7 +34,11 @@ else {
3434
}
3535

3636
$versionFile = Join-Path $ExtensionDirectory "version.txt"
37-
$version = Get-Content $versionFile
37+
$version = (Get-Content $versionFile).Trim()
38+
if ([string]::IsNullOrWhiteSpace($version)) {
39+
Write-Error "version.txt is empty at $versionFile"
40+
exit 1
41+
}
3842
$newVersion = "$version-$prereleaseCategory.$BuildId"
3943

4044
Set-Content $versionFile -Value $newVersion

eng/scripts/Set-ExtensionVersionVariable.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ param(
22
[string] $ExtensionDirectory
33
)
44

5-
$extVersion = Get-Content "$ExtensionDirectory/version.txt"
5+
$extVersion = (Get-Content "$ExtensionDirectory/version.txt").Trim()
66
Write-Host "Extension Version: $extVersion"
77
Write-Host "##vso[task.setvariable variable=EXT_VERSION;]$extVersion"

eng/scripts/Update-ExtensionDailyRegistry.ps1

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,14 @@ $artifactFiles = @(
7373
foreach ($artifact in $artifactFiles) {
7474
$filePath = Join-Path $ReleasePath $artifact.file
7575
if (Test-Path $filePath) {
76-
$hash = (Get-FileHash -Path $filePath -Algorithm SHA256).Hash.ToLower()
77-
$checksums[$artifact.key] = $hash
78-
Write-Host "Checksum $($artifact.key): $hash"
76+
try {
77+
$hash = (Get-FileHash -Path $filePath -Algorithm SHA256).Hash.ToLower()
78+
$checksums[$artifact.key] = $hash
79+
Write-Host "Checksum $($artifact.key): $hash"
80+
} catch {
81+
Write-Error "Failed to compute checksum for ${filePath}: $_"
82+
exit 1
83+
}
7984
} else {
8085
$missingArtifacts += $artifact.file
8186
}
@@ -126,6 +131,22 @@ foreach ($line in $extYaml -split "`n") {
126131
}
127132
if ($currentProvider) { $providers += $currentProvider }
128133

134+
# Validate required fields were parsed
135+
$requiredFields = @('namespace', 'displayName', 'description')
136+
foreach ($field in $requiredFields) {
137+
if (-not $extMeta[$field] -or $extMeta[$field] -eq '') {
138+
Write-Error "Required field '$field' missing or empty in extension.yaml"
139+
exit 1
140+
}
141+
}
142+
143+
Write-Host "Parsed extension metadata:"
144+
Write-Host " namespace: $($extMeta.namespace)"
145+
Write-Host " displayName: $($extMeta.displayName)"
146+
Write-Host " description: $($extMeta.description)"
147+
Write-Host " capabilities: $($capabilities -join ', ')"
148+
Write-Host " providers: $($providers.Count)"
149+
129150
# Load template and replace placeholders
130151
$template = Get-Content $TemplatePath -Raw
131152
$replacements = @{
@@ -217,7 +238,6 @@ Write-Host "Registry contents:"
217238
Get-Content $registryFile
218239

219240
# Upload to storage
220-
$ErrorActionPreference = 'Continue'
221241
azcopy copy $registryFile $RegistryBlobPath --overwrite=true
222242
if ($LASTEXITCODE -ne 0) {
223243
Write-Error "Failed to upload registry to $RegistryBlobPath (exit code $LASTEXITCODE)"

0 commit comments

Comments
 (0)