Skip to content

Commit

Permalink
Merge branch 'main' into jacktn/test-correct-filter-2
Browse files Browse the repository at this point in the history
  • Loading branch information
JackTn authored Sep 6, 2024
2 parents 881a21d + 02e5008 commit ccc62d0
Show file tree
Hide file tree
Showing 941 changed files with 145,500 additions and 6,224 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/protected-files.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Protected Files

on: pull_request

jobs:
protected-files:
name: Protected Files

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
# Required since "HEAD^" is passed to Get-ChangedFiles
fetch-depth: 2

- name: Detect changes to protected files
run: |
. eng/scripts/ChangedFiles-Functions.ps1
$protectedFiles = @("package.json", "package-lock.json")
$changedFiles = @(Get-ChangedFiles -baseCommitish HEAD^ -targetCommitish HEAD -diffFilter "")
$matchedFiles = @($protectedFiles | Where-Object { $changedFiles -contains $_})
if ($matchedFiles.Count -gt 0) {
foreach ($file in $matchedFiles) {
Write-Output "::error file=$file::File '$file' should only be updated by the Azure SDK team. If intentional, the PR may be merged by the Azure SDK team via bypassing the branch protections."
}
exit 1
}
else {
Write-Output "::notice::No changes to protected files: [$($protectedFiles -join ', ')]"
}
shell: pwsh
7 changes: 7 additions & 0 deletions cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,13 @@
"mqttbroker",
"schemaregistry"
]
},
{
"filename": "**/specification/servicefabricmanagedclusters/resource-manager/Microsoft.ServiceFabric/**/*.json",
"words": [
"sfmc",
"sfmc's"
]
}
],
"enableFiletypes": [
Expand Down
3 changes: 3 additions & 0 deletions eng/pipelines/typespec-validation-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ trigger:
branches:
include:
- main
- RPSaaSMaster
- typespec-next

pr:
branches:
include:
- main
- RPSaaSMaster
- typespec-next
paths:
include:
Expand All @@ -17,6 +19,7 @@ pr:
- package.json
- tsconfig.json
- eng
- specification/suppressions.yaml
- specification/common-types

resources:
Expand Down
3 changes: 2 additions & 1 deletion eng/scripts/ChangedFiles-Functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ function Get-ChangedCoreFiles($changedFiles = (Get-ChangedFiles)) {
".prettierrc.json",
"package-lock.json",
"package.json",
"tsconfig.json"
"tsconfig.json",
"specification/suppressions.yaml"
)

$coreFiles = $changedFiles.Where({
Expand Down
2 changes: 1 addition & 1 deletion eng/scripts/Get-TypeSpec-Folders.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ else {
$changedFiles = @(Get-ChangedFiles -baseCommitish $BaseCommitish -targetCommitish $TargetCommitish -diffFilter "")
$coreChangedFiles = Get-ChangedCoreFiles $changedFiles

if ($Env:BUILD_REPOSITORY_NAME -eq 'azure/azure-rest-api-specs' -and $coreChangedFiles) {
if ($coreChangedFiles) {
Write-Verbose "Found changes to core eng or root files so checking all specs."
$changedFiles = $checkAllPath
}
Expand Down
60 changes: 60 additions & 0 deletions eng/scripts/Suppressions-Functions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<#
.DESCRIPTION
Returns the suppressions for a tool applicable to a path. Walks up the directory tree to find all files named
"suppressions.yaml", parses and validates the contents, and returns the suppressions matching the tool and path.
Suppressions are ordered by file (closest to path is first), then within the file (closest to top is first).
.PARAMETER Tool
Name of tool. Matched against property "tool" in suppressions.yaml.
.PARAMETER Path
Path to file or directory under analysis.
.OUTPUTS
Hashtable[]
Array of suppressions matching tool and path (may be empty). See the "get-suppressions" tool for the definition
of the suppression object.
#>
function Get-Suppressions {
param (
[string]$Tool,
[string]$Path
)

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

if ($LASTEXITCODE -ne 0) {
throw "Failure running 'npm exec get-suppressions'"
}

return $suppressions;
}

<#
.DESCRIPTION
Returns the first suppression for a tool applicable to a path. Walks up the directory tree to find all files named
"suppressions.yaml", parses and validates the contents, and returns the first suppression matching the tool and path.
Suppressions are ordered by file (closest to path is first), then within the file (closest to top is first).
.PARAMETER Tool
Name of tool. Matched against property "tool" in suppressions.yaml.
.PARAMETER Path
Path to file or directory under analysis.
.OUTPUTS
Hashtable
First suppressions matching tool and path (may be null). See the "get-suppressions" tool for the definition
of the suppression object.
#>
function Get-Suppression {
param (
[string]$Tool,
[string]$Path
)

$suppressions = @(Get-Suppressions $Tool $Path)
return $suppressions ? $suppressions[0] : $null;
}
18 changes: 4 additions & 14 deletions eng/scripts/TypeSpec-Requirement.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,14 @@ Set-StrictMode -Version 3

. $PSScriptRoot/ChangedFiles-Functions.ps1
. $PSScriptRoot/Logging-Functions.ps1
. $PSScriptRoot/Suppressions-Functions.ps1

function Get-Suppression {
function Get-ValidatedSuppression {
param (
[string]$fileInSpecFolder
)

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

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
$suppression = Get-Suppression "TypeSpecRequirement" $fileInSpecFolder

if ($suppression) {
# Each path must specify a single version (without wildcards) under "preview|stable"
Expand Down Expand Up @@ -90,7 +80,7 @@ else {

$fullPath = (Join-Path $repoPath $file)

$suppression = Get-Suppression $fullPath
$suppression = Get-ValidatedSuppression $fullPath
if ($suppression) {
$reason = $suppression["reason"] ?? "<no reason specified>"

Expand Down
19 changes: 19 additions & 0 deletions eng/scripts/TypeSpec-Validation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
param (
[switch]$CheckAll = $false,
[switch]$GitClean = $false,
[switch]$DryRun = $false,
[string]$BaseCommitish = "HEAD^",
[string]$TargetCommitish = "HEAD"
)

. $PSScriptRoot/Logging-Functions.ps1
. $PSScriptRoot/Suppressions-Functions.ps1

$typespecFolders = &"$PSScriptRoot/Get-TypeSpec-Folders.ps1" -BaseCommitish:$BaseCommitish -TargetCommitish:$TargetCommitish -CheckAll:$CheckAll

Expand All @@ -15,7 +17,24 @@ if ($typespecFolders) {
$typespecFolders = $typespecFolders.Split('',[System.StringSplitOptions]::RemoveEmptyEntries)
foreach ($typespecFolder in $typespecFolders) {
LogGroupStart "Validating $typespecFolder"

if ($CheckAll) {
$suppression = Get-Suppression "TypeSpecValidationAll" $typespecFolder
if ($suppression) {
$reason = $suppression["reason"] ?? "<no reason specified>"
LogInfo "Suppressed: $reason"
LogGroupEnd
continue
}
}

LogInfo "npm exec --no -- tsv $typespecFolder"

if ($DryRun) {
LogGroupEnd
continue
}

npm exec --no -- tsv $typespecFolder 2>&1 | Write-Host
if ($LASTEXITCODE) {
$typespecFoldersWithFailures += $typespecFolder
Expand Down
4 changes: 2 additions & 2 deletions specification/azurefleet/AzureFleet.Management/fleet.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ model Fleet is TrackedResource<FleetProperties> {
@doc("The name of the Compute Fleet")
@key("fleetName")
@segment("fleets")
@pattern("^[^_\\W][\\w-._]{0,79}(?<![-.])$")
@pattern("^[^_\\W][\\w\\-._]{0,79}(?<![-.])$")
@path
name: string;

Expand Down Expand Up @@ -237,7 +237,7 @@ interface Fleets {
...ProviderNamespace<Fleet>,
...ResourceNameParameter<
Fleet,
NamePattern = "^[^_\\W][\\w-._]{0,79}(?<![-.])$"
NamePattern = "^[^_\\W][\\w\\-._]{0,79}(?<![-.])$"
>,
): ArmResponse<VirtualMachineScaleSetListResult> | ErrorResponse;
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
"description": "The name of the Compute Fleet",
"required": true,
"type": "string",
"pattern": "^[^_\\W][\\w-._]{0,79}(?<![-.])$"
"pattern": "^[^_\\W][\\w\\-._]{0,79}(?<![-.])$"
}
],
"responses": {
Expand Down Expand Up @@ -243,7 +243,7 @@
"description": "The name of the Compute Fleet",
"required": true,
"type": "string",
"pattern": "^[^_\\W][\\w-._]{0,79}(?<![-.])$"
"pattern": "^[^_\\W][\\w\\-._]{0,79}(?<![-.])$"
},
{
"name": "resource",
Expand Down Expand Up @@ -317,7 +317,7 @@
"description": "The name of the Compute Fleet",
"required": true,
"type": "string",
"pattern": "^[^_\\W][\\w-._]{0,79}(?<![-.])$"
"pattern": "^[^_\\W][\\w\\-._]{0,79}(?<![-.])$"
},
{
"name": "properties",
Expand Down Expand Up @@ -392,7 +392,7 @@
"description": "The name of the Compute Fleet",
"required": true,
"type": "string",
"pattern": "^[^_\\W][\\w-._]{0,79}(?<![-.])$"
"pattern": "^[^_\\W][\\w\\-._]{0,79}(?<![-.])$"
}
],
"responses": {
Expand Down Expand Up @@ -457,7 +457,7 @@
"description": "The name of the Fleet",
"required": true,
"type": "string",
"pattern": "^[^_\\W][\\w-._]{0,79}(?<![-.])$"
"pattern": "^[^_\\W][\\w\\-._]{0,79}(?<![-.])$"
}
],
"responses": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
"description": "The name of the Compute Fleet",
"required": true,
"type": "string",
"pattern": "^[^_\\W][\\w-._]{0,79}(?<![-.])$"
"pattern": "^[^_\\W][\\w\\-._]{0,79}(?<![-.])$"
}
],
"responses": {
Expand Down Expand Up @@ -231,7 +231,7 @@
"description": "The name of the Compute Fleet",
"required": true,
"type": "string",
"pattern": "^[^_\\W][\\w-._]{0,79}(?<![-.])$"
"pattern": "^[^_\\W][\\w\\-._]{0,79}(?<![-.])$"
},
{
"name": "resource",
Expand Down Expand Up @@ -305,7 +305,7 @@
"description": "The name of the Compute Fleet",
"required": true,
"type": "string",
"pattern": "^[^_\\W][\\w-._]{0,79}(?<![-.])$"
"pattern": "^[^_\\W][\\w\\-._]{0,79}(?<![-.])$"
},
{
"name": "properties",
Expand Down Expand Up @@ -377,7 +377,7 @@
"description": "The name of the Compute Fleet",
"required": true,
"type": "string",
"pattern": "^[^_\\W][\\w-._]{0,79}(?<![-.])$"
"pattern": "^[^_\\W][\\w\\-._]{0,79}(?<![-.])$"
}
],
"responses": {
Expand Down Expand Up @@ -439,7 +439,7 @@
"description": "The name of the Fleet",
"required": true,
"type": "string",
"pattern": "^[^_\\W][\\w-._]{0,79}(?<![-.])$"
"pattern": "^[^_\\W][\\w\\-._]{0,79}(?<![-.])$"
}
],
"responses": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"parameters": {
"api-version": "2024-05-01-preview",
"resourceUri": "subscriptions/fd3c3665-1729-4b7b-9a38-238e83b0f98b/resourceGroups/testrg/providers/Microsoft.HybridCompute/machines/DemoVM"
},
"responses": {
"200": {
"body": {
"name": "default",
"type": "Microsoft.AzureStackHCI/virtualMachineInstances/AttestationStatus",
"id": "/subscriptions/fd3c3665-1729-4b7b-9a38-238e83b0f98b/resourceGroups/testrg/providers/Microsoft.HybridCompute/machines/DemoVM/providers/Microsoft.AzureStackHCI/virtualMachineInstances/default/attestationStatus/default",
"properties": {
"attestSecureBootEnabled": "Disabled",
"attestationCertValidated": "Invalid",
"bootIntegrityValidated": "Invalid",
"errorMessage": "Attestation token has invalid signature",
"healthStatus": "Unhealthy",
"linuxKernelVersion": "1.0.0.0",
"timestamp": "2023/11/10 9:48"
}
}
}
},
"operationId": "AttestationStatuses_Get",
"title": "GetAttestationStatus"
}
Loading

0 comments on commit ccc62d0

Please sign in to comment.