From fb0c4bf2c79e29ac556cc4f685c83cf44b6a9489 Mon Sep 17 00:00:00 2001 From: wyunchi-ms Date: Thu, 3 Nov 2022 17:02:00 +0800 Subject: [PATCH 1/7] Add logic for necessary change check --- .ci-config.json | 6 +- build.proj | 7 +- .../CIFilterTask.cs | 6 ++ tools/PipelineResultTemplate.json | 6 ++ .../CollectStaticAnalysisPipelineResult.ps1 | 9 ++- .../Test-NecessaryChange.ps1 | 74 +++++++++++++++++++ 6 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 tools/StaticAnalysis/NecessaryChangeAnalyzer/Test-NecessaryChange.ps1 diff --git a/.ci-config.json b/.ci-config.json index 97dff94565e2..818dd2ad2240 100644 --- a/.ci-config.json +++ b/.ci-config.json @@ -99,7 +99,8 @@ "phases": [ "build:related-module", "dependence:dependence-module", - "test:dependence-module" + "test:dependence-module", + "necessary-change:module" ] }, { @@ -111,7 +112,8 @@ "breaking-change:module", "help:module", "signature:module", - "test:dependence-module" + "test:dependence-module", + "necessary-change:module" ] }, { diff --git a/build.proj b/build.proj index fd4abd30e3db..5491245e2ff0 100644 --- a/build.proj +++ b/build.proj @@ -268,7 +268,12 @@ - + + + + + + diff --git a/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs b/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs index ae551ab2b11d..02f8df900e8d 100644 --- a/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs +++ b/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs @@ -74,6 +74,7 @@ public class CIFilterTask : Task private const string ANALYSIS_HELP_PHASE = "help"; private const string ANALYSIS_DEPENDENCY_PHASE = "dependency"; private const string ANALYSIS_SIGNATURE_PHASE = "signature"; + private const string ANALYSIS_NECESSARY_CHANGE_PHASE = "necessary-change"; private const string TEST_PHASE = "test"; private const string ACCOUNT_MODULE_NAME = "Accounts"; @@ -190,6 +191,7 @@ private bool ProcessTargetModule(Dictionary csprojMap) [ANALYSIS_HELP_EXAMPLE_PHASE] = new HashSet(GetDependenceModuleList(TargetModule, csprojMap).ToList()), [ANALYSIS_HELP_PHASE] = new HashSet(GetDependenceModuleList(TargetModule, csprojMap).ToList()), [ANALYSIS_SIGNATURE_PHASE] = new HashSet(GetDependenceModuleList(TargetModule, csprojMap).ToList()), + [ANALYSIS_NECESSARY_CHANGE_PHASE] = new HashSet(GetDependenceModuleList(TargetModule, csprojMap).ToList()), [TEST_PHASE] = new HashSet(GetTestCsprojList(TargetModule, csprojMap).ToList()) }; @@ -245,6 +247,7 @@ private Dictionary> CalculateInfluencedModuleInfoForEach ANALYSIS_HELP_EXAMPLE_PHASE + ":" + AllModule, ANALYSIS_HELP_PHASE + ":" + AllModule, ANALYSIS_SIGNATURE_PHASE + ":" + AllModule, + ANALYSIS_NECESSARY_CHANGE_PHASE + ":" + AllModule, TEST_PHASE + ":" + AllModule, }; } @@ -293,6 +296,7 @@ private Dictionary> CalculateInfluencedModuleInfoForEach ANALYSIS_HELP_EXAMPLE_PHASE, ANALYSIS_HELP_PHASE, ANALYSIS_SIGNATURE_PHASE, + ANALYSIS_NECESSARY_CHANGE_PHASE, TEST_PHASE }; foreach (string phaseName in expectedKeyList) @@ -413,6 +417,7 @@ private bool ProcessFileChanged(Dictionary csprojMap) [ANALYSIS_HELP_EXAMPLE_PHASE] = influencedModuleInfo[ANALYSIS_HELP_EXAMPLE_PHASE], [ANALYSIS_HELP_PHASE] = influencedModuleInfo[ANALYSIS_HELP_PHASE], [ANALYSIS_SIGNATURE_PHASE] = influencedModuleInfo[ANALYSIS_SIGNATURE_PHASE], + [ANALYSIS_NECESSARY_CHANGE_PHASE] = influencedModuleInfo[ANALYSIS_NECESSARY_CHANGE_PHASE], [TEST_PHASE] = new HashSet(influencedModuleInfo[TEST_PHASE].Select(GetModuleNameFromPath).Where(x => x != null)) }; File.WriteAllText(Path.Combine(config.ArtifactPipelineInfoFolder, "CIPlan.json"), JsonConvert.SerializeObject(CIPlan, Formatting.Indented)); @@ -463,6 +468,7 @@ public override bool Execute() [ANALYSIS_HELP_EXAMPLE_PHASE] = new HashSet(selectedModuleList), [ANALYSIS_HELP_PHASE] = new HashSet(selectedModuleList), [ANALYSIS_SIGNATURE_PHASE] = new HashSet(selectedModuleList), + [ANALYSIS_HELP_EXAMPLE_PHASE] = new HashSet(selectedModuleList), [TEST_PHASE] = new HashSet(selectedModuleList) }; FilterTaskResult.PhaseInfo = CalculateCsprojForBuildAndTest(influencedModuleInfo, csprojMap); diff --git a/tools/PipelineResultTemplate.json b/tools/PipelineResultTemplate.json index 6b4f7ee2a478..ff42176d61e2 100644 --- a/tools/PipelineResultTemplate.json +++ b/tools/PipelineResultTemplate.json @@ -29,6 +29,12 @@ "Details": [ ] }, + "necessary-change": { + "Name": "Necessary Change Check", + "Order": 6, + "Details": [ + ] + }, "test": { "Name": "Test", "Order": 100, diff --git a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 index 971e69f5653d..1be6e16c2f1e 100644 --- a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 +++ b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 @@ -65,6 +65,10 @@ $Steps = @( @{ StepName = "signature" IssuePath = "$StaticAnalysisOutputDirectory/SignatureIssues.csv" + }, + @{ + StepName = "necessary-change" + IssuePath = "$StaticAnalysisOutputDirectory/NecessaryChangeIssue.csv" } ) @@ -102,7 +106,8 @@ ForEach ($Step In $Steps) If ($MatchedIssues.Length -Ne 0) { #Region generate table head of each step - If (($StepName -Eq "breaking-change") -Or ($StepName -Eq "help") -Or ($StepName -Eq "signature")) + $NormalSteps = [System.Collections.Generic.HashSet[String]]@("breaking-change", "help", "signature", "necessary-change") + If ($NormalSteps.Contains($StepName)) { $Content = "|Type|Cmdlet|Description|Remediation|`n|---|---|---|---|`n" } @@ -123,7 +128,7 @@ ForEach ($Step In $Steps) $ErrorTypeEmoji = "⚠️" } #Region generate table content of each step - If (($StepName -Eq "breaking-change") -Or ($StepName -Eq "help") -Or ($StepName -Eq "signature")) + If ($NormalSteps.Contains($StepName)) { $Content += "|$ErrorTypeEmoji|$($Issue.Target)|$($Issue.Description)|$($Issue.Remediation)|`n" } diff --git a/tools/StaticAnalysis/NecessaryChangeAnalyzer/Test-NecessaryChange.ps1 b/tools/StaticAnalysis/NecessaryChangeAnalyzer/Test-NecessaryChange.ps1 new file mode 100644 index 000000000000..5a05df1c409e --- /dev/null +++ b/tools/StaticAnalysis/NecessaryChangeAnalyzer/Test-NecessaryChange.ps1 @@ -0,0 +1,74 @@ +# ---------------------------------------------------------------------------------- +# 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. +# ---------------------------------------------------------------------------------- + +Param ( +) + +Class NecessaryChangeIssue { + [String]$Module + [Int]$Severity + [String]$Description + [String]$Remediation +} +$ExceptionList = @() + +$FilesChangedPath = "$PSScriptRoot/../../../artifacts/FilesChanged.txt" +$FilesChanged = Get-Content $FilesChangedPath +$ExceptionFilePath = "$PSScriptRoot/../../../artifacts/StaticAnalysisResults/NecessaryChangeIssue.csv" +$UpdatedChangeLogs = @{} + +ForEach ($FilePath In ($FilesChanged | Where-Object { $_.EndsWith("ChangeLog.md") })) +{ + $ModuleName = $FilePath.Split("/")[1] + $UpdatedChangeLogs.Add($ModuleName, $FilePath) +} + +ForEach ($FilePath In $FilesChanged) +{ + If ($FilePath.StartsWith("src/")) + { + $ModuleName = $FilePath.Split("/")[1] + $FileTypeArray = @(".cs", ".psd1", ".csproj", ".json") + ForEach ($FileType In $FileTypeArray) + { + If ($FilePath.EndsWith($FileType)) + { + If (-Not ($UpdatedChangeLogs.ContainsKey($ModuleName))) + { + $ExceptionList += [NecessaryChangeIssue]@{ + Module = "Az.$ModuleName"; + Severity = 2; + Description = "A update of `ChangeLog.md` is necessary if you want a new version of Az.$ModuleName." + Remediation = "Add a changelog record under `Upcoming Release` section with past tense." + } + } + } + } + + If ($FilePath.EndsWith("AssemblyInfo.cs")) + { + $ModuleName = $FilePath.Split("/")[1] + $ExceptionList += [NecessaryChangeIssue]@{ + Module = "Az.$ModuleName"; + Severity = 2; + Description = "We will update AssemblyInfo.cs automaticlly. Please donot update it manually." + Remediation = "Revert AssemblyInfo.cs to last version." + } + } + } +} + +If ($ExceptionList.Length -Ne 0) +{ + $ExceptionList | Sort-Object -Unique -Property Module,Description | Export-Csv $ExceptionFilePath -NoTypeInformation +} \ No newline at end of file From 62a095f444ad0ed332889420935125976c1cbb44 Mon Sep 17 00:00:00 2001 From: wyunchi-ms Date: Fri, 4 Nov 2022 13:47:22 +0800 Subject: [PATCH 2/7] Remove tools/CheckChangeLog.ps1 --- tools/CheckChangeLog.ps1 | 108 --------------------------------------- 1 file changed, 108 deletions(-) delete mode 100644 tools/CheckChangeLog.ps1 diff --git a/tools/CheckChangeLog.ps1 b/tools/CheckChangeLog.ps1 deleted file mode 100644 index e119638ced0f..000000000000 --- a/tools/CheckChangeLog.ps1 +++ /dev/null @@ -1,108 +0,0 @@ -[CmdletBinding()] -Param -( - [Parameter()] - [string]$FilesChanged -) - -$PathsToCheck = @("src") - -$PathStringsToIgnore = @( - "Test", - ".sln", - "Nuget.config", - ".psd1", - "Netcore", - "Stack" -) -Write-Host "Files changed: $FilesChanged" -$FilesChangedList = @() -while ($true) -{ - $Idx = $FilesChanged.IndexOf(";") - if ($Idx -lt 0) - { - $FilesChangedList += $FilesChanged - break - } - - $TempFile = $FilesChanged.Substring(0, $Idx) - Write-Host "Adding '$TempFile' to 'FilesChangedList'" - $FilesChangedList += $TempFile - $FilesChanged = $FilesChanged.Substring($Idx + 1) -} - -if ([string]::IsNullOrEmpty($FilesChanged) -or ($FilesChangedList.Count -eq 300)) -{ - Write-Host "The list of files changed is empty or is past the 300 file limit; skipping check for change log entry" - return -} - -$ChangeLogs = $FilesChangedList | where { $_ -like "*ChangeLog.md*" } -$UpdatedServicePaths = New-Object System.Collections.Generic.HashSet[string] -foreach ($ChangeLog in $ChangeLogs) -{ - if ($ChangeLog -eq "ChangeLog.md") - { - continue - } - elseif ($ChangeLog -like "src/ServiceManagement*") - { - $UpdatedServicePaths.Add("src/ServiceManagement") | Out-Null - } - elseif ($ChangeLog -like "src/Storage*") - { - $UpdatedServicePaths.Add("src/Storage") | Out-Null - } - else - { - # Handle to construct a string like "src/{{service}}" - $SplitPath = @() - while ($true) - { - $Idx = $ChangeLog.IndexOf("/") - if ($Idx -lt 0) - { - $SplitPath += $ChangeLog - break - } - - $TempPath = $ChangeLog.Substring(0, $Idx) - Write-Host "Adding '$TempPath' to 'SplitPath'" - $SplitPath += $TempPath - $ChangeLog = $ChangeLog.Substring($Idx + 1) - } - - $BasePath = $SplitPath[0],$SplitPath[1],$SplitPath[2] -join "/" - Write-Host "Change log '$ChangeLog' processed to base path '$BasePath'" - $UpdatedServicePaths.Add($BasePath) | Out-Null - } -} - -$message = "The following services were found to have a change log update:`n" -$UpdatedServicePaths | % { $message += "`t- $_`n" } -Write-Host "$message`n" - -$FlaggedFiles = @() -foreach ($File in $FilesChangedList) -{ - if ($File -like "*ChangeLog.md*" -or $File -like "*.psd1*" -or $File -like "*.sln") - { - continue - } - - if (($PathsToCheck | where { $File.StartsWith($_) } | Measure-Object).Count -gt 0 -and ` - ($PathStringsToIgnore | where { $File -like "*$_*" } | Measure-Object).Count -eq 0 -and ` - ($UpdatedServicePaths | where { $File.StartsWith($_) } | Measure-Object).Count -eq 0) - { - $FlaggedFiles += $File - } -} - -if ($FlaggedFiles.Count -gt 0) -{ - $message = "The following files were flagged for not having a change log entry:`n" - $FlaggedFiles | % { $message += "`t- $_`n" } - Write-Host $message - throw "Modified files were found with no update to their change log. Please add a snippet to the affected modules' change log." -} From daab8d03f3b529a2d2a4b0f8967a0d7d7f162caf Mon Sep 17 00:00:00 2001 From: wyunchi-ms Date: Fri, 4 Nov 2022 16:11:59 +0800 Subject: [PATCH 3/7] Rename task name --- .ci-config.json | 4 ++-- build.proj | 8 ++++---- .../Microsoft.Azure.Build.Tasks/CIFilterTask.cs | 10 +++++----- tools/ExecuteCIStep.ps1 | 16 +++++----------- tools/PipelineResultTemplate.json | 4 ++-- .../CollectStaticAnalysisPipelineResult.ps1 | 6 +++--- .../Test-FileChange.ps1} | 10 +++++----- 7 files changed, 26 insertions(+), 32 deletions(-) rename tools/StaticAnalysis/{NecessaryChangeAnalyzer/Test-NecessaryChange.ps1 => FileChangeAnalyzer/Test-FileChange.ps1} (91%) diff --git a/.ci-config.json b/.ci-config.json index 818dd2ad2240..852e0e8ab2bd 100644 --- a/.ci-config.json +++ b/.ci-config.json @@ -100,7 +100,7 @@ "build:related-module", "dependence:dependence-module", "test:dependence-module", - "necessary-change:module" + "file-change:module" ] }, { @@ -113,7 +113,7 @@ "help:module", "signature:module", "test:dependence-module", - "necessary-change:module" + "file-change:module" ] }, { diff --git a/build.proj b/build.proj index 5491245e2ff0..6330b198a9f6 100644 --- a/build.proj +++ b/build.proj @@ -268,12 +268,12 @@ - - - + + + - + diff --git a/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs b/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs index 02f8df900e8d..b1569c0e04f2 100644 --- a/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs +++ b/tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs @@ -74,7 +74,7 @@ public class CIFilterTask : Task private const string ANALYSIS_HELP_PHASE = "help"; private const string ANALYSIS_DEPENDENCY_PHASE = "dependency"; private const string ANALYSIS_SIGNATURE_PHASE = "signature"; - private const string ANALYSIS_NECESSARY_CHANGE_PHASE = "necessary-change"; + private const string ANALYSIS_FILE_CHANGE_PHASE = "file-change"; private const string TEST_PHASE = "test"; private const string ACCOUNT_MODULE_NAME = "Accounts"; @@ -191,7 +191,7 @@ private bool ProcessTargetModule(Dictionary csprojMap) [ANALYSIS_HELP_EXAMPLE_PHASE] = new HashSet(GetDependenceModuleList(TargetModule, csprojMap).ToList()), [ANALYSIS_HELP_PHASE] = new HashSet(GetDependenceModuleList(TargetModule, csprojMap).ToList()), [ANALYSIS_SIGNATURE_PHASE] = new HashSet(GetDependenceModuleList(TargetModule, csprojMap).ToList()), - [ANALYSIS_NECESSARY_CHANGE_PHASE] = new HashSet(GetDependenceModuleList(TargetModule, csprojMap).ToList()), + [ANALYSIS_FILE_CHANGE_PHASE] = new HashSet(GetDependenceModuleList(TargetModule, csprojMap).ToList()), [TEST_PHASE] = new HashSet(GetTestCsprojList(TargetModule, csprojMap).ToList()) }; @@ -247,7 +247,7 @@ private Dictionary> CalculateInfluencedModuleInfoForEach ANALYSIS_HELP_EXAMPLE_PHASE + ":" + AllModule, ANALYSIS_HELP_PHASE + ":" + AllModule, ANALYSIS_SIGNATURE_PHASE + ":" + AllModule, - ANALYSIS_NECESSARY_CHANGE_PHASE + ":" + AllModule, + ANALYSIS_FILE_CHANGE_PHASE + ":" + AllModule, TEST_PHASE + ":" + AllModule, }; } @@ -296,7 +296,7 @@ private Dictionary> CalculateInfluencedModuleInfoForEach ANALYSIS_HELP_EXAMPLE_PHASE, ANALYSIS_HELP_PHASE, ANALYSIS_SIGNATURE_PHASE, - ANALYSIS_NECESSARY_CHANGE_PHASE, + ANALYSIS_FILE_CHANGE_PHASE, TEST_PHASE }; foreach (string phaseName in expectedKeyList) @@ -417,7 +417,7 @@ private bool ProcessFileChanged(Dictionary csprojMap) [ANALYSIS_HELP_EXAMPLE_PHASE] = influencedModuleInfo[ANALYSIS_HELP_EXAMPLE_PHASE], [ANALYSIS_HELP_PHASE] = influencedModuleInfo[ANALYSIS_HELP_PHASE], [ANALYSIS_SIGNATURE_PHASE] = influencedModuleInfo[ANALYSIS_SIGNATURE_PHASE], - [ANALYSIS_NECESSARY_CHANGE_PHASE] = influencedModuleInfo[ANALYSIS_NECESSARY_CHANGE_PHASE], + [ANALYSIS_FILE_CHANGE_PHASE] = influencedModuleInfo[ANALYSIS_FILE_CHANGE_PHASE], [TEST_PHASE] = new HashSet(influencedModuleInfo[TEST_PHASE].Select(GetModuleNameFromPath).Where(x => x != null)) }; File.WriteAllText(Path.Combine(config.ArtifactPipelineInfoFolder, "CIPlan.json"), JsonConvert.SerializeObject(CIPlan, Formatting.Indented)); diff --git a/tools/ExecuteCIStep.ps1 b/tools/ExecuteCIStep.ps1 index 438ece1ee0ac..3450c056e466 100644 --- a/tools/ExecuteCIStep.ps1 +++ b/tools/ExecuteCIStep.ps1 @@ -22,9 +22,6 @@ Param( [String] $BuildAction='build', - [Switch] - $GenerateDocumentationFile, - [Switch] $Test, @@ -40,6 +37,9 @@ Param( [Switch] $StaticAnalysisHelp, + [Switch] + $GenerateDocumentationFile=$False, + [String] $RepoArtifacts='artifacts', @@ -63,14 +63,8 @@ $ErrorActionPreference = 'Stop' If ($Build) { $LogFile = "$RepoArtifacts/Build.Log" - If ($GenerateDocumentationFile) - { - dotnet $BuildAction $RepoArtifacts/Azure.PowerShell.sln -c $Configuration -fl "/flp1:logFile=$LogFile;verbosity=quiet" - } - Else - { - dotnet $BuildAction $RepoArtifacts/Azure.PowerShell.sln -c $Configuration -p:GenerateDocumentationFile=false -fl "/flp1:logFile=$LogFile;verbosity=quiet" - } + + dotnet $BuildAction $RepoArtifacts/Azure.PowerShell.sln -c $Configuration -p:GenerateDocumentationFile=$GenerateDocumentationFile -fl "/flp1:logFile=$LogFile;verbosity=quiet" If (Test-Path -Path "$RepoArtifacts/PipelineResult") { $LogContent = Get-Content $LogFile diff --git a/tools/PipelineResultTemplate.json b/tools/PipelineResultTemplate.json index ff42176d61e2..9347ea04bfaf 100644 --- a/tools/PipelineResultTemplate.json +++ b/tools/PipelineResultTemplate.json @@ -29,8 +29,8 @@ "Details": [ ] }, - "necessary-change": { - "Name": "Necessary Change Check", + "file-change": { + "Name": "File Change Check", "Order": 6, "Details": [ ] diff --git a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 index 1be6e16c2f1e..77d7521289df 100644 --- a/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 +++ b/tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 @@ -67,8 +67,8 @@ $Steps = @( IssuePath = "$StaticAnalysisOutputDirectory/SignatureIssues.csv" }, @{ - StepName = "necessary-change" - IssuePath = "$StaticAnalysisOutputDirectory/NecessaryChangeIssue.csv" + StepName = "file-change" + IssuePath = "$StaticAnalysisOutputDirectory/FileChangeIssue.csv" } ) @@ -106,7 +106,7 @@ ForEach ($Step In $Steps) If ($MatchedIssues.Length -Ne 0) { #Region generate table head of each step - $NormalSteps = [System.Collections.Generic.HashSet[String]]@("breaking-change", "help", "signature", "necessary-change") + $NormalSteps = [System.Collections.Generic.HashSet[String]]@("breaking-change", "help", "signature", "file-change") If ($NormalSteps.Contains($StepName)) { $Content = "|Type|Cmdlet|Description|Remediation|`n|---|---|---|---|`n" diff --git a/tools/StaticAnalysis/NecessaryChangeAnalyzer/Test-NecessaryChange.ps1 b/tools/StaticAnalysis/FileChangeAnalyzer/Test-FileChange.ps1 similarity index 91% rename from tools/StaticAnalysis/NecessaryChangeAnalyzer/Test-NecessaryChange.ps1 rename to tools/StaticAnalysis/FileChangeAnalyzer/Test-FileChange.ps1 index 5a05df1c409e..ddea1630b14a 100644 --- a/tools/StaticAnalysis/NecessaryChangeAnalyzer/Test-NecessaryChange.ps1 +++ b/tools/StaticAnalysis/FileChangeAnalyzer/Test-FileChange.ps1 @@ -14,7 +14,7 @@ Param ( ) -Class NecessaryChangeIssue { +Class FileChangeIssue { [String]$Module [Int]$Severity [String]$Description @@ -24,7 +24,7 @@ $ExceptionList = @() $FilesChangedPath = "$PSScriptRoot/../../../artifacts/FilesChanged.txt" $FilesChanged = Get-Content $FilesChangedPath -$ExceptionFilePath = "$PSScriptRoot/../../../artifacts/StaticAnalysisResults/NecessaryChangeIssue.csv" +$ExceptionFilePath = "$PSScriptRoot/../../../artifacts/StaticAnalysisResults/FileChangeIssue.csv" $UpdatedChangeLogs = @{} ForEach ($FilePath In ($FilesChanged | Where-Object { $_.EndsWith("ChangeLog.md") })) @@ -38,14 +38,14 @@ ForEach ($FilePath In $FilesChanged) If ($FilePath.StartsWith("src/")) { $ModuleName = $FilePath.Split("/")[1] - $FileTypeArray = @(".cs", ".psd1", ".csproj", ".json") + $FileTypeArray = @(".cs", ".psd1", ".csproj", ".json", ".ps1xml", ".resx") ForEach ($FileType In $FileTypeArray) { If ($FilePath.EndsWith($FileType)) { If (-Not ($UpdatedChangeLogs.ContainsKey($ModuleName))) { - $ExceptionList += [NecessaryChangeIssue]@{ + $ExceptionList += [FileChangeIssue]@{ Module = "Az.$ModuleName"; Severity = 2; Description = "A update of `ChangeLog.md` is necessary if you want a new version of Az.$ModuleName." @@ -58,7 +58,7 @@ ForEach ($FilePath In $FilesChanged) If ($FilePath.EndsWith("AssemblyInfo.cs")) { $ModuleName = $FilePath.Split("/")[1] - $ExceptionList += [NecessaryChangeIssue]@{ + $ExceptionList += [FileChangeIssue]@{ Module = "Az.$ModuleName"; Severity = 2; Description = "We will update AssemblyInfo.cs automaticlly. Please donot update it manually." From 614e2b2a43e44c8aa7f57f1c88dc8fc203db2c16 Mon Sep 17 00:00:00 2001 From: wyunchi-ms Date: Fri, 4 Nov 2022 16:14:51 +0800 Subject: [PATCH 4/7] Rename task name --- tools/ExecuteCIStep.ps1 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/ExecuteCIStep.ps1 b/tools/ExecuteCIStep.ps1 index 3450c056e466..438ece1ee0ac 100644 --- a/tools/ExecuteCIStep.ps1 +++ b/tools/ExecuteCIStep.ps1 @@ -22,6 +22,9 @@ Param( [String] $BuildAction='build', + [Switch] + $GenerateDocumentationFile, + [Switch] $Test, @@ -37,9 +40,6 @@ Param( [Switch] $StaticAnalysisHelp, - [Switch] - $GenerateDocumentationFile=$False, - [String] $RepoArtifacts='artifacts', @@ -63,8 +63,14 @@ $ErrorActionPreference = 'Stop' If ($Build) { $LogFile = "$RepoArtifacts/Build.Log" - - dotnet $BuildAction $RepoArtifacts/Azure.PowerShell.sln -c $Configuration -p:GenerateDocumentationFile=$GenerateDocumentationFile -fl "/flp1:logFile=$LogFile;verbosity=quiet" + If ($GenerateDocumentationFile) + { + dotnet $BuildAction $RepoArtifacts/Azure.PowerShell.sln -c $Configuration -fl "/flp1:logFile=$LogFile;verbosity=quiet" + } + Else + { + dotnet $BuildAction $RepoArtifacts/Azure.PowerShell.sln -c $Configuration -p:GenerateDocumentationFile=false -fl "/flp1:logFile=$LogFile;verbosity=quiet" + } If (Test-Path -Path "$RepoArtifacts/PipelineResult") { $LogContent = Get-Content $LogFile From 9dcf936795a734e09dc0736e0b3e18502e2f50b0 Mon Sep 17 00:00:00 2001 From: wyunchi-ms Date: Fri, 4 Nov 2022 16:58:32 +0800 Subject: [PATCH 5/7] Rename task name --- tools/StaticAnalysis/FileChangeAnalyzer/Test-FileChange.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/StaticAnalysis/FileChangeAnalyzer/Test-FileChange.ps1 b/tools/StaticAnalysis/FileChangeAnalyzer/Test-FileChange.ps1 index ddea1630b14a..3eca301b9c5a 100644 --- a/tools/StaticAnalysis/FileChangeAnalyzer/Test-FileChange.ps1 +++ b/tools/StaticAnalysis/FileChangeAnalyzer/Test-FileChange.ps1 @@ -48,7 +48,7 @@ ForEach ($FilePath In $FilesChanged) $ExceptionList += [FileChangeIssue]@{ Module = "Az.$ModuleName"; Severity = 2; - Description = "A update of `ChangeLog.md` is necessary if you want a new version of Az.$ModuleName." + Description = "It is required to update `ChangeLog.md` if you want to release a new version for Az.$ModuleName." Remediation = "Add a changelog record under `Upcoming Release` section with past tense." } } @@ -61,8 +61,8 @@ ForEach ($FilePath In $FilesChanged) $ExceptionList += [FileChangeIssue]@{ Module = "Az.$ModuleName"; Severity = 2; - Description = "We will update AssemblyInfo.cs automaticlly. Please donot update it manually." - Remediation = "Revert AssemblyInfo.cs to last version." + Description = "AssemblyInfo.cs will be updated automatically. Please do not update it manually." + Remediation = "Revert AssemblyInfo.cs to its last version." } } } From 5647d420650d8fe9d5d5168b7b790fbb8ded9320 Mon Sep 17 00:00:00 2001 From: wyunchi-ms Date: Fri, 4 Nov 2022 17:25:35 +0800 Subject: [PATCH 6/7] Update script to be more dotnet --- .../FileChangeAnalyzer/Test-FileChange.ps1 | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/tools/StaticAnalysis/FileChangeAnalyzer/Test-FileChange.ps1 b/tools/StaticAnalysis/FileChangeAnalyzer/Test-FileChange.ps1 index 3eca301b9c5a..d48992e6f543 100644 --- a/tools/StaticAnalysis/FileChangeAnalyzer/Test-FileChange.ps1 +++ b/tools/StaticAnalysis/FileChangeAnalyzer/Test-FileChange.ps1 @@ -22,9 +22,10 @@ Class FileChangeIssue { } $ExceptionList = @() -$FilesChangedPath = "$PSScriptRoot/../../../artifacts/FilesChanged.txt" +$ArtifactsFolder = "$PSScriptRoot/../../../artifacts" +$FilesChangedPath = "$ArtifactsFolder/FilesChanged.txt" $FilesChanged = Get-Content $FilesChangedPath -$ExceptionFilePath = "$PSScriptRoot/../../../artifacts/StaticAnalysisResults/FileChangeIssue.csv" +$ExceptionFilePath = "$ArtifactsFolder/StaticAnalysisResults/FileChangeIssue.csv" $UpdatedChangeLogs = @{} ForEach ($FilePath In ($FilesChanged | Where-Object { $_.EndsWith("ChangeLog.md") })) @@ -38,26 +39,24 @@ ForEach ($FilePath In $FilesChanged) If ($FilePath.StartsWith("src/")) { $ModuleName = $FilePath.Split("/")[1] - $FileTypeArray = @(".cs", ".psd1", ".csproj", ".json", ".ps1xml", ".resx") - ForEach ($FileType In $FileTypeArray) + + $FileTypeArray = @(".cs", ".psd1", ".csproj", ".ps1xml", ".resx") + $FileType = [System.IO.Path]::GetExtension($FilePath) + If ($FileType -In $FileTypeArray) { - If ($FilePath.EndsWith($FileType)) + If (-Not ($UpdatedChangeLogs.ContainsKey($ModuleName))) { - If (-Not ($UpdatedChangeLogs.ContainsKey($ModuleName))) - { - $ExceptionList += [FileChangeIssue]@{ - Module = "Az.$ModuleName"; - Severity = 2; - Description = "It is required to update `ChangeLog.md` if you want to release a new version for Az.$ModuleName." - Remediation = "Add a changelog record under `Upcoming Release` section with past tense." - } + $ExceptionList += [FileChangeIssue]@{ + Module = "Az.$ModuleName"; + Severity = 2; + Description = "It is required to update `ChangeLog.md` if you want to release a new version for Az.$ModuleName." + Remediation = "Add a changelog record under `Upcoming Release` section with past tense." } } } - If ($FilePath.EndsWith("AssemblyInfo.cs")) + If ([System.IO.Path]::GetFileName($FilePath) -Eq "AssemblyInfo.cs") { - $ModuleName = $FilePath.Split("/")[1] $ExceptionList += [FileChangeIssue]@{ Module = "Az.$ModuleName"; Severity = 2; From 373af755b684901a4d85292a1343ce501c711c52 Mon Sep 17 00:00:00 2001 From: wyunchi-ms Date: Fri, 4 Nov 2022 17:30:15 +0800 Subject: [PATCH 7/7] Update script to be more dotnet --- tools/StaticAnalysis/FileChangeAnalyzer/Test-FileChange.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/StaticAnalysis/FileChangeAnalyzer/Test-FileChange.ps1 b/tools/StaticAnalysis/FileChangeAnalyzer/Test-FileChange.ps1 index d48992e6f543..4346737f4556 100644 --- a/tools/StaticAnalysis/FileChangeAnalyzer/Test-FileChange.ps1 +++ b/tools/StaticAnalysis/FileChangeAnalyzer/Test-FileChange.ps1 @@ -40,7 +40,7 @@ ForEach ($FilePath In $FilesChanged) { $ModuleName = $FilePath.Split("/")[1] - $FileTypeArray = @(".cs", ".psd1", ".csproj", ".ps1xml", ".resx") + $FileTypeArray = @(".cs", ".psd1", ".csproj", ".ps1xml", ".resx", ".ps1", ".psm1") $FileType = [System.IO.Path]::GetExtension($FilePath) If ($FileType -In $FileTypeArray) {