From b62358986ecf5a27a4c4c859ff633e6a618dc964 Mon Sep 17 00:00:00 2001 From: NoriZC <110961157+NoriZC@users.noreply.github.com> Date: Thu, 15 Jun 2023 16:25:50 +0800 Subject: [PATCH 01/37] Gen code verify (#22080) * test the filechanges.txt location * do updates on Storage generated file * do updates on Storage generated file * try path * test path * test path * convert updated gen --- .azure-pipelines/powershell-core.yml | 61 +++++++++---------- .ci-config.json | 10 +++ .../CIFilterTask.cs | 2 +- tools/ExecuteCIStep.ps1 | 20 ++++++ .../SDKGeneratedCodeVerify.ps1 | 38 ++++++++++++ 5 files changed, 99 insertions(+), 32 deletions(-) create mode 100644 tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 diff --git a/.azure-pipelines/powershell-core.yml b/.azure-pipelines/powershell-core.yml index d6fa669bd240..c3380d56c96c 100644 --- a/.azure-pipelines/powershell-core.yml +++ b/.azure-pipelines/powershell-core.yml @@ -20,7 +20,6 @@ variables: EnableTestCoverage: true TestCoverageLocation: $(Build.SourcesDirectory)/artifacts PowerShellPlatform: PowerShell Core - trigger: none pr: @@ -58,34 +57,34 @@ jobs: testFramework: ${{ variables.TestFramework }} powerShellPlatform: ${{ variables.PowerShellPlatform }} -- job: Test - displayName: Test - dependsOn: Build - condition: succeeded() - timeoutInMinutes: ${{ variables.TestTimeoutInMinutes }} - strategy: - matrix: - windows: - OSName: ${{ variables.WindowsName }} - agentPoolName: ${{ variables.WindowsAgentPoolName }} - agentPoolVMImage: ${{ variables.WindowsAgentPoolVMImage }} - linux: - OSName: ${{ variables.LinuxName }} - agentPoolName: ${{ variables.LinuxAgentPoolName }} - agentPoolVMImage: ${{ variables.LinuxAgentPoolVMImage }} - macOS: - OSName: ${{ variables.MacOSName }} - agentPoolName: ${{ variables.MacOSAgentPoolName }} - agentPoolVMImage: ${{ variables.MacOSAgentPoolVMImage }} - pool: - name: $(agentPoolName) - vmImage: $(agentPoolVMImage) +# - job: Test +# displayName: Test +# dependsOn: Build +# condition: succeeded() +# timeoutInMinutes: ${{ variables.TestTimeoutInMinutes }} +# strategy: +# matrix: +# windows: +# OSName: ${{ variables.WindowsName }} +# agentPoolName: ${{ variables.WindowsAgentPoolName }} +# agentPoolVMImage: ${{ variables.WindowsAgentPoolVMImage }} +# linux: +# OSName: ${{ variables.LinuxName }} +# agentPoolName: ${{ variables.LinuxAgentPoolName }} +# agentPoolVMImage: ${{ variables.LinuxAgentPoolVMImage }} +# macOS: +# OSName: ${{ variables.MacOSName }} +# agentPoolName: ${{ variables.MacOSAgentPoolName }} +# agentPoolVMImage: ${{ variables.MacOSAgentPoolVMImage }} +# pool: +# name: $(agentPoolName) +# vmImage: $(agentPoolVMImage) - steps: - - template: util/test-steps.yml - parameters: - osName: $(OSName) - testFramework: ${{ variables.TestFramework }} - testTarget: ${{ variables.TestTarget }} - configuration: ${{ variables.Configuration }} - powerShellPlatform: ${{ variables.PowerShellPlatform }} +# steps: +# - template: util/test-steps.yml +# parameters: +# osName: $(OSName) +# testFramework: ${{ variables.TestFramework }} +# testTarget: ${{ variables.TestTarget }} +# configuration: ${{ variables.Configuration }} +# powerShellPlatform: ${{ variables.PowerShellPlatform }} diff --git a/.ci-config.json b/.ci-config.json index f0687183431c..7bf4682a861a 100644 --- a/.ci-config.json +++ b/.ci-config.json @@ -1,5 +1,15 @@ { "rules": [ + { + "patterns": [ + "src/{ModuleName}/{ModuleName}.Management.Sdk/Generated/*", + "src/{ModuleName}/{ModuleName}.LegacySdk/Generated/*", + "src/{ModuleName}/{ModuleName}.Sdk/Generated/*" + ], + "phases": [ + "verify-generated-sdk:related-module" + ] + }, { "patterns": [ "src/{ModuleName}/readme.md", diff --git a/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs b/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs index 559ff89c9710..a3c232da1c42 100644 --- a/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs +++ b/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs @@ -70,7 +70,7 @@ public class CIFilterTask : Task private const string BUILD_PHASE = "build"; private const string TEST_PHASE = "test"; - private readonly List ANALYSIS_PHASE_LIST = new List() { "breaking-change", "help-example", "help", "dependency", "signature", "file-change", "ux" }; + private readonly List ANALYSIS_PHASE_LIST = new List() { "breaking-change", "help-example", "help", "dependency", "signature", "file-change", "ux", "verify-generated-sdk" }; private readonly List ONLY_AFFECT_MODULE_PHASE_LIST = new List() { "cmdlet-diff" }; // These phases will be triggered only when the module is modified, not when its dependent module is updated. private const string ACCOUNT_MODULE_NAME = "Accounts"; diff --git a/tools/ExecuteCIStep.ps1 b/tools/ExecuteCIStep.ps1 index 345bc01a8087..b151edd9f741 100644 --- a/tools/ExecuteCIStep.ps1 +++ b/tools/ExecuteCIStep.ps1 @@ -397,6 +397,7 @@ If ($StaticAnalysis) .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisHelp @Parameters .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisUX @Parameters .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisCmdletDiff @Parameters + .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisVerifyGenCode @Parameters Return } @@ -507,3 +508,22 @@ If ($StaticAnalysisCmdletDiff) } Return } + +If ($StaticAnalysisVerifyGenSdk) +{ + If ($PSBoundParameters.ContainsKey("TargetModule")) + { + $VerifyGenSdkModuleList = $TargetModule + } + Else + { + $VerifyGenSdkModuleList = Join-String -Separator ';' -InputObject $CIPlan.'verify-generated-sdk' + } + If ("" -Ne $VerifyGenSdkModuleList) + { + Write-Host "Running static analysis to verify generated sdk..." + .($PSScriptRoot + "/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1") + # dotnet $RepoArtifacts/StaticAnalysis/StaticAnalysis.Netcore.dll -p $RepoArtifacts/$Configuration -r $StaticAnalysisOutputDirectory --analyzers verify-generated-sdk -u -m $VerifyGenSdkModuleList + } + Return +} \ No newline at end of file diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 new file mode 100644 index 000000000000..c710cedf0e1d --- /dev/null +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -0,0 +1,38 @@ +[CmdletBinding()] +param ( + [Parameter(Position=0)] + [string] $FilesChangedPaths = "../../../artifacts/FilesChanged.txt" +) +# All errors should be logged using this function, as it tracks the errors in +# the $errors array, which is used in the finally block of the script to determine +# the return code. +function LogError([string]$message) { + Write-Host -f Red "error: $message" + $script:errors += $message +} +# Extract changed modules who did changes on generated + +$ErrorActionPreference = 'Stop' +# $Env:NODE_OPTIONS = "--max-old-space-size=8192" +Set-StrictMode -Version 1 + +# . (Join-Path $PSScriptRoot\..\common\scripts common.ps1) +# When the input $MarkdownPaths is the path of txt file contained markdown paths + if ((Test-Path $FilesChangedPaths -PathType Leaf) -and $FilesChangedPaths.EndsWith(".txt")) { + $FilesChanged = Get-Content $FilesChangedPaths | Where-Object { ($_ -match "^src\\.*\.Sdk\\.*Generated.*")}# -and (Test-Path $_) } + # Write-Host "FilesChanged:" $FilesChanged + $ChangedModules = New-Object System.Collections.Generic.List[System.Object] + foreach ($_ in $FilesChanged) { + $ChangedModules.Add($_.Substring(0,$_.IndexOf('.Sdk'))+'.Sdk') + } + $ChangedModules = $ChangedModules | select -unique + # Write-Host $ChangedModules "c" + } + # When the input $MarkdownPaths is the path of a folder + else { + LogError "Only accept .txt files." + } + foreach ($_ in $ChangedModules) { + # Filter the .md of overview in "\help\" + Write-Host $_ + } \ No newline at end of file From a2c0ea46275363f07e0482dd5d615a03ec8fd3de Mon Sep 17 00:00:00 2001 From: NoriZC <110961157+NoriZC@users.noreply.github.com> Date: Thu, 15 Jun 2023 21:03:45 +0800 Subject: [PATCH 02/37] Gen code verify (#22085) * test the filechanges.txt location * do updates on Storage generated file * do updates on Storage generated file * try path * test path * test path * convert updated gen * comment test --- .azure-pipelines/windows-powershell.yml | 28 +++++----- tools/ExecuteCIStep.ps1 | 3 +- .../SDKGeneratedCodeVerify.ps1 | 55 ++++++++++++++++++- 3 files changed, 68 insertions(+), 18 deletions(-) diff --git a/.azure-pipelines/windows-powershell.yml b/.azure-pipelines/windows-powershell.yml index 8ca760978415..76e50543fca0 100644 --- a/.azure-pipelines/windows-powershell.yml +++ b/.azure-pipelines/windows-powershell.yml @@ -53,18 +53,18 @@ jobs: testFramework: ${{ variables.TestFramework }} powerShellPlatform: ${{ variables.PowerShellPlatform }} -- job: Test - displayName: Test - dependsOn: Build - condition: and(eq(variables.IsGenerateBased, false), succeeded()) - timeoutInMinutes: 180 - pool: ${{ variables.AgentPoolName }} +# - job: Test +# displayName: Test +# dependsOn: Build +# condition: and(eq(variables.IsGenerateBased, false), succeeded()) +# timeoutInMinutes: 180 +# pool: ${{ variables.AgentPoolName }} - steps: - - template: util/test-steps.yml - parameters: - osName: ${{ variables.WindowsName }} - testFramework: ${{ variables.TestFramework }} - testTarget: ${{ variables.TestTarget }} - configuration: ${{ variables.Configuration }} - powerShellPlatform: ${{ variables.PowerShellPlatform }} +# steps: +# - template: util/test-steps.yml +# parameters: +# osName: ${{ variables.WindowsName }} +# testFramework: ${{ variables.TestFramework }} +# testTarget: ${{ variables.TestTarget }} +# configuration: ${{ variables.Configuration }} +# powerShellPlatform: ${{ variables.PowerShellPlatform }} diff --git a/tools/ExecuteCIStep.ps1 b/tools/ExecuteCIStep.ps1 index b151edd9f741..fded358c47d7 100644 --- a/tools/ExecuteCIStep.ps1 +++ b/tools/ExecuteCIStep.ps1 @@ -522,7 +522,8 @@ If ($StaticAnalysisVerifyGenSdk) If ("" -Ne $VerifyGenSdkModuleList) { Write-Host "Running static analysis to verify generated sdk..." - .($PSScriptRoot + "/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1") + . .($PSScriptRoot + "/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1") + # dotnet $RepoArtifacts/StaticAnalysis/StaticAnalysis.Netcore.dll -p $RepoArtifacts/$Configuration -r $StaticAnalysisOutputDirectory --analyzers verify-generated-sdk -u -m $VerifyGenSdkModuleList } Return diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index c710cedf0e1d..fca10e7c2897 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -6,6 +6,8 @@ param ( # All errors should be logged using this function, as it tracks the errors in # the $errors array, which is used in the finally block of the script to determine # the return code. +[string[]] $errors = @() + function LogError([string]$message) { Write-Host -f Red "error: $message" $script:errors += $message @@ -16,8 +18,10 @@ $ErrorActionPreference = 'Stop' # $Env:NODE_OPTIONS = "--max-old-space-size=8192" Set-StrictMode -Version 1 -# . (Join-Path $PSScriptRoot\..\common\scripts common.ps1) -# When the input $MarkdownPaths is the path of txt file contained markdown paths +try{ + # . (Join-Path $PSScriptRoot\..\common\scripts common.ps1) + # When the input $MarkdownPaths is the path of txt file contained markdown paths + if ((Test-Path $FilesChangedPaths -PathType Leaf) -and $FilesChangedPaths.EndsWith(".txt")) { $FilesChanged = Get-Content $FilesChangedPaths | Where-Object { ($_ -match "^src\\.*\.Sdk\\.*Generated.*")}# -and (Test-Path $_) } # Write-Host "FilesChanged:" $FilesChanged @@ -30,9 +34,54 @@ Set-StrictMode -Version 1 } # When the input $MarkdownPaths is the path of a folder else { + Write-Error "Only accept .txt files as input." + } + foreach ($_ in $ChangedModules) { + # Direct to the Sdk directory + $module = ($_ -split "\/|\\")[1] + Write-Host "Directing to " + $PSScriptRoot + "../" + $_ + cd $PSScriptRoot + "../" + $_ + + # Regenerate the Sdk under Generated folder + Write-Host "Re-generating SDK under Generated folder for $module..." + if( Test-Path -Path "README.md" -PathType Leaf){ + autorest --reset + autorest --use:@microsoft.azure/autorest.csharp@2.3.90 + autorest.cmd README.md --version=v2 + } + else { + LogError "No README file detected." + } + + # See if the code is completely the same as we generated + $changes = git status --porcelain + if (!$changes -eq $null){ + LogError ` + "Generated code for $module is not up to date.` + You may need to rebase on the latest main, ` + re-generate code accroding to README.md file under $_` + " + } + } +} +finally { + Write-Host "" + Write-Host "Summary:" + Write-Host "" + Write-Host " $($errors.Length) error(s)" + Write-Host "" + + foreach ($err in $errors) { + Write-Host -f Red "error : $err" + } + + if ($errors) { + exit 1 + } +} LogError "Only accept .txt files." } foreach ($_ in $ChangedModules) { # Filter the .md of overview in "\help\" Write-Host $_ - } \ No newline at end of file + } From 5c4c4b5ba73ce60ad8ede123dd165d0830b61c5c Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Thu, 15 Jun 2023 21:41:07 +0800 Subject: [PATCH 03/37] add debug log --- tools/ExecuteCIStep.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/ExecuteCIStep.ps1 b/tools/ExecuteCIStep.ps1 index fded358c47d7..55bc556047b3 100644 --- a/tools/ExecuteCIStep.ps1 +++ b/tools/ExecuteCIStep.ps1 @@ -519,6 +519,7 @@ If ($StaticAnalysisVerifyGenSdk) { $VerifyGenSdkModuleList = Join-String -Separator ';' -InputObject $CIPlan.'verify-generated-sdk' } + Write-Host "VerifyGenSdkModuleList" + $VerifyGenSdkModuleList +"mmm" + $PSScriptRoot + "/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1" If ("" -Ne $VerifyGenSdkModuleList) { Write-Host "Running static analysis to verify generated sdk..." From bad134a1b4a72c6f8f862bb0f24342c8630c4ad2 Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Thu, 15 Jun 2023 22:07:24 +0800 Subject: [PATCH 04/37] add debug log --- tools/ExecuteCIStep.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ExecuteCIStep.ps1 b/tools/ExecuteCIStep.ps1 index 55bc556047b3..1a8828396de0 100644 --- a/tools/ExecuteCIStep.ps1 +++ b/tools/ExecuteCIStep.ps1 @@ -397,7 +397,7 @@ If ($StaticAnalysis) .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisHelp @Parameters .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisUX @Parameters .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisCmdletDiff @Parameters - .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisVerifyGenCode @Parameters + .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisVerifyGenSdk @Parameters Return } From ff65c9405142983cdd1fb5d234cdb1f8ce26711e Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Thu, 15 Jun 2023 22:54:21 +0800 Subject: [PATCH 05/37] add debug log --- .ci-config.json | 2 +- .../Microsoft.Azure.Build.Tasks/CIFilterTask.cs | 2 +- tools/ExecuteCIStep.ps1 | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.ci-config.json b/.ci-config.json index 7bf4682a861a..2c15e78b1783 100644 --- a/.ci-config.json +++ b/.ci-config.json @@ -7,7 +7,7 @@ "src/{ModuleName}/{ModuleName}.Sdk/Generated/*" ], "phases": [ - "verify-generated-sdk:related-module" + "verify-gensdk:related-module" ] }, { diff --git a/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs b/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs index a3c232da1c42..d5470062ce9a 100644 --- a/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs +++ b/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs @@ -70,7 +70,7 @@ public class CIFilterTask : Task private const string BUILD_PHASE = "build"; private const string TEST_PHASE = "test"; - private readonly List ANALYSIS_PHASE_LIST = new List() { "breaking-change", "help-example", "help", "dependency", "signature", "file-change", "ux", "verify-generated-sdk" }; + private readonly List ANALYSIS_PHASE_LIST = new List() { "breaking-change", "help-example", "help", "dependency", "signature", "file-change", "ux", "verify-gensdk" }; private readonly List ONLY_AFFECT_MODULE_PHASE_LIST = new List() { "cmdlet-diff" }; // These phases will be triggered only when the module is modified, not when its dependent module is updated. private const string ACCOUNT_MODULE_NAME = "Accounts"; diff --git a/tools/ExecuteCIStep.ps1 b/tools/ExecuteCIStep.ps1 index 1a8828396de0..32861e2795cd 100644 --- a/tools/ExecuteCIStep.ps1 +++ b/tools/ExecuteCIStep.ps1 @@ -62,6 +62,9 @@ Param( [Switch] $StaticAnalysisCmdletDiff, + [Switch] + $StaticAnalysisVerifyGensdk, + [String] $RepoArtifacts='artifacts', @@ -397,7 +400,7 @@ If ($StaticAnalysis) .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisHelp @Parameters .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisUX @Parameters .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisCmdletDiff @Parameters - .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisVerifyGenSdk @Parameters + .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisVerifyGensdk @Parameters Return } @@ -508,16 +511,17 @@ If ($StaticAnalysisCmdletDiff) } Return } - -If ($StaticAnalysisVerifyGenSdk) +write-Host "StaticAnalysisVerifyGensdk $StaticAnalysisVerifyGensdk" +If ($StaticAnalysisVerifyGensdk) { + Write-Host 1 If ($PSBoundParameters.ContainsKey("TargetModule")) { $VerifyGenSdkModuleList = $TargetModule } Else { - $VerifyGenSdkModuleList = Join-String -Separator ';' -InputObject $CIPlan.'verify-generated-sdk' + $VerifyGenSdkModuleList = Join-String -Separator ';' -InputObject $CIPlan.'verify-gensdk' } Write-Host "VerifyGenSdkModuleList" + $VerifyGenSdkModuleList +"mmm" + $PSScriptRoot + "/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1" If ("" -Ne $VerifyGenSdkModuleList) From e7a1d21addc8f649d6e8788e5a87b6e52272c882 Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Thu, 15 Jun 2023 23:24:30 +0800 Subject: [PATCH 06/37] add debug log --- .../Microsoft.Azure.Build.Tasks/CIFilterTask.cs | 3 ++- tools/ExecuteCIStep.ps1 | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs b/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs index d5470062ce9a..2b8bf4707621 100644 --- a/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs +++ b/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs @@ -70,7 +70,8 @@ public class CIFilterTask : Task private const string BUILD_PHASE = "build"; private const string TEST_PHASE = "test"; - private readonly List ANALYSIS_PHASE_LIST = new List() { "breaking-change", "help-example", "help", "dependency", "signature", "file-change", "ux", "verify-gensdk" }; + //private readonly List ANALYSIS_PHASE_LIST = new List() { "breaking-change", "help-example", "help", "dependency", "signature", "file-change", "ux", "verify-gensdk" }; + private readonly List ANALYSIS_PHASE_LIST = new List() { "file-change", "ux", "verify-gensdk" }; private readonly List ONLY_AFFECT_MODULE_PHASE_LIST = new List() { "cmdlet-diff" }; // These phases will be triggered only when the module is modified, not when its dependent module is updated. private const string ACCOUNT_MODULE_NAME = "Accounts"; diff --git a/tools/ExecuteCIStep.ps1 b/tools/ExecuteCIStep.ps1 index 32861e2795cd..c0d83037bf5a 100644 --- a/tools/ExecuteCIStep.ps1 +++ b/tools/ExecuteCIStep.ps1 @@ -527,7 +527,7 @@ If ($StaticAnalysisVerifyGensdk) If ("" -Ne $VerifyGenSdkModuleList) { Write-Host "Running static analysis to verify generated sdk..." - . .($PSScriptRoot + "/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1") + .($PSScriptRoot + "/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1") # dotnet $RepoArtifacts/StaticAnalysis/StaticAnalysis.Netcore.dll -p $RepoArtifacts/$Configuration -r $StaticAnalysisOutputDirectory --analyzers verify-generated-sdk -u -m $VerifyGenSdkModuleList } From fb907263a0e380859ca5a037a5b435c4c1d4df0b Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Thu, 15 Jun 2023 23:44:37 +0800 Subject: [PATCH 07/37] clean --- .../GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index fca10e7c2897..20ccb54cf6af 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -79,9 +79,3 @@ finally { exit 1 } } - LogError "Only accept .txt files." - } - foreach ($_ in $ChangedModules) { - # Filter the .md of overview in "\help\" - Write-Host $_ - } From 56dd38cc2ca9a623b6366aefb86fea10c8435185 Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Fri, 16 Jun 2023 00:08:10 +0800 Subject: [PATCH 08/37] for test --- .../GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index 20ccb54cf6af..bb02d82e6bec 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -1,8 +1,4 @@ -[CmdletBinding()] -param ( - [Parameter(Position=0)] - [string] $FilesChangedPaths = "../../../artifacts/FilesChanged.txt" -) +$FilesChangedPaths = "../../../artifacts/FilesChanged.txt" # All errors should be logged using this function, as it tracks the errors in # the $errors array, which is used in the finally block of the script to determine # the return code. From 4a505987847878d7fe645d2dd344bf3a53366d32 Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Fri, 16 Jun 2023 10:08:28 +0800 Subject: [PATCH 09/37] for test --- .../SDKGeneratedCodeVerify.ps1 | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index bb02d82e6bec..e4a7e796ed21 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -1,4 +1,4 @@ -$FilesChangedPaths = "../../../artifacts/FilesChanged.txt" +$FilesChangedPaths = "$PSScriptRoot/../../../artifacts/FilesChanged.txt" # All errors should be logged using this function, as it tracks the errors in # the $errors array, which is used in the finally block of the script to determine # the return code. @@ -17,7 +17,7 @@ Set-StrictMode -Version 1 try{ # . (Join-Path $PSScriptRoot\..\common\scripts common.ps1) # When the input $MarkdownPaths is the path of txt file contained markdown paths - + Write-Host (Resolve-Path $FilesChangedPaths) if ((Test-Path $FilesChangedPaths -PathType Leaf) -and $FilesChangedPaths.EndsWith(".txt")) { $FilesChanged = Get-Content $FilesChangedPaths | Where-Object { ($_ -match "^src\\.*\.Sdk\\.*Generated.*")}# -and (Test-Path $_) } # Write-Host "FilesChanged:" $FilesChanged @@ -35,20 +35,25 @@ try{ foreach ($_ in $ChangedModules) { # Direct to the Sdk directory $module = ($_ -split "\/|\\")[1] - Write-Host "Directing to " + $PSScriptRoot + "../" + $_ - cd $PSScriptRoot + "../" + $_ + Write-Host "Directing to " $PSScriptRoot/../../../$_ + cd $PSScriptRoot/../../../$_ # Regenerate the Sdk under Generated folder - Write-Host "Re-generating SDK under Generated folder for $module..." + Write-Host (Test-Path -Path "README.md" -PathType Leaf) if( Test-Path -Path "README.md" -PathType Leaf){ + Write-Host "Re-generating SDK under Generated folder for $module..." autorest --reset + Write-Host "1" autorest --use:@microsoft.azure/autorest.csharp@2.3.90 + Write-Host "2" autorest.cmd README.md --version=v2 + Write-Host "3" } else { LogError "No README file detected." } + Write-Host "git status" # See if the code is completely the same as we generated $changes = git status --porcelain if (!$changes -eq $null){ From e3af1d9da279de70c203efdf9b5ff6692b651e65 Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Fri, 16 Jun 2023 17:40:06 +0800 Subject: [PATCH 10/37] friday test --- tools/ExecuteCIStep.ps1 | 2 - tools/PipelineResultTemplate.json | 6 ++ .../CollectStaticAnalysisPipelineResult.ps1 | 4 ++ .../SDKGeneratedCodeVerify.ps1 | 63 ++++++++----------- 4 files changed, 35 insertions(+), 40 deletions(-) diff --git a/tools/ExecuteCIStep.ps1 b/tools/ExecuteCIStep.ps1 index c0d83037bf5a..86e6b9652518 100644 --- a/tools/ExecuteCIStep.ps1 +++ b/tools/ExecuteCIStep.ps1 @@ -528,8 +528,6 @@ If ($StaticAnalysisVerifyGensdk) { Write-Host "Running static analysis to verify generated sdk..." .($PSScriptRoot + "/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1") - - # dotnet $RepoArtifacts/StaticAnalysis/StaticAnalysis.Netcore.dll -p $RepoArtifacts/$Configuration -r $StaticAnalysisOutputDirectory --analyzers verify-generated-sdk -u -m $VerifyGenSdkModuleList } Return } \ No newline at end of file diff --git a/tools/PipelineResultTemplate.json b/tools/PipelineResultTemplate.json index 4f32bf1cef04..e644788aabfb 100644 --- a/tools/PipelineResultTemplate.json +++ b/tools/PipelineResultTemplate.json @@ -47,6 +47,12 @@ "Details": [ ] }, + "verify-gensdk": { + "PhaseName": "Verify Generated Sdk", + "Order": 9, + "Details": [ + ] + }, "test": { "PhaseName": "Test", "Order": 100, diff --git a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 index 7eb1357843ec..cab7a047be5f 100644 --- a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 +++ b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 @@ -71,6 +71,10 @@ $Steps = @( @{ PhaseName = "ux" IssuePath = "$StaticAnalysisOutputDirectory/UXMetadataIssues.csv" + }, + @{ + PhaseName = "phase-x" + IssuePath = "$StaticAnalysisVerifyGensdk/VerifyGensdk.csv" } ) diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index e4a7e796ed21..bc5f74c314aa 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -1,75 +1,62 @@ $FilesChangedPaths = "$PSScriptRoot/../../../artifacts/FilesChanged.txt" + +$errors = New-Object System.Collections.Generic.List[System.Object] # All errors should be logged using this function, as it tracks the errors in # the $errors array, which is used in the finally block of the script to determine # the return code. -[string[]] $errors = @() - function LogError([string]$message) { Write-Host -f Red "error: $message" - $script:errors += $message + $errors.Add($message) } -# Extract changed modules who did changes on generated - -$ErrorActionPreference = 'Stop' -# $Env:NODE_OPTIONS = "--max-old-space-size=8192" -Set-StrictMode -Version 1 try{ - # . (Join-Path $PSScriptRoot\..\common\scripts common.ps1) - # When the input $MarkdownPaths is the path of txt file contained markdown paths - Write-Host (Resolve-Path $FilesChangedPaths) if ((Test-Path $FilesChangedPaths -PathType Leaf) -and $FilesChangedPaths.EndsWith(".txt")) { - $FilesChanged = Get-Content $FilesChangedPaths | Where-Object { ($_ -match "^src\\.*\.Sdk\\.*Generated.*")}# -and (Test-Path $_) } - # Write-Host "FilesChanged:" $FilesChanged - $ChangedModules = New-Object System.Collections.Generic.List[System.Object] + # Read Changedfiles and check if generted sdk code is updated. + $FilesChanged = Get-Content $FilesChangedPaths | Where-Object { ($_ -match "^src\\.*\.Sdk\\.*Generated.*")} + # Collect Sdk paths whose files under Generated folder change. + $ChangedSdks = New-Object System.Collections.Generic.List[System.Object] foreach ($_ in $FilesChanged) { - $ChangedModules.Add($_.Substring(0,$_.IndexOf('.Sdk'))+'.Sdk') + $ChangedSdks.Add($_.Substring(0,$_.IndexOf('.Sdk'))+'.Sdk') } - $ChangedModules = $ChangedModules | select -unique - # Write-Host $ChangedModules "c" + # Remove duplicated Sdks. + $ChangedSdks = $ChangedSdks | select -unique } - # When the input $MarkdownPaths is the path of a folder else { Write-Error "Only accept .txt files as input." } - foreach ($_ in $ChangedModules) { + Write-Host "Preparing Autorest..." + autorest --reset + autorest --use:@microsoft.azure/autorest.csharp@2.3.90 + foreach ($_ in $ChangedSdks) { # Direct to the Sdk directory $module = ($_ -split "\/|\\")[1] - Write-Host "Directing to " $PSScriptRoot/../../../$_ - cd $PSScriptRoot/../../../$_ + Write-Host "Directing to " "$PSScriptRoot/../../../$_" + cd "$PSScriptRoot/../../../$_" # Regenerate the Sdk under Generated folder Write-Host (Test-Path -Path "README.md" -PathType Leaf) if( Test-Path -Path "README.md" -PathType Leaf){ Write-Host "Re-generating SDK under Generated folder for $module..." - autorest --reset - Write-Host "1" - autorest --use:@microsoft.azure/autorest.csharp@2.3.90 - Write-Host "2" autorest.cmd README.md --version=v2 - Write-Host "3" } else { - LogError "No README file detected." + LogError "No README file detected under $_." } - - Write-Host "git status" # See if the code is completely the same as we generated - $changes = git status --porcelain - if (!$changes -eq $null){ - LogError ` - "Generated code for $module is not up to date.` - You may need to rebase on the latest main, ` - re-generate code accroding to README.md file under $_` - " + $changes = git status ".\Generated" --porcelain + if ($changes -ne $null){ + $changes = $changes.replace(" ", "`n") + Write-Host "gitstatus: $changes" + Write-Host "loging error..." + LogError "Generated code for $module is not up to date.`n You may need to rebase on the latest main, regenerate code accroding to README.md file under $_`n" } } } finally { Write-Host "" - Write-Host "Summary:" + Write-Host "Summary:" Write-Host "" - Write-Host " $($errors.Length) error(s)" + Write-Host " $($errors.Count) error(s):" Write-Host "" foreach ($err in $errors) { From 7f9f06d43b3a90bb286f365f785d36d03ee53ffb Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Fri, 16 Jun 2023 18:05:38 +0800 Subject: [PATCH 11/37] friday test --- .../GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index bc5f74c314aa..7fc77086281d 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -25,6 +25,7 @@ try{ Write-Error "Only accept .txt files as input." } Write-Host "Preparing Autorest..." + npm install -g autorest autorest --reset autorest --use:@microsoft.azure/autorest.csharp@2.3.90 foreach ($_ in $ChangedSdks) { From c3800ea43deabde5ec04b578de6f712bfd14e055 Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Fri, 16 Jun 2023 20:05:19 +0800 Subject: [PATCH 12/37] friday test --- .../GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index 7fc77086281d..244bd3fb06f6 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -26,8 +26,11 @@ try{ } Write-Host "Preparing Autorest..." npm install -g autorest + Write-Host "changed1: $ChangedSdks" autorest --reset + Write-Host "changed2: $ChangedSdks" autorest --use:@microsoft.azure/autorest.csharp@2.3.90 + Write-Host "changed3: $ChangedSdks" foreach ($_ in $ChangedSdks) { # Direct to the Sdk directory $module = ($_ -split "\/|\\")[1] From 47d736d51d1ffcf83bd4e6260fb44dc8d797694f Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Fri, 16 Jun 2023 20:08:04 +0800 Subject: [PATCH 13/37] friday test --- .../GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index 244bd3fb06f6..057b4ef4d9a0 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -25,7 +25,7 @@ try{ Write-Error "Only accept .txt files as input." } Write-Host "Preparing Autorest..." - npm install -g autorest + npm install -g autorest@latest Write-Host "changed1: $ChangedSdks" autorest --reset Write-Host "changed2: $ChangedSdks" From 412ed42d52ec1e3a128f12c0417ad3e399388a97 Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Fri, 16 Jun 2023 20:39:40 +0800 Subject: [PATCH 14/37] friday test --- .../GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index 057b4ef4d9a0..08f9bef47cc2 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -13,12 +13,14 @@ try{ if ((Test-Path $FilesChangedPaths -PathType Leaf) -and $FilesChangedPaths.EndsWith(".txt")) { # Read Changedfiles and check if generted sdk code is updated. $FilesChanged = Get-Content $FilesChangedPaths | Where-Object { ($_ -match "^src\\.*\.Sdk\\.*Generated.*")} + Write-Host "changed-1: $FilesChanged" # Collect Sdk paths whose files under Generated folder change. $ChangedSdks = New-Object System.Collections.Generic.List[System.Object] foreach ($_ in $FilesChanged) { $ChangedSdks.Add($_.Substring(0,$_.IndexOf('.Sdk'))+'.Sdk') } # Remove duplicated Sdks. + Write-Host "changed0: $ChangedSdks" $ChangedSdks = $ChangedSdks | select -unique } else { From 695ae9d7beac0f788d7cc505fdf060d4e23fd69a Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Fri, 16 Jun 2023 21:06:25 +0800 Subject: [PATCH 15/37] friday test --- .../GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index 08f9bef47cc2..7d2f4ef8f8fc 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -11,6 +11,7 @@ function LogError([string]$message) { try{ if ((Test-Path $FilesChangedPaths -PathType Leaf) -and $FilesChangedPaths.EndsWith(".txt")) { + Write-Host (Get-Content $FilesChangedPaths) # Read Changedfiles and check if generted sdk code is updated. $FilesChanged = Get-Content $FilesChangedPaths | Where-Object { ($_ -match "^src\\.*\.Sdk\\.*Generated.*")} Write-Host "changed-1: $FilesChanged" From 90f92acc747e52406c09cdc305e567e1bab5a71a Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Fri, 16 Jun 2023 21:22:56 +0800 Subject: [PATCH 16/37] friday test --- .../GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index 7d2f4ef8f8fc..94c2947d9c37 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -13,7 +13,7 @@ try{ if ((Test-Path $FilesChangedPaths -PathType Leaf) -and $FilesChangedPaths.EndsWith(".txt")) { Write-Host (Get-Content $FilesChangedPaths) # Read Changedfiles and check if generted sdk code is updated. - $FilesChanged = Get-Content $FilesChangedPaths | Where-Object { ($_ -match "^src\\.*\.Sdk\\.*Generated.*")} + $FilesChanged = Get-Content $FilesChangedPaths | Where-Object { ($_ -match "^src\/.*\.Sdk\/.*Generated.*")} Write-Host "changed-1: $FilesChanged" # Collect Sdk paths whose files under Generated folder change. $ChangedSdks = New-Object System.Collections.Generic.List[System.Object] From 7503e888a8aa6a8384318ae142ee71d23281d7f4 Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Fri, 16 Jun 2023 22:51:55 +0800 Subject: [PATCH 17/37] friday test --- .../CIFilterTask.cs | 3 +- .../SDKGeneratedCodeVerify.ps1 | 37 +++++++++++++------ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs b/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs index 2b8bf4707621..d5470062ce9a 100644 --- a/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs +++ b/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs @@ -70,8 +70,7 @@ public class CIFilterTask : Task private const string BUILD_PHASE = "build"; private const string TEST_PHASE = "test"; - //private readonly List ANALYSIS_PHASE_LIST = new List() { "breaking-change", "help-example", "help", "dependency", "signature", "file-change", "ux", "verify-gensdk" }; - private readonly List ANALYSIS_PHASE_LIST = new List() { "file-change", "ux", "verify-gensdk" }; + private readonly List ANALYSIS_PHASE_LIST = new List() { "breaking-change", "help-example", "help", "dependency", "signature", "file-change", "ux", "verify-gensdk" }; private readonly List ONLY_AFFECT_MODULE_PHASE_LIST = new List() { "cmdlet-diff" }; // These phases will be triggered only when the module is modified, not when its dependent module is updated. private const string ACCOUNT_MODULE_NAME = "Accounts"; diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index 94c2947d9c37..95e86a06106a 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -1,5 +1,13 @@ -$FilesChangedPaths = "$PSScriptRoot/../../../artifacts/FilesChanged.txt" - +$ArtifactsFolder = "$PSScriptRoot/../../../artifacts" +$FilesChangedPaths = "$ArtifactsFolder/FilesChanged.txt" +$ExceptionFilePath = "$ArtifactsFolder/StaticAnalysisResults/FileChangeIssue.csv" +Class GeneratedSdkIssue { + [String]$Module + [Int]$Severity + [String]$Description + [String]$Remediation +} +$ExceptionList = @() $errors = New-Object System.Collections.Generic.List[System.Object] # All errors should be logged using this function, as it tracks the errors in # the $errors array, which is used in the finally block of the script to determine @@ -14,14 +22,12 @@ try{ Write-Host (Get-Content $FilesChangedPaths) # Read Changedfiles and check if generted sdk code is updated. $FilesChanged = Get-Content $FilesChangedPaths | Where-Object { ($_ -match "^src\/.*\.Sdk\/.*Generated.*")} - Write-Host "changed-1: $FilesChanged" # Collect Sdk paths whose files under Generated folder change. $ChangedSdks = New-Object System.Collections.Generic.List[System.Object] foreach ($_ in $FilesChanged) { $ChangedSdks.Add($_.Substring(0,$_.IndexOf('.Sdk'))+'.Sdk') } # Remove duplicated Sdks. - Write-Host "changed0: $ChangedSdks" $ChangedSdks = $ChangedSdks | select -unique } else { @@ -29,25 +35,28 @@ try{ } Write-Host "Preparing Autorest..." npm install -g autorest@latest - Write-Host "changed1: $ChangedSdks" autorest --reset - Write-Host "changed2: $ChangedSdks" autorest --use:@microsoft.azure/autorest.csharp@2.3.90 - Write-Host "changed3: $ChangedSdks" foreach ($_ in $ChangedSdks) { # Direct to the Sdk directory - $module = ($_ -split "\/|\\")[1] + $ModuleName = ($_ -split "\/|\\")[1] Write-Host "Directing to " "$PSScriptRoot/../../../$_" cd "$PSScriptRoot/../../../$_" # Regenerate the Sdk under Generated folder Write-Host (Test-Path -Path "README.md" -PathType Leaf) if( Test-Path -Path "README.md" -PathType Leaf){ - Write-Host "Re-generating SDK under Generated folder for $module..." + Write-Host "Re-generating SDK under Generated folder for $ModuleName..." autorest.cmd README.md --version=v2 } else { LogError "No README file detected under $_." + $ExceptionList += [GeneratedSdkIssue]@{ + Module = $ModuleName; + Severity = 2; + Description = "No README file detected under $_." + Remediation = "Make sure that the ReadMe file of Sdk is loaded." + } } # See if the code is completely the same as we generated $changes = git status ".\Generated" --porcelain @@ -55,7 +64,13 @@ try{ $changes = $changes.replace(" ", "`n") Write-Host "gitstatus: $changes" Write-Host "loging error..." - LogError "Generated code for $module is not up to date.`n You may need to rebase on the latest main, regenerate code accroding to README.md file under $_`n" + LogError "Generated code for $ModuleName is not up to date.`n You may need to rebase on the latest main, regenerate code accroding to README.md file under $_`n" + $ExceptionList += [GeneratedSdkIssue]@{ + Module = Az.$ModuleName; + Severity = 1; + Description = "Generated code for $ModuleName is not up to date or you have updated generated Sdk." + Remediation = "You may need to rebase on the latest main, regenerate code accroding to README.md file under $_, and make sure no more updates based on generated files." + } } } } @@ -71,6 +86,6 @@ finally { } if ($errors) { - exit 1 + $ExceptionList | Sort-Object -Unique -Property Module,Description | Export-Csv $ExceptionFilePath -NoTypeInformation } } From a1bc21e1c08e41e4f0d6b43f2ccd919df38ba9c6 Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Sat, 17 Jun 2023 13:49:41 +0800 Subject: [PATCH 18/37] friday test --- .../GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index 95e86a06106a..5576200c11e5 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -66,7 +66,7 @@ try{ Write-Host "loging error..." LogError "Generated code for $ModuleName is not up to date.`n You may need to rebase on the latest main, regenerate code accroding to README.md file under $_`n" $ExceptionList += [GeneratedSdkIssue]@{ - Module = Az.$ModuleName; + Module = $ModuleName; Severity = 1; Description = "Generated code for $ModuleName is not up to date or you have updated generated Sdk." Remediation = "You may need to rebase on the latest main, regenerate code accroding to README.md file under $_, and make sure no more updates based on generated files." From be5090b6541e640c50539e962756bf8d57c52e93 Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Sat, 17 Jun 2023 15:40:41 +0800 Subject: [PATCH 19/37] Saturday test --- tools/ExecuteCIStep.ps1 | 4 +- .../SDKGeneratedCodeVerify.ps1 | 47 ++++++++++++------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/tools/ExecuteCIStep.ps1 b/tools/ExecuteCIStep.ps1 index 86e6b9652518..f96dca6ac3e9 100644 --- a/tools/ExecuteCIStep.ps1 +++ b/tools/ExecuteCIStep.ps1 @@ -511,10 +511,9 @@ If ($StaticAnalysisCmdletDiff) } Return } -write-Host "StaticAnalysisVerifyGensdk $StaticAnalysisVerifyGensdk" + If ($StaticAnalysisVerifyGensdk) { - Write-Host 1 If ($PSBoundParameters.ContainsKey("TargetModule")) { $VerifyGenSdkModuleList = $TargetModule @@ -523,7 +522,6 @@ If ($StaticAnalysisVerifyGensdk) { $VerifyGenSdkModuleList = Join-String -Separator ';' -InputObject $CIPlan.'verify-gensdk' } - Write-Host "VerifyGenSdkModuleList" + $VerifyGenSdkModuleList +"mmm" + $PSScriptRoot + "/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1" If ("" -Ne $VerifyGenSdkModuleList) { Write-Host "Running static analysis to verify generated sdk..." diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index 5576200c11e5..05e60d428afb 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -1,21 +1,38 @@ +# ---------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost If the code +# is regenerated. +# ---------------------------------------------------------------------------------- + $ArtifactsFolder = "$PSScriptRoot/../../../artifacts" $FilesChangedPaths = "$ArtifactsFolder/FilesChanged.txt" $ExceptionFilePath = "$ArtifactsFolder/StaticAnalysisResults/FileChangeIssue.csv" + Class GeneratedSdkIssue { [String]$Module [Int]$Severity [String]$Description [String]$Remediation } + $ExceptionList = @() -$errors = New-Object System.Collections.Generic.List[System.Object] -# All errors should be logged using this function, as it tracks the errors in -# the $errors array, which is used in the finally block of the script to determine -# the return code. -function LogError([string]$message) { - Write-Host -f Red "error: $message" - $errors.Add($message) -} +# $errors = New-Object System.Collections.Generic.List[System.Object] +# # All errors should be logged using this function, as it tracks the errors in +# # the $errors array, which is used in the finally block of the script to determine +# # the return code. +# function LogError([string]$message) { +# Write-Host -f Red "error: $message" +# $errors.Add($message) +# } try{ if ((Test-Path $FilesChangedPaths -PathType Leaf) -and $FilesChangedPaths.EndsWith(".txt")) { @@ -50,7 +67,7 @@ try{ autorest.cmd README.md --version=v2 } else { - LogError "No README file detected under $_." + # LogError "No README file detected under $_." $ExceptionList += [GeneratedSdkIssue]@{ Module = $ModuleName; Severity = 2; @@ -62,9 +79,7 @@ try{ $changes = git status ".\Generated" --porcelain if ($changes -ne $null){ $changes = $changes.replace(" ", "`n") - Write-Host "gitstatus: $changes" - Write-Host "loging error..." - LogError "Generated code for $ModuleName is not up to date.`n You may need to rebase on the latest main, regenerate code accroding to README.md file under $_`n" + # LogError "Generated code for $ModuleName is not up to date.`n You may need to rebase on the latest main, regenerate code accroding to README.md file under $_`n" $ExceptionList += [GeneratedSdkIssue]@{ Module = $ModuleName; Severity = 1; @@ -78,14 +93,14 @@ finally { Write-Host "" Write-Host "Summary:" Write-Host "" - Write-Host " $($errors.Count) error(s):" + Write-Host " $($ExceptionList.Length) error(s):" Write-Host "" - foreach ($err in $errors) { - Write-Host -f Red "error : $err" + foreach ($err in $ExceptionList) { + Write-Host -f Red "error : " $err.Description " " $err.Remediation } - if ($errors) { + if ($ExceptionList.Length -ne 0) { $ExceptionList | Sort-Object -Unique -Property Module,Description | Export-Csv $ExceptionFilePath -NoTypeInformation } } From 9a39259e83f95974d6612245407f4fb69fee56fd Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Sat, 17 Jun 2023 16:10:19 +0800 Subject: [PATCH 20/37] Add ux --- .../CollectStaticAnalysisPipelineResult.ps1 | 6 +++--- .../SDKGeneratedCodeVerify.ps1 | 21 +++++-------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 index cab7a047be5f..0d299ec91abb 100644 --- a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 +++ b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 @@ -73,8 +73,8 @@ $Steps = @( IssuePath = "$StaticAnalysisOutputDirectory/UXMetadataIssues.csv" }, @{ - PhaseName = "phase-x" - IssuePath = "$StaticAnalysisVerifyGensdk/VerifyGensdk.csv" + PhaseName = "verify-gensdk" + IssuePath = "$StaticAnalysisOutputDirectory/VerifyGensdk.csv" } ) @@ -141,7 +141,7 @@ ForEach ($Step In $Steps) { $MatchedIssues = $Issues | Where-Object { $_.Module -Eq $ModuleName } If ($MatchedIssues.Length -Ne 0) { #Region generate table head of each step - $NormalSteps = [System.Collections.Generic.HashSet[String]]@("breaking-change", "help", "signature", "file-change") + $NormalSteps = [System.Collections.Generic.HashSet[String]]@("breaking-change", "help", "signature", "file-change", "verify-gensdk") If ($NormalSteps.Contains($PhaseName)) { $Content = "|Type|Cmdlet|Description|Remediation|`n|---|---|---|---|`n" } diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index 05e60d428afb..ac2cdf2755af 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -15,7 +15,7 @@ $ArtifactsFolder = "$PSScriptRoot/../../../artifacts" $FilesChangedPaths = "$ArtifactsFolder/FilesChanged.txt" -$ExceptionFilePath = "$ArtifactsFolder/StaticAnalysisResults/FileChangeIssue.csv" +$ExceptionFilePath = "$ArtifactsFolder/StaticAnalysisResults/VerifyGenSdk.csv" Class GeneratedSdkIssue { [String]$Module @@ -25,18 +25,9 @@ Class GeneratedSdkIssue { } $ExceptionList = @() -# $errors = New-Object System.Collections.Generic.List[System.Object] -# # All errors should be logged using this function, as it tracks the errors in -# # the $errors array, which is used in the finally block of the script to determine -# # the return code. -# function LogError([string]$message) { -# Write-Host -f Red "error: $message" -# $errors.Add($message) -# } try{ if ((Test-Path $FilesChangedPaths -PathType Leaf) -and $FilesChangedPaths.EndsWith(".txt")) { - Write-Host (Get-Content $FilesChangedPaths) # Read Changedfiles and check if generted sdk code is updated. $FilesChanged = Get-Content $FilesChangedPaths | Where-Object { ($_ -match "^src\/.*\.Sdk\/.*Generated.*")} # Collect Sdk paths whose files under Generated folder change. @@ -55,19 +46,18 @@ try{ autorest --reset autorest --use:@microsoft.azure/autorest.csharp@2.3.90 foreach ($_ in $ChangedSdks) { - # Direct to the Sdk directory + # Extract Module Name $ModuleName = ($_ -split "\/|\\")[1] + # Direct to the Sdk directory Write-Host "Directing to " "$PSScriptRoot/../../../$_" cd "$PSScriptRoot/../../../$_" # Regenerate the Sdk under Generated folder - Write-Host (Test-Path -Path "README.md" -PathType Leaf) if( Test-Path -Path "README.md" -PathType Leaf){ Write-Host "Re-generating SDK under Generated folder for $ModuleName..." autorest.cmd README.md --version=v2 } else { - # LogError "No README file detected under $_." $ExceptionList += [GeneratedSdkIssue]@{ Module = $ModuleName; Severity = 2; @@ -79,7 +69,6 @@ try{ $changes = git status ".\Generated" --porcelain if ($changes -ne $null){ $changes = $changes.replace(" ", "`n") - # LogError "Generated code for $ModuleName is not up to date.`n You may need to rebase on the latest main, regenerate code accroding to README.md file under $_`n" $ExceptionList += [GeneratedSdkIssue]@{ Module = $ModuleName; Severity = 1; @@ -93,11 +82,11 @@ finally { Write-Host "" Write-Host "Summary:" Write-Host "" - Write-Host " $($ExceptionList.Length) error(s):" + Write-Host " $($ExceptionList.Length) error(s) detected while verifying generated sdk:" Write-Host "" foreach ($err in $ExceptionList) { - Write-Host -f Red "error : " $err.Description " " $err.Remediation + Write-Host -f Red "error : " $err.Description "`n " $err.Remediation } if ($ExceptionList.Length -ne 0) { From 74b2a95746e635243581d0c3a460db0e8ec5d919 Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Sat, 17 Jun 2023 16:36:55 +0800 Subject: [PATCH 21/37] Uncomment test steps --- .azure-pipelines/powershell-core.yml | 61 +++++++++++++------------ .azure-pipelines/windows-powershell.yml | 28 ++++++------ 2 files changed, 45 insertions(+), 44 deletions(-) diff --git a/.azure-pipelines/powershell-core.yml b/.azure-pipelines/powershell-core.yml index c3380d56c96c..d6fa669bd240 100644 --- a/.azure-pipelines/powershell-core.yml +++ b/.azure-pipelines/powershell-core.yml @@ -20,6 +20,7 @@ variables: EnableTestCoverage: true TestCoverageLocation: $(Build.SourcesDirectory)/artifacts PowerShellPlatform: PowerShell Core + trigger: none pr: @@ -57,34 +58,34 @@ jobs: testFramework: ${{ variables.TestFramework }} powerShellPlatform: ${{ variables.PowerShellPlatform }} -# - job: Test -# displayName: Test -# dependsOn: Build -# condition: succeeded() -# timeoutInMinutes: ${{ variables.TestTimeoutInMinutes }} -# strategy: -# matrix: -# windows: -# OSName: ${{ variables.WindowsName }} -# agentPoolName: ${{ variables.WindowsAgentPoolName }} -# agentPoolVMImage: ${{ variables.WindowsAgentPoolVMImage }} -# linux: -# OSName: ${{ variables.LinuxName }} -# agentPoolName: ${{ variables.LinuxAgentPoolName }} -# agentPoolVMImage: ${{ variables.LinuxAgentPoolVMImage }} -# macOS: -# OSName: ${{ variables.MacOSName }} -# agentPoolName: ${{ variables.MacOSAgentPoolName }} -# agentPoolVMImage: ${{ variables.MacOSAgentPoolVMImage }} -# pool: -# name: $(agentPoolName) -# vmImage: $(agentPoolVMImage) +- job: Test + displayName: Test + dependsOn: Build + condition: succeeded() + timeoutInMinutes: ${{ variables.TestTimeoutInMinutes }} + strategy: + matrix: + windows: + OSName: ${{ variables.WindowsName }} + agentPoolName: ${{ variables.WindowsAgentPoolName }} + agentPoolVMImage: ${{ variables.WindowsAgentPoolVMImage }} + linux: + OSName: ${{ variables.LinuxName }} + agentPoolName: ${{ variables.LinuxAgentPoolName }} + agentPoolVMImage: ${{ variables.LinuxAgentPoolVMImage }} + macOS: + OSName: ${{ variables.MacOSName }} + agentPoolName: ${{ variables.MacOSAgentPoolName }} + agentPoolVMImage: ${{ variables.MacOSAgentPoolVMImage }} + pool: + name: $(agentPoolName) + vmImage: $(agentPoolVMImage) -# steps: -# - template: util/test-steps.yml -# parameters: -# osName: $(OSName) -# testFramework: ${{ variables.TestFramework }} -# testTarget: ${{ variables.TestTarget }} -# configuration: ${{ variables.Configuration }} -# powerShellPlatform: ${{ variables.PowerShellPlatform }} + steps: + - template: util/test-steps.yml + parameters: + osName: $(OSName) + testFramework: ${{ variables.TestFramework }} + testTarget: ${{ variables.TestTarget }} + configuration: ${{ variables.Configuration }} + powerShellPlatform: ${{ variables.PowerShellPlatform }} diff --git a/.azure-pipelines/windows-powershell.yml b/.azure-pipelines/windows-powershell.yml index 76e50543fca0..8ca760978415 100644 --- a/.azure-pipelines/windows-powershell.yml +++ b/.azure-pipelines/windows-powershell.yml @@ -53,18 +53,18 @@ jobs: testFramework: ${{ variables.TestFramework }} powerShellPlatform: ${{ variables.PowerShellPlatform }} -# - job: Test -# displayName: Test -# dependsOn: Build -# condition: and(eq(variables.IsGenerateBased, false), succeeded()) -# timeoutInMinutes: 180 -# pool: ${{ variables.AgentPoolName }} +- job: Test + displayName: Test + dependsOn: Build + condition: and(eq(variables.IsGenerateBased, false), succeeded()) + timeoutInMinutes: 180 + pool: ${{ variables.AgentPoolName }} -# steps: -# - template: util/test-steps.yml -# parameters: -# osName: ${{ variables.WindowsName }} -# testFramework: ${{ variables.TestFramework }} -# testTarget: ${{ variables.TestTarget }} -# configuration: ${{ variables.Configuration }} -# powerShellPlatform: ${{ variables.PowerShellPlatform }} + steps: + - template: util/test-steps.yml + parameters: + osName: ${{ variables.WindowsName }} + testFramework: ${{ variables.TestFramework }} + testTarget: ${{ variables.TestTarget }} + configuration: ${{ variables.Configuration }} + powerShellPlatform: ${{ variables.PowerShellPlatform }} From 5280ad333f43d61b3bd5cc1df0f7afc97118ab85 Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Tue, 27 Jun 2023 19:44:15 +0800 Subject: [PATCH 22/37] Resolve comments --- .../CollectStaticAnalysisPipelineResult.ps1 | 7 +- .../SDKGeneratedCodeVerify.ps1 | 12 ++- .../GeneratedSdkAnalyzer/VerifyGenSdkIssue.cs | 77 +++++++++++++++++++ .../IssueChecker/IssueChecker.cs | 2 + 4 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 tools/StaticAnalysis/GeneratedSdkAnalyzer/VerifyGenSdkIssue.cs diff --git a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 index 0d299ec91abb..84eb7c2218d5 100644 --- a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 +++ b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 @@ -74,7 +74,7 @@ $Steps = @( }, @{ PhaseName = "verify-gensdk" - IssuePath = "$StaticAnalysisOutputDirectory/VerifyGensdk.csv" + IssuePath = "$StaticAnalysisOutputDirectory/VerifyGensdkIssues.csv" } ) @@ -141,7 +141,7 @@ ForEach ($Step In $Steps) { $MatchedIssues = $Issues | Where-Object { $_.Module -Eq $ModuleName } If ($MatchedIssues.Length -Ne 0) { #Region generate table head of each step - $NormalSteps = [System.Collections.Generic.HashSet[String]]@("breaking-change", "help", "signature", "file-change", "verify-gensdk") + $NormalSteps = [System.Collections.Generic.HashSet[String]]@("breaking-change", "help", "signature", "file-change") If ($NormalSteps.Contains($PhaseName)) { $Content = "|Type|Cmdlet|Description|Remediation|`n|---|---|---|---|`n" } @@ -151,6 +151,9 @@ ForEach ($Step In $Steps) { ElseIf ($PhaseName -Eq "ux") { $Content = "|Type|Module|ResourceType|SubResourceType|Command|Description|`n|---|---|---|---|---|---|`n" } + ElseIf ($PhaseName -Eq "verify-gensdk") { + $Content = "|Type|Module|Sdk|Description|Remediation|`n|---|---|---|---|---|`n" + } #EndRegion ForEach ($Issue In $MatchedIssues) { diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index ac2cdf2755af..7aea50e676ca 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -15,10 +15,11 @@ $ArtifactsFolder = "$PSScriptRoot/../../../artifacts" $FilesChangedPaths = "$ArtifactsFolder/FilesChanged.txt" -$ExceptionFilePath = "$ArtifactsFolder/StaticAnalysisResults/VerifyGenSdk.csv" +$ExceptionFilePath = "$ArtifactsFolder/StaticAnalysisResults/VerifyGenSdkIssues.csv" Class GeneratedSdkIssue { [String]$Module + [String]$Sdk [Int]$Severity [String]$Description [String]$Remediation @@ -39,7 +40,8 @@ try{ $ChangedSdks = $ChangedSdks | select -unique } else { - Write-Error "Only accept .txt files as input." + Write-Warning "Only accept .txt files as input." + return } Write-Host "Preparing Autorest..." npm install -g autorest@latest @@ -60,7 +62,8 @@ try{ else { $ExceptionList += [GeneratedSdkIssue]@{ Module = $ModuleName; - Severity = 2; + Sdk = $_; + Severity = 1; Description = "No README file detected under $_." Remediation = "Make sure that the ReadMe file of Sdk is loaded." } @@ -71,6 +74,7 @@ try{ $changes = $changes.replace(" ", "`n") $ExceptionList += [GeneratedSdkIssue]@{ Module = $ModuleName; + Sdk = $_; Severity = 1; Description = "Generated code for $ModuleName is not up to date or you have updated generated Sdk." Remediation = "You may need to rebase on the latest main, regenerate code accroding to README.md file under $_, and make sure no more updates based on generated files." @@ -90,6 +94,6 @@ finally { } if ($ExceptionList.Length -ne 0) { - $ExceptionList | Sort-Object -Unique -Property Module,Description | Export-Csv $ExceptionFilePath -NoTypeInformation + $ExceptionList | Sort-Object -Unique -Property Module,Sdk,Description | Export-Csv $ExceptionFilePath -NoTypeInformation } } diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/VerifyGenSdkIssue.cs b/tools/StaticAnalysis/GeneratedSdkAnalyzer/VerifyGenSdkIssue.cs new file mode 100644 index 000000000000..31438f0f9b3d --- /dev/null +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/VerifyGenSdkIssue.cs @@ -0,0 +1,77 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Text.RegularExpressions; +using Tools.Common.Issues; + +namespace StaticAnalysis.GeneratedSdkAnalyzer +{ + public class VerifyGenSdkIssue : IReportRecord + { + /// + /// The module containing the generated sdk issue + /// + public string Module { get; set; } + /// + /// The associated sdk of the module. + /// + public string Sdk { get; set; } + public string Description { get; set; } + public string Remediation { get; set; } + public int Severity { get; set; } + public string PrintHeaders() + { + return "\"Module\",\"Sdk\",\"Severity\",\"Description\",\"Remediation\""; + } + + public string FormatRecord() + { + return string.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\"", + Module, Sdk, Severity, Description, Remediation); + } + + public bool Match(IReportRecord other) + { + var result = false; + var record = other as VerifyGenSdkIssue; + if (record != null) + { + result = string.Equals(record.Module, Module, StringComparison.OrdinalIgnoreCase) && + string.Equals(record.Sdk, Sdk, StringComparison.OrdinalIgnoreCase) && + string.Equals(record.Description, Description, StringComparison.OrdinalIgnoreCase); + } + + return result; + } + + public IReportRecord Parse(string line) + { + var matcher = "\"([^\"]*)\",\"([^\"]*)\",\"([^\"]+)\",\"([^\"]*)\",\"([^\"]*)\""; + var match = Regex.Match(line, matcher); + if (!match.Success || match.Groups.Count < 6) + { + throw new InvalidOperationException(string.Format("Could not parse '{0}' as VerifyGenSdkIssue record", line)); + } + + Module = match.Groups[1].Value; + Sdk = match.Groups[2].Value; + Severity = int.Parse(match.Groups[3].Value); + // ProblemId = int.Parse(match.Groups[5].Value); + Description = match.Groups[4].Value; + Remediation = match.Groups[5].Value; + return this; + } + } +} diff --git a/tools/StaticAnalysis/IssueChecker/IssueChecker.cs b/tools/StaticAnalysis/IssueChecker/IssueChecker.cs index 4614528536b5..2997fe191616 100644 --- a/tools/StaticAnalysis/IssueChecker/IssueChecker.cs +++ b/tools/StaticAnalysis/IssueChecker/IssueChecker.cs @@ -27,6 +27,7 @@ using StaticAnalysis.SignatureVerifier; using StaticAnalysis.ExampleAnalyzer; using StaticAnalysis.UXMetadataAnalyzer; +using StaticAnalysis.GeneratedSdkAnalyzer; namespace StaticAnalysis.IssueChecker { @@ -43,6 +44,7 @@ public class IssueChecker : IStaticAnalyzer ("SignatureIssues.csv", typeof(SignatureIssue).FullName), ("ExampleIssues.csv", typeof(ExampleIssue).FullName), ("UXMetadataIssues.csv", typeof(UXMetadataIssue).FullName), + ("VerifyGenSdkIssues.csv", typeof(VerifyGenSdkIssue).FullName) }; public AnalysisLogger Logger { get; set; } From e95a6a3a4568e60393c500e51eae469d6bf106d8 Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Tue, 27 Jun 2023 22:43:01 +0800 Subject: [PATCH 23/37] Resolve comments --- .../CollectStaticAnalysisPipelineResult.ps1 | 3 +++ .../SDKGeneratedCodeVerify.ps1 | 5 +++++ .../GeneratedSdkAnalyzer/VerifyGenSdkIssue.cs | 18 ++++++++++-------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 index 84eb7c2218d5..29b6e84fddca 100644 --- a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 +++ b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 @@ -173,6 +173,9 @@ ForEach ($Step In $Steps) { ElseIf ($PhaseName -Eq "ux") { $Content += "|$ErrorTypeEmoji|$($Issue.Module)|$($Issue.ResourceType)|$($Issue.SubResourceType)|$($Issue.Command)|$($Issue.Description)|`n" } + ElseIf ($PhaseName -Eq "verify-gensdk") { + $Content += "|$ErrorTypeEmoji|$($Issue.Module)|$($Issue.Sdk)|$($Issue.Description)|$($Issue.Remediation)|`n" + } #EndRegion } $ModuleInfo.Content = $Content diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index 7aea50e676ca..dc7863f2ca71 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -21,12 +21,15 @@ Class GeneratedSdkIssue { [String]$Module [String]$Sdk [Int]$Severity + [Int]$ProblemId [String]$Description [String]$Remediation } $ExceptionList = @() +$MissReadMe = 9000 +$GenSdkChanged = 9090 try{ if ((Test-Path $FilesChangedPaths -PathType Leaf) -and $FilesChangedPaths.EndsWith(".txt")) { # Read Changedfiles and check if generted sdk code is updated. @@ -64,6 +67,7 @@ try{ Module = $ModuleName; Sdk = $_; Severity = 1; + ProblemId = $MissReadMe; Description = "No README file detected under $_." Remediation = "Make sure that the ReadMe file of Sdk is loaded." } @@ -76,6 +80,7 @@ try{ Module = $ModuleName; Sdk = $_; Severity = 1; + ProblemId = $GenSdkChanged Description = "Generated code for $ModuleName is not up to date or you have updated generated Sdk." Remediation = "You may need to rebase on the latest main, regenerate code accroding to README.md file under $_, and make sure no more updates based on generated files." } diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/VerifyGenSdkIssue.cs b/tools/StaticAnalysis/GeneratedSdkAnalyzer/VerifyGenSdkIssue.cs index 31438f0f9b3d..c5b25a6ce6f7 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/VerifyGenSdkIssue.cs +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/VerifyGenSdkIssue.cs @@ -28,18 +28,19 @@ public class VerifyGenSdkIssue : IReportRecord /// The associated sdk of the module. /// public string Sdk { get; set; } + public int ProblemId { get; set; } public string Description { get; set; } public string Remediation { get; set; } public int Severity { get; set; } public string PrintHeaders() { - return "\"Module\",\"Sdk\",\"Severity\",\"Description\",\"Remediation\""; + return "\"Module\",\"Sdk\",\"Severity\",\"ProblemId\",\"Description\",\"Remediation\""; } public string FormatRecord() { return string.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\"", - Module, Sdk, Severity, Description, Remediation); + Module, Sdk, Severity, ProblemId, Description, Remediation); } public bool Match(IReportRecord other) @@ -50,7 +51,8 @@ public bool Match(IReportRecord other) { result = string.Equals(record.Module, Module, StringComparison.OrdinalIgnoreCase) && string.Equals(record.Sdk, Sdk, StringComparison.OrdinalIgnoreCase) && - string.Equals(record.Description, Description, StringComparison.OrdinalIgnoreCase); + string.Equals(record.Description, Description, StringComparison.OrdinalIgnoreCase)&& + record.ProblemId == ProblemId; } return result; @@ -58,9 +60,9 @@ public bool Match(IReportRecord other) public IReportRecord Parse(string line) { - var matcher = "\"([^\"]*)\",\"([^\"]*)\",\"([^\"]+)\",\"([^\"]*)\",\"([^\"]*)\""; + var matcher = "\"([^\"]*)\",\"([^\"]*)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]*)\",\"([^\"]*)\""; var match = Regex.Match(line, matcher); - if (!match.Success || match.Groups.Count < 6) + if (!match.Success || match.Groups.Count < 7) { throw new InvalidOperationException(string.Format("Could not parse '{0}' as VerifyGenSdkIssue record", line)); } @@ -68,9 +70,9 @@ public IReportRecord Parse(string line) Module = match.Groups[1].Value; Sdk = match.Groups[2].Value; Severity = int.Parse(match.Groups[3].Value); - // ProblemId = int.Parse(match.Groups[5].Value); - Description = match.Groups[4].Value; - Remediation = match.Groups[5].Value; + ProblemId = int.Parse(match.Groups[4].Value); + Description = match.Groups[5].Value; + Remediation = match.Groups[6].Value; return this; } } From 473350ad77cd9b1be27139f450ec19a5070bb806 Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Wed, 28 Jun 2023 13:00:32 +0800 Subject: [PATCH 24/37] Resolve comments --- .ci-config.json | 2 +- .../GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.ci-config.json b/.ci-config.json index 2c15e78b1783..60685db8042f 100644 --- a/.ci-config.json +++ b/.ci-config.json @@ -7,7 +7,7 @@ "src/{ModuleName}/{ModuleName}.Sdk/Generated/*" ], "phases": [ - "verify-gensdk:related-module" + "verify-gensdk:module" ] }, { diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index dc7863f2ca71..72ac183624be 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -87,6 +87,9 @@ try{ } } } +catch [] { + "Caught an error." +} finally { Write-Host "" Write-Host "Summary:" @@ -102,3 +105,4 @@ finally { $ExceptionList | Sort-Object -Unique -Property Module,Sdk,Description | Export-Csv $ExceptionFilePath -NoTypeInformation } } +return \ No newline at end of file From 4c07174457ab73a139701eefb63ebd0dbda4df69 Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Wed, 28 Jun 2023 13:14:58 +0800 Subject: [PATCH 25/37] Resolve comments --- .../GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index 72ac183624be..1fa73741e18b 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -87,7 +87,7 @@ try{ } } } -catch [] { +catch{ "Caught an error." } finally { From 8482aded73eb44f1d29984798d6eaf3571a17fb7 Mon Sep 17 00:00:00 2001 From: wyunchi-ms Date: Wed, 28 Jun 2023 13:54:19 +0800 Subject: [PATCH 26/37] Test for unknown exception --- .../SDKGeneratedCodeVerify.ps1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index 1fa73741e18b..8f07b00a155c 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -27,6 +27,7 @@ Class GeneratedSdkIssue { } $ExceptionList = @() +$SavePath = $PWD $MissReadMe = 9000 $GenSdkChanged = 9090 @@ -49,7 +50,6 @@ try{ Write-Host "Preparing Autorest..." npm install -g autorest@latest autorest --reset - autorest --use:@microsoft.azure/autorest.csharp@2.3.90 foreach ($_ in $ChangedSdks) { # Extract Module Name $ModuleName = ($_ -split "\/|\\")[1] @@ -60,7 +60,8 @@ try{ # Regenerate the Sdk under Generated folder if( Test-Path -Path "README.md" -PathType Leaf){ Write-Host "Re-generating SDK under Generated folder for $ModuleName..." - autorest.cmd README.md --version=v2 + autorest --use:@microsoft.azure/autorest.csharp@2.3.90 + autorest README.md --version=v2 } else { $ExceptionList += [GeneratedSdkIssue]@{ @@ -85,12 +86,8 @@ try{ Remediation = "You may need to rebase on the latest main, regenerate code accroding to README.md file under $_, and make sure no more updates based on generated files." } } + Set-Location $SavePath } -} -catch{ - "Caught an error." -} -finally { Write-Host "" Write-Host "Summary:" Write-Host "" @@ -105,4 +102,7 @@ finally { $ExceptionList | Sort-Object -Unique -Property Module,Sdk,Description | Export-Csv $ExceptionFilePath -NoTypeInformation } } +catch{ + Write-Host "Caught an error." +} return \ No newline at end of file From cbacc5efa2e98a7afc198c1f965711428a989b08 Mon Sep 17 00:00:00 2001 From: wyunchi-ms Date: Wed, 28 Jun 2023 14:09:44 +0800 Subject: [PATCH 27/37] Test for unknown exception --- .../SDKGeneratedCodeVerify.ps1 | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index 8f07b00a155c..c42c2b25bd7c 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -88,21 +88,21 @@ try{ } Set-Location $SavePath } - Write-Host "" - Write-Host "Summary:" - Write-Host "" - Write-Host " $($ExceptionList.Length) error(s) detected while verifying generated sdk:" - Write-Host "" + # Write-Host "" + # Write-Host "Summary:" + # Write-Host "" + # Write-Host " $($ExceptionList.Length) error(s) detected while verifying generated sdk:" + # Write-Host "" - foreach ($err in $ExceptionList) { - Write-Host -f Red "error : " $err.Description "`n " $err.Remediation - } + # foreach ($err in $ExceptionList) { + # Write-Host -f Red "error : " $err.Description "`n " $err.Remediation + # } - if ($ExceptionList.Length -ne 0) { - $ExceptionList | Sort-Object -Unique -Property Module,Sdk,Description | Export-Csv $ExceptionFilePath -NoTypeInformation - } + # if ($ExceptionList.Length -ne 0) { + # $ExceptionList | Sort-Object -Unique -Property Module,Sdk,Description | Export-Csv $ExceptionFilePath -NoTypeInformation + # } } catch{ Write-Host "Caught an error." } -return \ No newline at end of file +exit 0 \ No newline at end of file From 7e91eaade5aced41bd832d1f3c59d3f6c637f385 Mon Sep 17 00:00:00 2001 From: wyunchi-ms Date: Wed, 28 Jun 2023 14:12:04 +0800 Subject: [PATCH 28/37] Test for unknown exception --- tools/ExecuteCIStep.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/ExecuteCIStep.ps1 b/tools/ExecuteCIStep.ps1 index f96dca6ac3e9..5ff6ac6e782d 100644 --- a/tools/ExecuteCIStep.ps1 +++ b/tools/ExecuteCIStep.ps1 @@ -525,7 +525,8 @@ If ($StaticAnalysisVerifyGensdk) If ("" -Ne $VerifyGenSdkModuleList) { Write-Host "Running static analysis to verify generated sdk..." - .($PSScriptRoot + "/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1") + $result = .($PSScriptRoot + "/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1") + Write-Host "Static analysis to verify generated sdk result: $result" } Return } \ No newline at end of file From 5c7e6153443c2e87b4e69d610d0485f5813877b1 Mon Sep 17 00:00:00 2001 From: wyunchi-ms Date: Wed, 28 Jun 2023 14:29:42 +0800 Subject: [PATCH 29/37] Test for unknown exception --- .../SDKGeneratedCodeVerify.ps1 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index c42c2b25bd7c..c51f1d288ab7 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -88,19 +88,19 @@ try{ } Set-Location $SavePath } - # Write-Host "" - # Write-Host "Summary:" - # Write-Host "" - # Write-Host " $($ExceptionList.Length) error(s) detected while verifying generated sdk:" - # Write-Host "" + Write-Host "" + Write-Host "Summary:" + Write-Host "" + Write-Host " $($ExceptionList.Length) error(s) detected while verifying generated sdk:" + Write-Host "" # foreach ($err in $ExceptionList) { # Write-Host -f Red "error : " $err.Description "`n " $err.Remediation # } - # if ($ExceptionList.Length -ne 0) { - # $ExceptionList | Sort-Object -Unique -Property Module,Sdk,Description | Export-Csv $ExceptionFilePath -NoTypeInformation - # } + if ($ExceptionList.Length -ne 0) { + $ExceptionList | Sort-Object -Unique -Property Module,Sdk,Description | Export-Csv $ExceptionFilePath -NoTypeInformation + } } catch{ Write-Host "Caught an error." From fdf003d5cfd3458421606622103df8b7a39c1b17 Mon Sep 17 00:00:00 2001 From: wyunchi-ms Date: Wed, 28 Jun 2023 14:55:33 +0800 Subject: [PATCH 30/37] Test for unknown exception --- .../SDKGeneratedCodeVerify.ps1 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index c51f1d288ab7..f824b06e620e 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -88,21 +88,22 @@ try{ } Set-Location $SavePath } +} +catch{ + Write-Host "Caught an error." +} +finally { Write-Host "" Write-Host "Summary:" Write-Host "" Write-Host " $($ExceptionList.Length) error(s) detected while verifying generated sdk:" Write-Host "" - # foreach ($err in $ExceptionList) { - # Write-Host -f Red "error : " $err.Description "`n " $err.Remediation - # } + foreach ($err in $ExceptionList) { + Write-Host "error : " $err.Description "`n " $err.Remediation + } if ($ExceptionList.Length -ne 0) { $ExceptionList | Sort-Object -Unique -Property Module,Sdk,Description | Export-Csv $ExceptionFilePath -NoTypeInformation } } -catch{ - Write-Host "Caught an error." -} -exit 0 \ No newline at end of file From e100154bfbefc9e27c487e68c1ffb14f228d94ff Mon Sep 17 00:00:00 2001 From: wyunchi-ms Date: Wed, 28 Jun 2023 15:18:27 +0800 Subject: [PATCH 31/37] Test for unknown exception --- .../GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index f824b06e620e..5e8ed7a33511 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -99,9 +99,9 @@ finally { Write-Host " $($ExceptionList.Length) error(s) detected while verifying generated sdk:" Write-Host "" - foreach ($err in $ExceptionList) { - Write-Host "error : " $err.Description "`n " $err.Remediation - } + # foreach ($err in $ExceptionList) { + # Write-Host "error : " $err.Description "`n " $err.Remediation + # } if ($ExceptionList.Length -ne 0) { $ExceptionList | Sort-Object -Unique -Property Module,Sdk,Description | Export-Csv $ExceptionFilePath -NoTypeInformation From b3256d5d06e0f0836ebcc5175b3319cc9de85368 Mon Sep 17 00:00:00 2001 From: wyunchi-ms Date: Wed, 28 Jun 2023 15:57:42 +0800 Subject: [PATCH 32/37] Test for unknown exception --- tools/StaticAnalysis/ReportRecordFactory.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/StaticAnalysis/ReportRecordFactory.cs b/tools/StaticAnalysis/ReportRecordFactory.cs index 27432a2293ee..efaa9690b810 100644 --- a/tools/StaticAnalysis/ReportRecordFactory.cs +++ b/tools/StaticAnalysis/ReportRecordFactory.cs @@ -68,6 +68,10 @@ public static IReportRecord Create(string type) { return new UXMetadataIssue(); } + if (type.Equals(typeof(VerifyGenSdkIssue).FullName)) + { + return new VerifyGenSdkIssue(); + } return null; } From b1c96d67865a167bc220f5be4a083d3d12544943 Mon Sep 17 00:00:00 2001 From: wyunchi-ms Date: Wed, 28 Jun 2023 16:04:22 +0800 Subject: [PATCH 33/37] Test for unknown exception --- tools/StaticAnalysis/ReportRecordFactory.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/StaticAnalysis/ReportRecordFactory.cs b/tools/StaticAnalysis/ReportRecordFactory.cs index efaa9690b810..06c32d9b0312 100644 --- a/tools/StaticAnalysis/ReportRecordFactory.cs +++ b/tools/StaticAnalysis/ReportRecordFactory.cs @@ -19,6 +19,7 @@ using StaticAnalysis.SignatureVerifier; using StaticAnalysis.ExampleAnalyzer; using StaticAnalysis.UXMetadataAnalyzer; +using StaticAnalysis.GeneratedSdkAnalyzer; using System; using System.Collections.Generic; From 70ebe96c1fe30ddd3f0f164dece244dda27248e9 Mon Sep 17 00:00:00 2001 From: wyunchi-ms Date: Thu, 29 Jun 2023 09:59:48 +0800 Subject: [PATCH 34/37] Test for unknown exception --- tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 index 29b6e84fddca..03b2c1111715 100644 --- a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 +++ b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 @@ -74,7 +74,7 @@ $Steps = @( }, @{ PhaseName = "verify-gensdk" - IssuePath = "$StaticAnalysisOutputDirectory/VerifyGensdkIssues.csv" + IssuePath = "$StaticAnalysisOutputDirectory/VerifyGenSdkIssues.csv" } ) From f42c8c4fb8762324259c9d9078b5d5e337ed6445 Mon Sep 17 00:00:00 2001 From: wyunchi-ms Date: Thu, 29 Jun 2023 10:20:03 +0800 Subject: [PATCH 35/37] Test for unknown exception --- tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 index 03b2c1111715..fd92f602ec77 100644 --- a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 +++ b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 @@ -120,6 +120,9 @@ ForEach ($Step In $Steps) { } Else { $Issues = @() + Write-Host "==============================" + Write-Host "No issues for $PhaseName" + Write-Host "==============================" } ForEach ($ModuleInfo In $Details.Modules) { $ModuleName = $ModuleInfo.Module From efaea4e06b197af7eec07cbc4b01176ff79c6db8 Mon Sep 17 00:00:00 2001 From: wyunchi-ms Date: Thu, 29 Jun 2023 10:36:33 +0800 Subject: [PATCH 36/37] Test for unknown exception --- tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 | 3 --- .../GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 index fd92f602ec77..03b2c1111715 100644 --- a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 +++ b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 @@ -120,9 +120,6 @@ ForEach ($Step In $Steps) { } Else { $Issues = @() - Write-Host "==============================" - Write-Host "No issues for $PhaseName" - Write-Host "==============================" } ForEach ($ModuleInfo In $Details.Modules) { $ModuleName = $ModuleInfo.Module diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index 5e8ed7a33511..14222921d2ae 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -52,7 +52,7 @@ try{ autorest --reset foreach ($_ in $ChangedSdks) { # Extract Module Name - $ModuleName = ($_ -split "\/|\\")[1] + $ModuleName = "Az." + ($_ -split "\/|\\")[1] # Direct to the Sdk directory Write-Host "Directing to " "$PSScriptRoot/../../../$_" cd "$PSScriptRoot/../../../$_" From 1960ca7fea19b10f756bf34990c7f2d84ddea390 Mon Sep 17 00:00:00 2001 From: Nori Zhang Date: Fri, 30 Jun 2023 16:26:51 +0800 Subject: [PATCH 37/37] Rename generated sdk verification step in Static Analysis --- .ci-config.json | 2 +- .../Microsoft.Azure.Build.Tasks/CIFilterTask.cs | 2 +- tools/ExecuteCIStep.ps1 | 12 ++++++------ tools/PipelineResultTemplate.json | 4 ++-- .../CollectStaticAnalysisPipelineResult.ps1 | 8 ++++---- .../{VerifyGenSdkIssue.cs => GeneratedSdkIssue.cs} | 6 +++--- .../GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 | 2 +- tools/StaticAnalysis/IssueChecker/IssueChecker.cs | 2 +- tools/StaticAnalysis/ReportRecordFactory.cs | 4 ++-- 9 files changed, 21 insertions(+), 21 deletions(-) rename tools/StaticAnalysis/GeneratedSdkAnalyzer/{VerifyGenSdkIssue.cs => GeneratedSdkIssue.cs} (94%) diff --git a/.ci-config.json b/.ci-config.json index 60685db8042f..f6dfa5f8afa0 100644 --- a/.ci-config.json +++ b/.ci-config.json @@ -7,7 +7,7 @@ "src/{ModuleName}/{ModuleName}.Sdk/Generated/*" ], "phases": [ - "verify-gensdk:module" + "generated-sdk:module" ] }, { diff --git a/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs b/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs index d5470062ce9a..beefa8a2ba70 100644 --- a/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs +++ b/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs @@ -70,7 +70,7 @@ public class CIFilterTask : Task private const string BUILD_PHASE = "build"; private const string TEST_PHASE = "test"; - private readonly List ANALYSIS_PHASE_LIST = new List() { "breaking-change", "help-example", "help", "dependency", "signature", "file-change", "ux", "verify-gensdk" }; + private readonly List ANALYSIS_PHASE_LIST = new List() { "breaking-change", "help-example", "help", "dependency", "signature", "file-change", "ux", "generated-sdk" }; private readonly List ONLY_AFFECT_MODULE_PHASE_LIST = new List() { "cmdlet-diff" }; // These phases will be triggered only when the module is modified, not when its dependent module is updated. private const string ACCOUNT_MODULE_NAME = "Accounts"; diff --git a/tools/ExecuteCIStep.ps1 b/tools/ExecuteCIStep.ps1 index 5ff6ac6e782d..a9608a768572 100644 --- a/tools/ExecuteCIStep.ps1 +++ b/tools/ExecuteCIStep.ps1 @@ -63,7 +63,7 @@ Param( $StaticAnalysisCmdletDiff, [Switch] - $StaticAnalysisVerifyGensdk, + $StaticAnalysisGeneratedSdk, [String] $RepoArtifacts='artifacts', @@ -400,7 +400,7 @@ If ($StaticAnalysis) .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisHelp @Parameters .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisUX @Parameters .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisCmdletDiff @Parameters - .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisVerifyGensdk @Parameters + .("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisGeneratedSdk @Parameters Return } @@ -512,17 +512,17 @@ If ($StaticAnalysisCmdletDiff) Return } -If ($StaticAnalysisVerifyGensdk) +If ($StaticAnalysisGeneratedSdk) { If ($PSBoundParameters.ContainsKey("TargetModule")) { - $VerifyGenSdkModuleList = $TargetModule + $GeneratedSdkModuleList = $TargetModule } Else { - $VerifyGenSdkModuleList = Join-String -Separator ';' -InputObject $CIPlan.'verify-gensdk' + $GeneratedSdkModuleList = Join-String -Separator ';' -InputObject $CIPlan.'generated-sdk' } - If ("" -Ne $VerifyGenSdkModuleList) + If ("" -Ne $GeneratedSdkModuleList) { Write-Host "Running static analysis to verify generated sdk..." $result = .($PSScriptRoot + "/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1") diff --git a/tools/PipelineResultTemplate.json b/tools/PipelineResultTemplate.json index e644788aabfb..9ebe250999f9 100644 --- a/tools/PipelineResultTemplate.json +++ b/tools/PipelineResultTemplate.json @@ -47,8 +47,8 @@ "Details": [ ] }, - "verify-gensdk": { - "PhaseName": "Verify Generated Sdk", + "generated-sdk": { + "PhaseName": "Generated Sdk Check", "Order": 9, "Details": [ ] diff --git a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 index df5f9ed4affa..81e1e86db479 100644 --- a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 +++ b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 @@ -73,8 +73,8 @@ $Steps = @( IssuePath = "$StaticAnalysisOutputDirectory/UXMetadataIssues.csv" }, @{ - PhaseName = "verify-gensdk" - IssuePath = "$StaticAnalysisOutputDirectory/VerifyGenSdkIssues.csv + PhaseName = "generated-sdk" + IssuePath = "$StaticAnalysisOutputDirectory/GeneratedSdkIssues.csv" } ) @@ -151,7 +151,7 @@ ForEach ($Step In $Steps) { ElseIf ($PhaseName -Eq "ux") { $Content = "|Type|Module|ResourceType|SubResourceType|Command|Description|`n|---|---|---|---|---|---|`n" } - ElseIf ($PhaseName -Eq "verify-gensdk") { + ElseIf ($PhaseName -Eq "generated-sdk") { $Content = "|Type|Module|Sdk|Description|Remediation|`n|---|---|---|---|---|`n" } #EndRegion @@ -173,7 +173,7 @@ ForEach ($Step In $Steps) { ElseIf ($PhaseName -Eq "ux") { $Content += "|$ErrorTypeEmoji|$($Issue.Module)|$($Issue.ResourceType)|$($Issue.SubResourceType)|$($Issue.Command)|$($Issue.Description)|`n" } - ElseIf ($PhaseName -Eq "verify-gensdk") { + ElseIf ($PhaseName -Eq "generated-sdk") { $Content += "|$ErrorTypeEmoji|$($Issue.Module)|$($Issue.Sdk)|$($Issue.Description)|$($Issue.Remediation)|`n" } #EndRegion diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/VerifyGenSdkIssue.cs b/tools/StaticAnalysis/GeneratedSdkAnalyzer/GeneratedSdkIssue.cs similarity index 94% rename from tools/StaticAnalysis/GeneratedSdkAnalyzer/VerifyGenSdkIssue.cs rename to tools/StaticAnalysis/GeneratedSdkAnalyzer/GeneratedSdkIssue.cs index c5b25a6ce6f7..0f8e2efacfd0 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/VerifyGenSdkIssue.cs +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/GeneratedSdkIssue.cs @@ -18,7 +18,7 @@ namespace StaticAnalysis.GeneratedSdkAnalyzer { - public class VerifyGenSdkIssue : IReportRecord + public class GeneratedSdkIssue : IReportRecord { /// /// The module containing the generated sdk issue @@ -46,7 +46,7 @@ public string FormatRecord() public bool Match(IReportRecord other) { var result = false; - var record = other as VerifyGenSdkIssue; + var record = other as GeneratedSdkIssue; if (record != null) { result = string.Equals(record.Module, Module, StringComparison.OrdinalIgnoreCase) && @@ -64,7 +64,7 @@ public IReportRecord Parse(string line) var match = Regex.Match(line, matcher); if (!match.Success || match.Groups.Count < 7) { - throw new InvalidOperationException(string.Format("Could not parse '{0}' as VerifyGenSdkIssue record", line)); + throw new InvalidOperationException(string.Format("Could not parse '{0}' as GeneratedSdkIssue record", line)); } Module = match.Groups[1].Value; diff --git a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 index 89acd0fcd493..e5bd816d5d46 100644 --- a/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 +++ b/tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1 @@ -15,7 +15,7 @@ $ArtifactsFolder = "$PSScriptRoot/../../../artifacts" $FilesChangedPaths = "$ArtifactsFolder/FilesChanged.txt" -$ExceptionFilePath = "$ArtifactsFolder/StaticAnalysisResults/VerifyGenSdkIssues.csv" +$ExceptionFilePath = "$ArtifactsFolder/StaticAnalysisResults/GeneratedSdkIssues.csv" Class GeneratedSdkIssue { [String]$Module diff --git a/tools/StaticAnalysis/IssueChecker/IssueChecker.cs b/tools/StaticAnalysis/IssueChecker/IssueChecker.cs index 2997fe191616..6acb64322e7d 100644 --- a/tools/StaticAnalysis/IssueChecker/IssueChecker.cs +++ b/tools/StaticAnalysis/IssueChecker/IssueChecker.cs @@ -44,7 +44,7 @@ public class IssueChecker : IStaticAnalyzer ("SignatureIssues.csv", typeof(SignatureIssue).FullName), ("ExampleIssues.csv", typeof(ExampleIssue).FullName), ("UXMetadataIssues.csv", typeof(UXMetadataIssue).FullName), - ("VerifyGenSdkIssues.csv", typeof(VerifyGenSdkIssue).FullName) + ("GeneratedSdkIssues.csv", typeof(GeneratedSdkIssue).FullName) }; public AnalysisLogger Logger { get; set; } diff --git a/tools/StaticAnalysis/ReportRecordFactory.cs b/tools/StaticAnalysis/ReportRecordFactory.cs index 06c32d9b0312..5ee968aad3e5 100644 --- a/tools/StaticAnalysis/ReportRecordFactory.cs +++ b/tools/StaticAnalysis/ReportRecordFactory.cs @@ -69,9 +69,9 @@ public static IReportRecord Create(string type) { return new UXMetadataIssue(); } - if (type.Equals(typeof(VerifyGenSdkIssue).FullName)) + if (type.Equals(typeof(GeneratedSdkIssue).FullName)) { - return new VerifyGenSdkIssue(); + return new GeneratedSdkIssue(); } return null;