Skip to content

Commit

Permalink
[TypeSpecRequirement] Only allow one version per suppression (#29001)
Browse files Browse the repository at this point in the history
- Fixes #28755
  • Loading branch information
mikeharder committed May 7, 2024
1 parent 9fe3ac4 commit d678044
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions eng/scripts/TypeSpec-Requirement.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,37 @@ function Get-Suppression {

# -NoEnumerate to prevent single-element arrays from being collapsed to a single object
# -AsHashtable is closer to raw JSON than PSCustomObject
$suppressions = npx get-suppressions TypeSpecRequirement $fileInSpecFolder | ConvertFrom-Json -NoEnumerate -AsHashtable
$suppressions = npm exec --no -- get-suppressions TypeSpecRequirement $fileInSpecFolder | ConvertFrom-Json -NoEnumerate -AsHashtable

return $suppressions ? $suppressions[0] : $null;
if ($LASTEXITCODE -ne 0) {
LogError "Failure running 'npm exec get-suppressions'"
LogJobFailure
exit 1
}

# For now, we just use the first matching suppression returned by "get-suppressions" (#29003)
$suppression = $suppressions ? $suppressions[0] : $null

if ($suppression) {
$path = $suppression["path"]

# Path must specify a single version (without wildcards) under "preview|stable"
#
# Allowed: data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/**/*.json
# Disallowed: data-plane/Azure.Contoso.WidgetManager/preview/**/*.json
# Disallowed: data-plane/**/*.json
#
# Include "." since a few specs use versions like "X.Y" instead of "YYYY-MM-DD"
$singleVersionPattern = "/(preview|stable)/[A-Za-z0-9._-]+/"

if ($path -notmatch $singleVersionPattern) {
LogError ("Invalid path '$path'. Path must only include one version per suppression.")
LogJobFailure
exit 1
}
}

return $suppression
}

$repoPath = Resolve-Path "$PSScriptRoot/../.."
Expand Down

0 comments on commit d678044

Please sign in to comment.