Skip to content

Commit f90cdb0

Browse files
authored
Add logic for file change check (#20015)
* 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
1 parent fde2e39 commit f90cdb0

File tree

7 files changed

+102
-113
lines changed

7 files changed

+102
-113
lines changed

.ci-config.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@
9999
"phases": [
100100
"build:related-module",
101101
"dependence:dependence-module",
102-
"test:dependence-module"
102+
"test:dependence-module",
103+
"file-change:module"
103104
]
104105
},
105106
{
@@ -111,7 +112,8 @@
111112
"breaking-change:module",
112113
"help:module",
113114
"signature:module",
114-
"test:dependence-module"
115+
"test:dependence-module",
116+
"file-change:module"
115117
]
116118
},
117119
{

build.proj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,12 @@
268268
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;. $(RepoTools)/StaticAnalysis/ExampleAnalyzer/Measure-MarkdownOrScript.ps1 -MarkdownPaths $(RepoArtifacts)/FilesChanged.txt -RulePaths $(RepoTools)/StaticAnalysis/ExampleAnalyzer/AnalyzeRules/*.psm1 &quot;"/>
269269
</Target>
270270

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

274279
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;. $(RepoTools)/CheckAssemblies.ps1 -BuildConfig $(Configuration) &quot;" />

tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public class CIFilterTask : Task
7474
private const string ANALYSIS_HELP_PHASE = "help";
7575
private const string ANALYSIS_DEPENDENCY_PHASE = "dependency";
7676
private const string ANALYSIS_SIGNATURE_PHASE = "signature";
77+
private const string ANALYSIS_FILE_CHANGE_PHASE = "file-change";
7778
private const string TEST_PHASE = "test";
7879
private const string ACCOUNT_MODULE_NAME = "Accounts";
7980

@@ -190,6 +191,7 @@ private bool ProcessTargetModule(Dictionary<string, string[]> csprojMap)
190191
[ANALYSIS_HELP_EXAMPLE_PHASE] = new HashSet<string>(GetDependenceModuleList(TargetModule, csprojMap).ToList()),
191192
[ANALYSIS_HELP_PHASE] = new HashSet<string>(GetDependenceModuleList(TargetModule, csprojMap).ToList()),
192193
[ANALYSIS_SIGNATURE_PHASE] = new HashSet<string>(GetDependenceModuleList(TargetModule, csprojMap).ToList()),
194+
[ANALYSIS_FILE_CHANGE_PHASE] = new HashSet<string>(GetDependenceModuleList(TargetModule, csprojMap).ToList()),
193195
[TEST_PHASE] = new HashSet<string>(GetTestCsprojList(TargetModule, csprojMap).ToList())
194196
};
195197

@@ -245,6 +247,7 @@ private Dictionary<string, HashSet<string>> CalculateInfluencedModuleInfoForEach
245247
ANALYSIS_HELP_EXAMPLE_PHASE + ":" + AllModule,
246248
ANALYSIS_HELP_PHASE + ":" + AllModule,
247249
ANALYSIS_SIGNATURE_PHASE + ":" + AllModule,
250+
ANALYSIS_FILE_CHANGE_PHASE + ":" + AllModule,
248251
TEST_PHASE + ":" + AllModule,
249252
};
250253
}
@@ -293,6 +296,7 @@ private Dictionary<string, HashSet<string>> CalculateInfluencedModuleInfoForEach
293296
ANALYSIS_HELP_EXAMPLE_PHASE,
294297
ANALYSIS_HELP_PHASE,
295298
ANALYSIS_SIGNATURE_PHASE,
299+
ANALYSIS_FILE_CHANGE_PHASE,
296300
TEST_PHASE
297301
};
298302
foreach (string phaseName in expectedKeyList)
@@ -413,6 +417,7 @@ private bool ProcessFileChanged(Dictionary<string, string[]> csprojMap)
413417
[ANALYSIS_HELP_EXAMPLE_PHASE] = influencedModuleInfo[ANALYSIS_HELP_EXAMPLE_PHASE],
414418
[ANALYSIS_HELP_PHASE] = influencedModuleInfo[ANALYSIS_HELP_PHASE],
415419
[ANALYSIS_SIGNATURE_PHASE] = influencedModuleInfo[ANALYSIS_SIGNATURE_PHASE],
420+
[ANALYSIS_FILE_CHANGE_PHASE] = influencedModuleInfo[ANALYSIS_FILE_CHANGE_PHASE],
416421
[TEST_PHASE] = new HashSet<string>(influencedModuleInfo[TEST_PHASE].Select(GetModuleNameFromPath).Where(x => x != null))
417422
};
418423
File.WriteAllText(Path.Combine(config.ArtifactPipelineInfoFolder, "CIPlan.json"), JsonConvert.SerializeObject(CIPlan, Formatting.Indented));
@@ -463,6 +468,7 @@ public override bool Execute()
463468
[ANALYSIS_HELP_EXAMPLE_PHASE] = new HashSet<string>(selectedModuleList),
464469
[ANALYSIS_HELP_PHASE] = new HashSet<string>(selectedModuleList),
465470
[ANALYSIS_SIGNATURE_PHASE] = new HashSet<string>(selectedModuleList),
471+
[ANALYSIS_HELP_EXAMPLE_PHASE] = new HashSet<string>(selectedModuleList),
466472
[TEST_PHASE] = new HashSet<string>(selectedModuleList)
467473
};
468474
FilterTaskResult.PhaseInfo = CalculateCsprojForBuildAndTest(influencedModuleInfo, csprojMap);

tools/CheckChangeLog.ps1

Lines changed: 0 additions & 108 deletions
This file was deleted.

tools/PipelineResultTemplate.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
"Details": [
3030
]
3131
},
32+
"file-change": {
33+
"Name": "File Change Check",
34+
"Order": 6,
35+
"Details": [
36+
]
37+
},
3238
"test": {
3339
"Name": "Test",
3440
"Order": 100,

tools/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ $Steps = @(
6565
@{
6666
StepName = "signature"
6767
IssuePath = "$StaticAnalysisOutputDirectory/SignatureIssues.csv"
68+
},
69+
@{
70+
StepName = "file-change"
71+
IssuePath = "$StaticAnalysisOutputDirectory/FileChangeIssue.csv"
6872
}
6973
)
7074

@@ -102,7 +106,8 @@ ForEach ($Step In $Steps)
102106
If ($MatchedIssues.Length -Ne 0)
103107
{
104108
#Region generate table head of each step
105-
If (($StepName -Eq "breaking-change") -Or ($StepName -Eq "help") -Or ($StepName -Eq "signature"))
109+
$NormalSteps = [System.Collections.Generic.HashSet[String]]@("breaking-change", "help", "signature", "file-change")
110+
If ($NormalSteps.Contains($StepName))
106111
{
107112
$Content = "|Type|Cmdlet|Description|Remediation|`n|---|---|---|---|`n"
108113
}
@@ -123,7 +128,7 @@ ForEach ($Step In $Steps)
123128
$ErrorTypeEmoji = "⚠️"
124129
}
125130
#Region generate table content of each step
126-
If (($StepName -Eq "breaking-change") -Or ($StepName -Eq "help") -Or ($StepName -Eq "signature"))
131+
If ($NormalSteps.Contains($StepName))
127132
{
128133
$Content += "|$ErrorTypeEmoji|$($Issue.Target)|$($Issue.Description)|$($Issue.Remediation)|`n"
129134
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# ----------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
# ----------------------------------------------------------------------------------
13+
14+
Param (
15+
)
16+
17+
Class FileChangeIssue {
18+
[String]$Module
19+
[Int]$Severity
20+
[String]$Description
21+
[String]$Remediation
22+
}
23+
$ExceptionList = @()
24+
25+
$ArtifactsFolder = "$PSScriptRoot/../../../artifacts"
26+
$FilesChangedPath = "$ArtifactsFolder/FilesChanged.txt"
27+
$FilesChanged = Get-Content $FilesChangedPath
28+
$ExceptionFilePath = "$ArtifactsFolder/StaticAnalysisResults/FileChangeIssue.csv"
29+
$UpdatedChangeLogs = @{}
30+
31+
ForEach ($FilePath In ($FilesChanged | Where-Object { $_.EndsWith("ChangeLog.md") }))
32+
{
33+
$ModuleName = $FilePath.Split("/")[1]
34+
$UpdatedChangeLogs.Add($ModuleName, $FilePath)
35+
}
36+
37+
ForEach ($FilePath In $FilesChanged)
38+
{
39+
If ($FilePath.StartsWith("src/"))
40+
{
41+
$ModuleName = $FilePath.Split("/")[1]
42+
43+
$FileTypeArray = @(".cs", ".psd1", ".csproj", ".ps1xml", ".resx", ".ps1", ".psm1")
44+
$FileType = [System.IO.Path]::GetExtension($FilePath)
45+
If ($FileType -In $FileTypeArray)
46+
{
47+
If (-Not ($UpdatedChangeLogs.ContainsKey($ModuleName)))
48+
{
49+
$ExceptionList += [FileChangeIssue]@{
50+
Module = "Az.$ModuleName";
51+
Severity = 2;
52+
Description = "It is required to update `ChangeLog.md` if you want to release a new version for Az.$ModuleName."
53+
Remediation = "Add a changelog record under `Upcoming Release` section with past tense."
54+
}
55+
}
56+
}
57+
58+
If ([System.IO.Path]::GetFileName($FilePath) -Eq "AssemblyInfo.cs")
59+
{
60+
$ExceptionList += [FileChangeIssue]@{
61+
Module = "Az.$ModuleName";
62+
Severity = 2;
63+
Description = "AssemblyInfo.cs will be updated automatically. Please do not update it manually."
64+
Remediation = "Revert AssemblyInfo.cs to its last version."
65+
}
66+
}
67+
}
68+
}
69+
70+
If ($ExceptionList.Length -Ne 0)
71+
{
72+
$ExceptionList | Sort-Object -Unique -Property Module,Description | Export-Csv $ExceptionFilePath -NoTypeInformation
73+
}

0 commit comments

Comments
 (0)