From aa5bd9361d8879a29411e4a392a6cf0d976f298c Mon Sep 17 00:00:00 2001 From: "Paul D.Smith" Date: Wed, 30 Oct 2024 14:28:14 +0000 Subject: [PATCH 01/12] Initial Powershell release compliance tool. --- .../ConnectedKubernetes.Autorest/README.md | 10 ++ tools/CheckPowershellCompliance.ps1 | 138 ++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 tools/CheckPowershellCompliance.ps1 diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md index fbe518c45ada..5820bece6b07 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md @@ -86,3 +86,13 @@ directive: subject-prefix: ConnectedKubernetes hide: true ``` + +### PSScriptAnalyzer Configuration +``` yaml +targetVersions: +- "5.1" +- "7.0" +targetProfiles: +- "win-8_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework" +- "win-8_x64_10.0.14393.0_7.0.0_x64_3.1.2_core" +``` diff --git a/tools/CheckPowershellCompliance.ps1 b/tools/CheckPowershellCompliance.ps1 new file mode 100644 index 000000000000..a34857de143b --- /dev/null +++ b/tools/CheckPowershellCompliance.ps1 @@ -0,0 +1,138 @@ +# This Powershell script checks Powershell compatibility of any custom scripts +# in the repository. It assumes configuration for this is present in the +# README.md. +# +# The configuration should look like this: +# +# ### PSScriptAnalyzer Configuration +# ``` yaml +# targetVersions: +# - "5.1" +# - "7.0" +# targetProfiles: +# - "win-8_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework" +# - "win-8_x64_10.0.14393.0_7.0.0_x64_3.1.2_core" +# ``` + +function Read-ComplianceConfiguration { + $path = "README.md" + $configMarker = "### PSScriptAnalyzer Configuration" + $backTicksYaml = '``` yaml' + $backTicks = '```' + + $readme = Get-Content $path + + # Extract out the YAML which sits between backticks markers after the + # PSScriptAnalyzer configuration marker. + $yaml = "" + $inConfig = $false + for ($i = 0; $i -lt $readme.Length; $i++) { + if ($readme[$i] -eq $configMarker) { + $inConfig = $true + } + if ($inConfig -and ($readme[$i] -eq $backTicksYaml)) { + $i++ + while ($i -lt $readme.Length -and $readme[$i] -ne $backticks) { + $yaml += "`n" + $readme[$i] + $i++ + } + break + } + } + + if ("" -eq $yaml) { + Write-Error "No PSScriptAnalyzer Configuration found in README.md" + exit 2 + } + + # Parse the YAML. + $yamlObj = ConvertFrom-YAML $yaml + + # Confirm that there is at least one TargetVersion and that there are the + # same number of TargetVersions as TargetProfiles. + if ($yamlObj.targetVersions.Count -eq 0) { + Write-Error "No TargetVersions found in PSScriptAnalyzer Configuration." + exit 4 + } + if ($yamlObj.targetVersions.Count -ne $yamlObj.targetProfiles.Count) { + Write-Error "Number of TargetVersions ($($yamlObj.targetVersions.Count)) and TargetProfiles ($($yamlObj.targetprofiles.Count)) do not match." + exit 6 + } + + return $yamlObj +} + +function Confirm-Compliance { + param( + [string[]]$TargetVersions, + [string[]]$TargetProfiles + ) + Write-Output -ForegroundColor Green 'Linting and checking Powershell back-compatibility...' + Install-Module PSScriptAnalyzer -Scope CurrentUser -Force + $settings = @{ + # Ref: https://devblogs.microsoft.com/powershell/using-psscriptanalyzer-to-check-powershell-version-compatibility/ + Rules = @{ + PSUseCompatibleSyntax = @{ + # This turns the rule on (setting it to false will turn it off) + Enable = $true + + # List the targeted versions of PowerShell here + TargetVersions = $TargetVersions + } + PSUseCompatibleCommands = @{ + # Turns the rule on + Enable = $true + + # Lists the PowerShell platforms we want to check compatibility with + # Ref: https://learn.microsoft.com/en-gb/powershell/utility-modules/psscriptanalyzer/rules/usecompatiblecommands?view=ps-modules + TargetProfiles = $TargetProfiles + } + } + } + + # Recursively find all *.ps1 files and run Invoke-ScriptAnalyzer against them. + Get-ChildItem -Path . -Recurse -Include '*.ps1' | Invoke-ScriptAnalyzer -Settings $settings + if ($LastExitCode -ne 0) { + Write-Error 'ScriptAnalyzer found (possibly back-compatibility) issues.' + exit 5 + } +} + +function Confirm-CustomScript { + Write-Debug "Confirm custom scripts are present." + + # Get all *.ps1 files in the current directory + $scripts = Get-ChildItem -Path ./custom -Recurse -Include '*.ps1' + if ($scripts.Length -eq 0) { + Write-Error "No custom scripts found in the repository." + exit 3 + } +} + +function Confirm-InAutorestEnv { + Write-Debug "Confirm in an autorest directory." + + # Get current working directory then confirm it ends in ".autorest" + $cwd = Get-Location + if ($cwd -notlike "*.autorest") { + Write-Error "This script should be run from an autorest directory." + exit 1 + } + +} + +# Confirm that the required modules are installed. +if (-not(Get-InstalledModule -Name "powershell-yaml")) { + Write-Error "powershell-yaml module is required. Please install it." + exit 7 +} +if (-not(Get-InstalledModule -Name PSScriptAnalyzer)) { + Write-Error "PSScriptAnalyzer module is required. Please install it." + exit 7 +} + +# Run the script. +Confirm-InAutorestEnv +Confirm-CustomScript +$configuration = Read-ComplianceConfiguration +Confirm-Compliance -TargetVersions $configuration.targetVersions -TargetProfiles $configuration.targetProfiles \ No newline at end of file From 3acf909ac9239f666b0eee53c68d364345b29389 Mon Sep 17 00:00:00 2001 From: "Paul D.Smith" Date: Mon, 4 Nov 2024 09:59:40 +0000 Subject: [PATCH 02/12] LASTERROREXIT does not catch Invoke-Analyzer errors. --- tools/CheckPowershellCompliance.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/CheckPowershellCompliance.ps1 b/tools/CheckPowershellCompliance.ps1 index a34857de143b..b694604ce4b4 100644 --- a/tools/CheckPowershellCompliance.ps1 +++ b/tools/CheckPowershellCompliance.ps1 @@ -91,8 +91,9 @@ function Confirm-Compliance { } # Recursively find all *.ps1 files and run Invoke-ScriptAnalyzer against them. - Get-ChildItem -Path . -Recurse -Include '*.ps1' | Invoke-ScriptAnalyzer -Settings $settings - if ($LastExitCode -ne 0) { + $problems = $(Get-ChildItem -Path ./custom -Recurse -Include '*.ps1' | Invoke-ScriptAnalyzer -Settings $settings) + if ("" -ne $problems) { + Write-Output $problems Write-Error 'ScriptAnalyzer found (possibly back-compatibility) issues.' exit 5 } From d721b421f947f813a5a52c25075b357017133f15 Mon Sep 17 00:00:00 2001 From: "Paul D.Smith" Date: Wed, 6 Nov 2024 11:47:09 +0000 Subject: [PATCH 03/12] Updated Powershell definitions to latest versions. --- .../ConnectedKubernetes.Autorest/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md index 5820bece6b07..f2440d51d7fa 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md @@ -93,6 +93,6 @@ targetVersions: - "5.1" - "7.0" targetProfiles: -- "win-8_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework" -- "win-8_x64_10.0.14393.0_7.0.0_x64_3.1.2_core" +- "win-48_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework" +- "win-4_x64_10.0.18362.0_7.0.0_x64_3.1.2_core" ``` From 021daf456b86cd992e65d5ddad89154e65876963 Mon Sep 17 00:00:00 2001 From: "Paul D.Smith" Date: Tue, 27 May 2025 10:26:01 +0100 Subject: [PATCH 04/12] Correct backticks ref Replace use of Write-Error/exit with Throw. --- tools/CheckPowershellCompliance.ps1 | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/tools/CheckPowershellCompliance.ps1 b/tools/CheckPowershellCompliance.ps1 index b694604ce4b4..1861cea400d4 100644 --- a/tools/CheckPowershellCompliance.ps1 +++ b/tools/CheckPowershellCompliance.ps1 @@ -5,7 +5,7 @@ # The configuration should look like this: # # ### PSScriptAnalyzer Configuration -# ``` yaml +# ```yaml # targetVersions: # - "5.1" # - "7.0" @@ -17,7 +17,7 @@ function Read-ComplianceConfiguration { $path = "README.md" $configMarker = "### PSScriptAnalyzer Configuration" - $backTicksYaml = '``` yaml' + $backTicksYaml = '```yaml' $backTicks = '```' $readme = Get-Content $path @@ -41,8 +41,7 @@ function Read-ComplianceConfiguration { } if ("" -eq $yaml) { - Write-Error "No PSScriptAnalyzer Configuration found in README.md" - exit 2 + Throw "No PSScriptAnalyzer Configuration found in README.md" } # Parse the YAML. @@ -51,12 +50,10 @@ function Read-ComplianceConfiguration { # Confirm that there is at least one TargetVersion and that there are the # same number of TargetVersions as TargetProfiles. if ($yamlObj.targetVersions.Count -eq 0) { - Write-Error "No TargetVersions found in PSScriptAnalyzer Configuration." - exit 4 + Throw "No TargetVersions found in PSScriptAnalyzer Configuration." } if ($yamlObj.targetVersions.Count -ne $yamlObj.targetProfiles.Count) { - Write-Error "Number of TargetVersions ($($yamlObj.targetVersions.Count)) and TargetProfiles ($($yamlObj.targetprofiles.Count)) do not match." - exit 6 + Throw "Number of TargetVersions ($($yamlObj.targetVersions.Count)) and TargetProfiles ($($yamlObj.targetprofiles.Count)) do not match." } return $yamlObj @@ -94,8 +91,7 @@ function Confirm-Compliance { $problems = $(Get-ChildItem -Path ./custom -Recurse -Include '*.ps1' | Invoke-ScriptAnalyzer -Settings $settings) if ("" -ne $problems) { Write-Output $problems - Write-Error 'ScriptAnalyzer found (possibly back-compatibility) issues.' - exit 5 + Throw 'ScriptAnalyzer found (possibly back-compatibility) issues.' } } @@ -105,8 +101,7 @@ function Confirm-CustomScript { # Get all *.ps1 files in the current directory $scripts = Get-ChildItem -Path ./custom -Recurse -Include '*.ps1' if ($scripts.Length -eq 0) { - Write-Error "No custom scripts found in the repository." - exit 3 + Throw "No custom scripts found in the repository." } } @@ -116,20 +111,17 @@ function Confirm-InAutorestEnv { # Get current working directory then confirm it ends in ".autorest" $cwd = Get-Location if ($cwd -notlike "*.autorest") { - Write-Error "This script should be run from an autorest directory." - exit 1 + Throw "This script should be run from an autorest directory." } } # Confirm that the required modules are installed. if (-not(Get-InstalledModule -Name "powershell-yaml")) { - Write-Error "powershell-yaml module is required. Please install it." - exit 7 + Throw "powershell-yaml module is required. Please install it." } if (-not(Get-InstalledModule -Name PSScriptAnalyzer)) { - Write-Error "PSScriptAnalyzer module is required. Please install it." - exit 7 + Throw "PSScriptAnalyzer module is required. Please install it." } # Run the script. From b39f4bc5e34571ae27de089dbd2f015c185a91c7 Mon Sep 17 00:00:00 2001 From: "Paul D.Smith" Date: Tue, 27 May 2025 10:28:59 +0100 Subject: [PATCH 05/12] Correct source to show real powershell versions. --- tools/CheckPowershellCompliance.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/CheckPowershellCompliance.ps1 b/tools/CheckPowershellCompliance.ps1 index 1861cea400d4..704981efcd58 100644 --- a/tools/CheckPowershellCompliance.ps1 +++ b/tools/CheckPowershellCompliance.ps1 @@ -10,8 +10,8 @@ # - "5.1" # - "7.0" # targetProfiles: -# - "win-8_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework" -# - "win-8_x64_10.0.14393.0_7.0.0_x64_3.1.2_core" +# - "win-48_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework" +# - "win-4_x64_10.0.18362.0_7.0.0_x64_3.1.2_core" # ``` function Read-ComplianceConfiguration { From e56ec8ecedcf3583c5a223d0f83ec946f8389107 Mon Sep 17 00:00:00 2001 From: "Paul D.Smith" Date: Tue, 27 May 2025 10:30:18 +0100 Subject: [PATCH 06/12] Correct backticks. --- src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md index f2440d51d7fa..574ab3d8d08e 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md @@ -88,7 +88,7 @@ directive: ``` ### PSScriptAnalyzer Configuration -``` yaml +```yaml targetVersions: - "5.1" - "7.0" From 9a2841365a349f924fb2a28bff62d1ee624a2ebf Mon Sep 17 00:00:00 2001 From: "Paul D.Smith" Date: Wed, 30 Oct 2024 14:28:14 +0000 Subject: [PATCH 07/12] Initial Powershell release compliance tool. --- .../ConnectedKubernetes.Autorest/README.md | 10 ++ tools/CheckPowershellCompliance.ps1 | 138 ++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 tools/CheckPowershellCompliance.ps1 diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md index fbe518c45ada..5820bece6b07 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md @@ -86,3 +86,13 @@ directive: subject-prefix: ConnectedKubernetes hide: true ``` + +### PSScriptAnalyzer Configuration +``` yaml +targetVersions: +- "5.1" +- "7.0" +targetProfiles: +- "win-8_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework" +- "win-8_x64_10.0.14393.0_7.0.0_x64_3.1.2_core" +``` diff --git a/tools/CheckPowershellCompliance.ps1 b/tools/CheckPowershellCompliance.ps1 new file mode 100644 index 000000000000..a34857de143b --- /dev/null +++ b/tools/CheckPowershellCompliance.ps1 @@ -0,0 +1,138 @@ +# This Powershell script checks Powershell compatibility of any custom scripts +# in the repository. It assumes configuration for this is present in the +# README.md. +# +# The configuration should look like this: +# +# ### PSScriptAnalyzer Configuration +# ``` yaml +# targetVersions: +# - "5.1" +# - "7.0" +# targetProfiles: +# - "win-8_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework" +# - "win-8_x64_10.0.14393.0_7.0.0_x64_3.1.2_core" +# ``` + +function Read-ComplianceConfiguration { + $path = "README.md" + $configMarker = "### PSScriptAnalyzer Configuration" + $backTicksYaml = '``` yaml' + $backTicks = '```' + + $readme = Get-Content $path + + # Extract out the YAML which sits between backticks markers after the + # PSScriptAnalyzer configuration marker. + $yaml = "" + $inConfig = $false + for ($i = 0; $i -lt $readme.Length; $i++) { + if ($readme[$i] -eq $configMarker) { + $inConfig = $true + } + if ($inConfig -and ($readme[$i] -eq $backTicksYaml)) { + $i++ + while ($i -lt $readme.Length -and $readme[$i] -ne $backticks) { + $yaml += "`n" + $readme[$i] + $i++ + } + break + } + } + + if ("" -eq $yaml) { + Write-Error "No PSScriptAnalyzer Configuration found in README.md" + exit 2 + } + + # Parse the YAML. + $yamlObj = ConvertFrom-YAML $yaml + + # Confirm that there is at least one TargetVersion and that there are the + # same number of TargetVersions as TargetProfiles. + if ($yamlObj.targetVersions.Count -eq 0) { + Write-Error "No TargetVersions found in PSScriptAnalyzer Configuration." + exit 4 + } + if ($yamlObj.targetVersions.Count -ne $yamlObj.targetProfiles.Count) { + Write-Error "Number of TargetVersions ($($yamlObj.targetVersions.Count)) and TargetProfiles ($($yamlObj.targetprofiles.Count)) do not match." + exit 6 + } + + return $yamlObj +} + +function Confirm-Compliance { + param( + [string[]]$TargetVersions, + [string[]]$TargetProfiles + ) + Write-Output -ForegroundColor Green 'Linting and checking Powershell back-compatibility...' + Install-Module PSScriptAnalyzer -Scope CurrentUser -Force + $settings = @{ + # Ref: https://devblogs.microsoft.com/powershell/using-psscriptanalyzer-to-check-powershell-version-compatibility/ + Rules = @{ + PSUseCompatibleSyntax = @{ + # This turns the rule on (setting it to false will turn it off) + Enable = $true + + # List the targeted versions of PowerShell here + TargetVersions = $TargetVersions + } + PSUseCompatibleCommands = @{ + # Turns the rule on + Enable = $true + + # Lists the PowerShell platforms we want to check compatibility with + # Ref: https://learn.microsoft.com/en-gb/powershell/utility-modules/psscriptanalyzer/rules/usecompatiblecommands?view=ps-modules + TargetProfiles = $TargetProfiles + } + } + } + + # Recursively find all *.ps1 files and run Invoke-ScriptAnalyzer against them. + Get-ChildItem -Path . -Recurse -Include '*.ps1' | Invoke-ScriptAnalyzer -Settings $settings + if ($LastExitCode -ne 0) { + Write-Error 'ScriptAnalyzer found (possibly back-compatibility) issues.' + exit 5 + } +} + +function Confirm-CustomScript { + Write-Debug "Confirm custom scripts are present." + + # Get all *.ps1 files in the current directory + $scripts = Get-ChildItem -Path ./custom -Recurse -Include '*.ps1' + if ($scripts.Length -eq 0) { + Write-Error "No custom scripts found in the repository." + exit 3 + } +} + +function Confirm-InAutorestEnv { + Write-Debug "Confirm in an autorest directory." + + # Get current working directory then confirm it ends in ".autorest" + $cwd = Get-Location + if ($cwd -notlike "*.autorest") { + Write-Error "This script should be run from an autorest directory." + exit 1 + } + +} + +# Confirm that the required modules are installed. +if (-not(Get-InstalledModule -Name "powershell-yaml")) { + Write-Error "powershell-yaml module is required. Please install it." + exit 7 +} +if (-not(Get-InstalledModule -Name PSScriptAnalyzer)) { + Write-Error "PSScriptAnalyzer module is required. Please install it." + exit 7 +} + +# Run the script. +Confirm-InAutorestEnv +Confirm-CustomScript +$configuration = Read-ComplianceConfiguration +Confirm-Compliance -TargetVersions $configuration.targetVersions -TargetProfiles $configuration.targetProfiles \ No newline at end of file From c2d8ba26c2066c7d96299a6185739f9ac313345e Mon Sep 17 00:00:00 2001 From: "Paul D.Smith" Date: Mon, 4 Nov 2024 09:59:40 +0000 Subject: [PATCH 08/12] LASTERROREXIT does not catch Invoke-Analyzer errors. --- tools/CheckPowershellCompliance.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/CheckPowershellCompliance.ps1 b/tools/CheckPowershellCompliance.ps1 index a34857de143b..b694604ce4b4 100644 --- a/tools/CheckPowershellCompliance.ps1 +++ b/tools/CheckPowershellCompliance.ps1 @@ -91,8 +91,9 @@ function Confirm-Compliance { } # Recursively find all *.ps1 files and run Invoke-ScriptAnalyzer against them. - Get-ChildItem -Path . -Recurse -Include '*.ps1' | Invoke-ScriptAnalyzer -Settings $settings - if ($LastExitCode -ne 0) { + $problems = $(Get-ChildItem -Path ./custom -Recurse -Include '*.ps1' | Invoke-ScriptAnalyzer -Settings $settings) + if ("" -ne $problems) { + Write-Output $problems Write-Error 'ScriptAnalyzer found (possibly back-compatibility) issues.' exit 5 } From 1af7f82912f0aa8ec9c98bb303373ee66acc633c Mon Sep 17 00:00:00 2001 From: "Paul D.Smith" Date: Wed, 6 Nov 2024 11:47:09 +0000 Subject: [PATCH 09/12] Updated Powershell definitions to latest versions. --- .../ConnectedKubernetes.Autorest/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md index 5820bece6b07..f2440d51d7fa 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md @@ -93,6 +93,6 @@ targetVersions: - "5.1" - "7.0" targetProfiles: -- "win-8_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework" -- "win-8_x64_10.0.14393.0_7.0.0_x64_3.1.2_core" +- "win-48_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework" +- "win-4_x64_10.0.18362.0_7.0.0_x64_3.1.2_core" ``` From fcdf90f8fb047cda0e4629384c6f8878fe7965db Mon Sep 17 00:00:00 2001 From: "Paul D.Smith" Date: Tue, 27 May 2025 10:26:01 +0100 Subject: [PATCH 10/12] Correct backticks ref Replace use of Write-Error/exit with Throw. --- tools/CheckPowershellCompliance.ps1 | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/tools/CheckPowershellCompliance.ps1 b/tools/CheckPowershellCompliance.ps1 index b694604ce4b4..1861cea400d4 100644 --- a/tools/CheckPowershellCompliance.ps1 +++ b/tools/CheckPowershellCompliance.ps1 @@ -5,7 +5,7 @@ # The configuration should look like this: # # ### PSScriptAnalyzer Configuration -# ``` yaml +# ```yaml # targetVersions: # - "5.1" # - "7.0" @@ -17,7 +17,7 @@ function Read-ComplianceConfiguration { $path = "README.md" $configMarker = "### PSScriptAnalyzer Configuration" - $backTicksYaml = '``` yaml' + $backTicksYaml = '```yaml' $backTicks = '```' $readme = Get-Content $path @@ -41,8 +41,7 @@ function Read-ComplianceConfiguration { } if ("" -eq $yaml) { - Write-Error "No PSScriptAnalyzer Configuration found in README.md" - exit 2 + Throw "No PSScriptAnalyzer Configuration found in README.md" } # Parse the YAML. @@ -51,12 +50,10 @@ function Read-ComplianceConfiguration { # Confirm that there is at least one TargetVersion and that there are the # same number of TargetVersions as TargetProfiles. if ($yamlObj.targetVersions.Count -eq 0) { - Write-Error "No TargetVersions found in PSScriptAnalyzer Configuration." - exit 4 + Throw "No TargetVersions found in PSScriptAnalyzer Configuration." } if ($yamlObj.targetVersions.Count -ne $yamlObj.targetProfiles.Count) { - Write-Error "Number of TargetVersions ($($yamlObj.targetVersions.Count)) and TargetProfiles ($($yamlObj.targetprofiles.Count)) do not match." - exit 6 + Throw "Number of TargetVersions ($($yamlObj.targetVersions.Count)) and TargetProfiles ($($yamlObj.targetprofiles.Count)) do not match." } return $yamlObj @@ -94,8 +91,7 @@ function Confirm-Compliance { $problems = $(Get-ChildItem -Path ./custom -Recurse -Include '*.ps1' | Invoke-ScriptAnalyzer -Settings $settings) if ("" -ne $problems) { Write-Output $problems - Write-Error 'ScriptAnalyzer found (possibly back-compatibility) issues.' - exit 5 + Throw 'ScriptAnalyzer found (possibly back-compatibility) issues.' } } @@ -105,8 +101,7 @@ function Confirm-CustomScript { # Get all *.ps1 files in the current directory $scripts = Get-ChildItem -Path ./custom -Recurse -Include '*.ps1' if ($scripts.Length -eq 0) { - Write-Error "No custom scripts found in the repository." - exit 3 + Throw "No custom scripts found in the repository." } } @@ -116,20 +111,17 @@ function Confirm-InAutorestEnv { # Get current working directory then confirm it ends in ".autorest" $cwd = Get-Location if ($cwd -notlike "*.autorest") { - Write-Error "This script should be run from an autorest directory." - exit 1 + Throw "This script should be run from an autorest directory." } } # Confirm that the required modules are installed. if (-not(Get-InstalledModule -Name "powershell-yaml")) { - Write-Error "powershell-yaml module is required. Please install it." - exit 7 + Throw "powershell-yaml module is required. Please install it." } if (-not(Get-InstalledModule -Name PSScriptAnalyzer)) { - Write-Error "PSScriptAnalyzer module is required. Please install it." - exit 7 + Throw "PSScriptAnalyzer module is required. Please install it." } # Run the script. From 97e644d9e8715b8edaede0aa0e37cc0ef135e185 Mon Sep 17 00:00:00 2001 From: "Paul D.Smith" Date: Tue, 27 May 2025 10:28:59 +0100 Subject: [PATCH 11/12] Correct source to show real powershell versions. --- tools/CheckPowershellCompliance.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/CheckPowershellCompliance.ps1 b/tools/CheckPowershellCompliance.ps1 index 1861cea400d4..704981efcd58 100644 --- a/tools/CheckPowershellCompliance.ps1 +++ b/tools/CheckPowershellCompliance.ps1 @@ -10,8 +10,8 @@ # - "5.1" # - "7.0" # targetProfiles: -# - "win-8_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework" -# - "win-8_x64_10.0.14393.0_7.0.0_x64_3.1.2_core" +# - "win-48_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework" +# - "win-4_x64_10.0.18362.0_7.0.0_x64_3.1.2_core" # ``` function Read-ComplianceConfiguration { From e0ace040cc19a5d760aaa2a028ab9dc1f434f8ce Mon Sep 17 00:00:00 2001 From: "Paul D.Smith" Date: Tue, 27 May 2025 10:30:18 +0100 Subject: [PATCH 12/12] Correct backticks. --- src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md index f2440d51d7fa..574ab3d8d08e 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md @@ -88,7 +88,7 @@ directive: ``` ### PSScriptAnalyzer Configuration -``` yaml +```yaml targetVersions: - "5.1" - "7.0"