Skip to content

Commit

Permalink
Add logic for file change check (Azure#20015)
Browse files Browse the repository at this point in the history
* Add logic for necessary change check

* Remove tools/CheckChangeLog.ps1

* Rename task name

* Rename task name

* Rename task name

* Update script to be more dotnet

* Update script to be more dotnet
  • Loading branch information
wyunchi-ms authored Nov 4, 2022
1 parent fde2e39 commit f90cdb0
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 113 deletions.
6 changes: 4 additions & 2 deletions .ci-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
"phases": [
"build:related-module",
"dependence:dependence-module",
"test:dependence-module"
"test:dependence-module",
"file-change:module"
]
},
{
Expand All @@ -111,7 +112,8 @@
"breaking-change:module",
"help:module",
"signature:module",
"test:dependence-module"
"test:dependence-module",
"file-change:module"
]
},
{
Expand Down
7 changes: 6 additions & 1 deletion build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,12 @@
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;. $(RepoTools)/StaticAnalysis/ExampleAnalyzer/Measure-MarkdownOrScript.ps1 -MarkdownPaths $(RepoArtifacts)/FilesChanged.txt -RulePaths $(RepoTools)/StaticAnalysis/ExampleAnalyzer/AnalyzeRules/*.psm1 &quot;"/>
</Target>

<Target Name="StaticAnalysis" DependsOnTargets="StaticAnalysisBreakingChange;StaticAnalysisDependency;StaticAnalysisSignature;StaticAnalysisHelp;StaticAnalysisExample">
<Target Name="StaticAnalysisFileChange" Condition="'$(RunStaticAnalysis)' == 'true'">
<Message Importance="high" Text="Running static analysis for file changes..." />
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;.\tools\StaticAnalysis\FileChangeAnalyzer\Test-FileChange.ps1 &quot;" />
</Target>

<Target Name="StaticAnalysis" DependsOnTargets="StaticAnalysisBreakingChange;StaticAnalysisDependency;StaticAnalysisSignature;StaticAnalysisHelp;StaticAnalysisExample;StaticAnalysisFileChange">
<Message Importance="high" Text="Running static analysis..." />

<Exec Command="$(PowerShellCoreCommandPrefix) &quot;. $(RepoTools)/CheckAssemblies.ps1 -BuildConfig $(Configuration) &quot;" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_FILE_CHANGE_PHASE = "file-change";
private const string TEST_PHASE = "test";
private const string ACCOUNT_MODULE_NAME = "Accounts";

Expand Down Expand Up @@ -190,6 +191,7 @@ private bool ProcessTargetModule(Dictionary<string, string[]> csprojMap)
[ANALYSIS_HELP_EXAMPLE_PHASE] = new HashSet<string>(GetDependenceModuleList(TargetModule, csprojMap).ToList()),
[ANALYSIS_HELP_PHASE] = new HashSet<string>(GetDependenceModuleList(TargetModule, csprojMap).ToList()),
[ANALYSIS_SIGNATURE_PHASE] = new HashSet<string>(GetDependenceModuleList(TargetModule, csprojMap).ToList()),
[ANALYSIS_FILE_CHANGE_PHASE] = new HashSet<string>(GetDependenceModuleList(TargetModule, csprojMap).ToList()),
[TEST_PHASE] = new HashSet<string>(GetTestCsprojList(TargetModule, csprojMap).ToList())
};

Expand Down Expand Up @@ -245,6 +247,7 @@ private Dictionary<string, HashSet<string>> CalculateInfluencedModuleInfoForEach
ANALYSIS_HELP_EXAMPLE_PHASE + ":" + AllModule,
ANALYSIS_HELP_PHASE + ":" + AllModule,
ANALYSIS_SIGNATURE_PHASE + ":" + AllModule,
ANALYSIS_FILE_CHANGE_PHASE + ":" + AllModule,
TEST_PHASE + ":" + AllModule,
};
}
Expand Down Expand Up @@ -293,6 +296,7 @@ private Dictionary<string, HashSet<string>> CalculateInfluencedModuleInfoForEach
ANALYSIS_HELP_EXAMPLE_PHASE,
ANALYSIS_HELP_PHASE,
ANALYSIS_SIGNATURE_PHASE,
ANALYSIS_FILE_CHANGE_PHASE,
TEST_PHASE
};
foreach (string phaseName in expectedKeyList)
Expand Down Expand Up @@ -413,6 +417,7 @@ private bool ProcessFileChanged(Dictionary<string, string[]> 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_FILE_CHANGE_PHASE] = influencedModuleInfo[ANALYSIS_FILE_CHANGE_PHASE],
[TEST_PHASE] = new HashSet<string>(influencedModuleInfo[TEST_PHASE].Select(GetModuleNameFromPath).Where(x => x != null))
};
File.WriteAllText(Path.Combine(config.ArtifactPipelineInfoFolder, "CIPlan.json"), JsonConvert.SerializeObject(CIPlan, Formatting.Indented));
Expand Down Expand Up @@ -463,6 +468,7 @@ public override bool Execute()
[ANALYSIS_HELP_EXAMPLE_PHASE] = new HashSet<string>(selectedModuleList),
[ANALYSIS_HELP_PHASE] = new HashSet<string>(selectedModuleList),
[ANALYSIS_SIGNATURE_PHASE] = new HashSet<string>(selectedModuleList),
[ANALYSIS_HELP_EXAMPLE_PHASE] = new HashSet<string>(selectedModuleList),
[TEST_PHASE] = new HashSet<string>(selectedModuleList)
};
FilterTaskResult.PhaseInfo = CalculateCsprojForBuildAndTest(influencedModuleInfo, csprojMap);
Expand Down
108 changes: 0 additions & 108 deletions tools/CheckChangeLog.ps1

This file was deleted.

6 changes: 6 additions & 0 deletions tools/PipelineResultTemplate.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
"Details": [
]
},
"file-change": {
"Name": "File Change Check",
"Order": 6,
"Details": [
]
},
"test": {
"Name": "Test",
"Order": 100,
Expand Down
9 changes: 7 additions & 2 deletions tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ $Steps = @(
@{
StepName = "signature"
IssuePath = "$StaticAnalysisOutputDirectory/SignatureIssues.csv"
},
@{
StepName = "file-change"
IssuePath = "$StaticAnalysisOutputDirectory/FileChangeIssue.csv"
}
)

Expand Down Expand Up @@ -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", "file-change")
If ($NormalSteps.Contains($StepName))
{
$Content = "|Type|Cmdlet|Description|Remediation|`n|---|---|---|---|`n"
}
Expand All @@ -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"
}
Expand Down
73 changes: 73 additions & 0 deletions tools/StaticAnalysis/FileChangeAnalyzer/Test-FileChange.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# ----------------------------------------------------------------------------------
# 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 FileChangeIssue {
[String]$Module
[Int]$Severity
[String]$Description
[String]$Remediation
}
$ExceptionList = @()

$ArtifactsFolder = "$PSScriptRoot/../../../artifacts"
$FilesChangedPath = "$ArtifactsFolder/FilesChanged.txt"
$FilesChanged = Get-Content $FilesChangedPath
$ExceptionFilePath = "$ArtifactsFolder/StaticAnalysisResults/FileChangeIssue.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", ".ps1xml", ".resx", ".ps1", ".psm1")
$FileType = [System.IO.Path]::GetExtension($FilePath)
If ($FileType -In $FileTypeArray)
{
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."
}
}
}

If ([System.IO.Path]::GetFileName($FilePath) -Eq "AssemblyInfo.cs")
{
$ExceptionList += [FileChangeIssue]@{
Module = "Az.$ModuleName";
Severity = 2;
Description = "AssemblyInfo.cs will be updated automatically. Please do not update it manually."
Remediation = "Revert AssemblyInfo.cs to its last version."
}
}
}
}

If ($ExceptionList.Length -Ne 0)
{
$ExceptionList | Sort-Object -Unique -Property Module,Description | Export-Csv $ExceptionFilePath -NoTypeInformation
}

0 comments on commit f90cdb0

Please sign in to comment.