Skip to content

Commit

Permalink
Setup schema validation for UX metadata files (Azure#20086)
Browse files Browse the repository at this point in the history
* Add support for UX

* Update the logic of dependency check (Azure#20040)

* Add analysis step for UX metadata.

* Add support for UX

* Add support for UX

* Add support for UX

* Add support for UX

* Add support for UX

* Add support for UX

* Add support for UX
  • Loading branch information
wyunchi-ms authored Nov 14, 2022
1 parent 396d37b commit 5673141
Show file tree
Hide file tree
Showing 12 changed files with 522 additions and 66 deletions.
3 changes: 2 additions & 1 deletion .ci-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
"help:module",
"signature:module",
"test:dependence-module",
"file-change:module"
"file-change:module",
"ux:module"
]
},
{
Expand Down
31 changes: 3 additions & 28 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -239,33 +239,6 @@
<!-- Everything except Publish -->
<Target Name="Full" DependsOnTargets="Clean;Build;OnPremChecks;CopyAboutTopics;GenerateHelp;StaticAnalysis;Test" />

<Target Name="StaticAnalysisBreakingChange" Condition="'$(RunStaticAnalysis)' == 'true'">
<Message Importance="high" Text="Running static analysis for breaking change..." />
<MakeDir Directories="$(StaticAnalysisOutputDirectory)" />

<Exec Command="$(PowerShellCoreCommandPrefix) &quot;.\tools\ExecuteCIStep.ps1 -StaticAnalysisBreakingChange -RepoArtifacts $(RepoArtifacts) -Configuration $(Configuration) -StaticAnalysisOutputDirectory $(StaticAnalysisOutputDirectory)&quot;" />
</Target>

<Target Name="StaticAnalysisDependency" Condition="'$(RunStaticAnalysis)' == 'true'">
<Message Importance="high" Text="Running static analysis for dependency..." />
<MakeDir Directories="$(StaticAnalysisOutputDirectory)" />

<Exec Command="$(PowerShellCoreCommandPrefix) &quot;.\tools\ExecuteCIStep.ps1 -StaticAnalysisDependency -RepoArtifacts $(RepoArtifacts) -Configuration $(Configuration) -StaticAnalysisOutputDirectory $(StaticAnalysisOutputDirectory)&quot;" />
</Target>

<Target Name="StaticAnalysisSignature" Condition="'$(RunStaticAnalysis)' == 'true'">
<Message Importance="high" Text="Running static analysis for signature..." />
<MakeDir Directories="$(StaticAnalysisOutputDirectory)" />
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;.\tools\ExecuteCIStep.ps1 -StaticAnalysisSignature -RepoArtifacts $(RepoArtifacts) -Configuration $(Configuration) -StaticAnalysisOutputDirectory $(StaticAnalysisOutputDirectory)&quot;" />
</Target>

<Target Name="StaticAnalysisHelp" Condition="'$(RunStaticAnalysis)' == 'true'">
<Message Importance="high" Text="Running static analysis for help..." />
<MakeDir Directories="$(StaticAnalysisOutputDirectory)" />

<Exec Command="$(PowerShellCoreCommandPrefix) &quot;.\tools\ExecuteCIStep.ps1 -StaticAnalysisHelp -RepoArtifacts $(RepoArtifacts) -Configuration $(Configuration) -StaticAnalysisOutputDirectory $(StaticAnalysisOutputDirectory)&quot;" />
</Target>

<Target Name="StaticAnalysisExample" Condition="'$(RunStaticAnalysis)' == 'true'" AfterTargets="StaticAnalysisHelp">
<Message Importance="high" Text="Running static analysis for PowerShell examples..." />
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;. $(RepoTools)/StaticAnalysis/ExampleAnalyzer/Measure-MarkdownOrScript.ps1 -MarkdownPaths $(RepoArtifacts)/FilesChanged.txt -RulePaths $(RepoTools)/StaticAnalysis/ExampleAnalyzer/AnalyzeRules/*.psm1 &quot;"/>
Expand All @@ -276,9 +249,11 @@
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;.\tools\StaticAnalysis\FileChangeAnalyzer\Test-FileChange.ps1 &quot;" />
</Target>

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

<Exec Command="$(PowerShellCoreCommandPrefix) &quot;.\tools\ExecuteCIStep.ps1 -StaticAnalysis -RepoArtifacts $(RepoArtifacts) -Configuration $(Configuration) -StaticAnalysisOutputDirectory $(StaticAnalysisOutputDirectory)&quot;" />

<Exec Command="$(PowerShellCoreCommandPrefix) &quot;. $(RepoTools)/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 -StaticAnalysisOutputDirectory $(StaticAnalysisOutputDirectory) &quot;"/>
<Exec Command="dotnet $(RepoArtifacts)StaticAnalysis/StaticAnalysis.Netcore.dll -p $(RepoArtifacts)$(Configuration) -r $(StaticAnalysisOutputDirectory) --analyzers check-error" />
<OnError ExecuteTargets="StaticAnalysisErrorMessage" />
Expand Down
54 changes: 18 additions & 36 deletions tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,8 @@ public class CIFilterTask : Task
private const string RelatedModule = "related-module"; // self, modules that self dependent on and modules dependent on this module

private const string BUILD_PHASE = "build";
private const string ANALYSIS_BREAKING_CHANGE_PHASE = "breaking-change";
private const string ANALYSIS_HELP_EXAMPLE_PHASE = "help-example";
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 readonly List<string> ANALYSIS_PHASE_LIST = new List<string>() { "breaking-change", "help-example", "help", "dependency", "signature", "file-change", "ux" };
private const string ACCOUNT_MODULE_NAME = "Accounts";

private const string MODULE_NAME_PLACEHOLDER = "ModuleName";
Expand Down Expand Up @@ -186,14 +181,12 @@ private bool ProcessTargetModule(Dictionary<string, string[]> csprojMap)
Dictionary<string, HashSet<string>> influencedModuleInfo = new Dictionary<string, HashSet<string>>
{
[BUILD_PHASE] = new HashSet<string>(GetBuildCsprojList(TargetModule, csprojMap).ToList()),
[ANALYSIS_BREAKING_CHANGE_PHASE] = new HashSet<string>(GetDependenceModuleList(TargetModule, csprojMap).ToList()),
[ANALYSIS_DEPENDENCY_PHASE] = new HashSet<string>(GetDependenceModuleList(TargetModule, csprojMap).ToList()),
[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())
};
foreach (var analysisPhase in ANALYSIS_PHASE_LIST)
{
influencedModuleInfo.Add(analysisPhase, new HashSet<string>(GetDependenceModuleList(TargetModule, csprojMap).ToList()));
}

Console.WriteLine("----------------- InfluencedModuleInfo TargetModule -----------------");
foreach (string phaseName in influencedModuleInfo.Keys)
Expand Down Expand Up @@ -242,14 +235,12 @@ private Dictionary<string, HashSet<string>> CalculateInfluencedModuleInfoForEach
phaseList = new List<string>()
{
BUILD_PHASE + ":" + AllModule,
ANALYSIS_BREAKING_CHANGE_PHASE + ":" + AllModule,
ANALYSIS_DEPENDENCY_PHASE + ":" + AllModule,
ANALYSIS_HELP_EXAMPLE_PHASE + ":" + AllModule,
ANALYSIS_HELP_PHASE + ":" + AllModule,
ANALYSIS_SIGNATURE_PHASE + ":" + AllModule,
ANALYSIS_FILE_CHANGE_PHASE + ":" + AllModule,
TEST_PHASE + ":" + AllModule,
};
foreach (var analysisPhase in ANALYSIS_PHASE_LIST)
{
phaseList.Add(string.Format("{0}:{1}", analysisPhase, AllModule));
}
}
foreach (string phase in phaseList)
{
Expand Down Expand Up @@ -291,14 +282,9 @@ private Dictionary<string, HashSet<string>> CalculateInfluencedModuleInfoForEach
List<string> expectedKeyList = new List<string>()
{
BUILD_PHASE,
ANALYSIS_BREAKING_CHANGE_PHASE,
ANALYSIS_DEPENDENCY_PHASE,
ANALYSIS_HELP_EXAMPLE_PHASE,
ANALYSIS_HELP_PHASE,
ANALYSIS_SIGNATURE_PHASE,
ANALYSIS_FILE_CHANGE_PHASE,
TEST_PHASE
};
expectedKeyList.AddRange(ANALYSIS_PHASE_LIST);
foreach (string phaseName in expectedKeyList)
{
if (!influencedModuleInfo.ContainsKey(phaseName))
Expand Down Expand Up @@ -412,14 +398,12 @@ private bool ProcessFileChanged(Dictionary<string, string[]> csprojMap)
Dictionary<string, HashSet<string>> CIPlan = new Dictionary<string, HashSet<string>>
{
[BUILD_PHASE] = new HashSet<string>(influencedModuleInfo[BUILD_PHASE].Select(GetModuleNameFromPath).Where(x => x != null)),
[ANALYSIS_BREAKING_CHANGE_PHASE] = influencedModuleInfo[ANALYSIS_BREAKING_CHANGE_PHASE],
[ANALYSIS_DEPENDENCY_PHASE] = influencedModuleInfo[ANALYSIS_DEPENDENCY_PHASE],
[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))
};
foreach (var analysisPhase in ANALYSIS_PHASE_LIST)
{
CIPlan.Add(analysisPhase, influencedModuleInfo[analysisPhase]);
}
File.WriteAllText(Path.Combine(config.ArtifactPipelineInfoFolder, "CIPlan.json"), JsonConvert.SerializeObject(CIPlan, Formatting.Indented));

return true;
Expand Down Expand Up @@ -463,14 +447,12 @@ public override bool Execute()
Dictionary<string, HashSet<string>> influencedModuleInfo = new Dictionary<string, HashSet<string>>
{
[BUILD_PHASE] = new HashSet<string>(selectedModuleList),
[ANALYSIS_BREAKING_CHANGE_PHASE] = new HashSet<string>(selectedModuleList),
[ANALYSIS_DEPENDENCY_PHASE] = new HashSet<string>(selectedModuleList),
[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)
};
foreach (var analysisPhase in ANALYSIS_PHASE_LIST)
{
influencedModuleInfo.Add(analysisPhase, new HashSet<string>(selectedModuleList));
}
FilterTaskResult.PhaseInfo = CalculateCsprojForBuildAndTest(influencedModuleInfo, csprojMap);
return true;
}
Expand Down
48 changes: 48 additions & 0 deletions tools/ExecuteCIStep.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Param(
[Switch]
$Test,

[Switch]
$StaticAnalysis,

[Switch]
$StaticAnalysisBreakingChange,

Expand All @@ -40,6 +43,9 @@ Param(
[Switch]
$StaticAnalysisHelp,

[Switch]
$StaticAnalysisUX,

[String]
$RepoArtifacts='artifacts',

Expand Down Expand Up @@ -204,6 +210,25 @@ If ($Test -And $CIPlan.test.Length -Ne 0)
Return
}

If ($StaticAnalysis)
{
$Parameters = @{
RepoArtifacts = $RepoArtifacts;
StaticAnalysisOutputDirectory = $StaticAnalysisOutputDirectory;
Configuration = $Configuration;
}
If ($PSBoundParameters.ContainsKey("TargetModule"))
{
$Parameters["TargetModule"] = $TargetModule
}
.("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisBreakingChange @Parameters
.("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisDependency @Parameters
.("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisSignature @Parameters
.("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisHelp @Parameters
.("$PSScriptRoot/ExecuteCIStep.ps1") -StaticAnalysisUX @Parameters
Return
}

If ($StaticAnalysisBreakingChange)
{
If ($PSBoundParameters.ContainsKey("TargetModule"))
Expand All @@ -216,6 +241,7 @@ If ($StaticAnalysisBreakingChange)
}
If ("" -Ne $BreakingChangeCheckModuleList)
{
Write-Host "Running static analysis for breaking change..."
dotnet $RepoArtifacts/StaticAnalysis/StaticAnalysis.Netcore.dll -p $RepoArtifacts/$Configuration -r $StaticAnalysisOutputDirectory --analyzers breaking-change -u -m $BreakingChangeCheckModuleList
}
Return
Expand All @@ -232,6 +258,7 @@ If ($StaticAnalysisDependency)
}
If ("" -Ne $DependencyCheckModuleList)
{
Write-Host "Running static analysis for dependency..."
dotnet $RepoArtifacts/StaticAnalysis/StaticAnalysis.Netcore.dll -p $RepoArtifacts/$Configuration -r $StaticAnalysisOutputDirectory --analyzers dependency -u -m $DependencyCheckModuleList
.($PSScriptRoot + "/CheckAssemblies.ps1") -BuildConfig $Configuration
}
Expand All @@ -250,6 +277,7 @@ If ($StaticAnalysisSignature)
}
If ("" -Ne $SignatureCheckModuleList)
{
Write-Host "Running static analysis for signature..."
dotnet $RepoArtifacts/StaticAnalysis/StaticAnalysis.Netcore.dll -p $RepoArtifacts/$Configuration -r $StaticAnalysisOutputDirectory --analyzers signature -u -m $SignatureCheckModuleList
}
Return
Expand All @@ -267,7 +295,27 @@ If ($StaticAnalysisHelp)
}
If ("" -Ne $HelpCheckModuleList)
{
Write-Host "Running static analysis for help..."
dotnet $RepoArtifacts/StaticAnalysis/StaticAnalysis.Netcore.dll -p $RepoArtifacts/$Configuration -r $StaticAnalysisOutputDirectory --analyzers help -u -m $HelpCheckModuleList
}
Return
}

If ($StaticAnalysisUX)
{
If ($PSBoundParameters.ContainsKey("TargetModule"))
{
$UXModuleList = $TargetModule
}
Else
{
$UXModuleList = Join-String -Separator ';' -InputObject $CIPlan.ux
}
If ("" -Ne $UXModuleList)
{
Write-Host "Running static analysis for UX metadata..."
.("$PSScriptRoot/StaticAnalysis/UXMetadataAnalyzer/PrepareUXMetadata.ps1") -RepoArtifacts $RepoArtifacts -Configuration $Configuration
dotnet $RepoArtifacts/StaticAnalysis/StaticAnalysis.Netcore.dll -p $RepoArtifacts/$Configuration -r $StaticAnalysisOutputDirectory --analyzers ux -u -m $UXModuleList
}
Return
}
2 changes: 2 additions & 0 deletions tools/StaticAnalysis/IssueChecker/IssueChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using StaticAnalysis.DependencyAnalyzer;
using StaticAnalysis.SignatureVerifier;
using StaticAnalysis.ExampleAnalyzer;
using StaticAnalysis.UXMetadataAnalyzer;

namespace StaticAnalysis.IssueChecker
{
Expand All @@ -41,6 +42,7 @@ public class IssueChecker : IStaticAnalyzer
("ExtraAssemblies.csv", typeof(ExtraAssembly).FullName),
("SignatureIssues.csv", typeof(SignatureIssue).FullName),
("ExampleIssues.csv", typeof(ExampleIssue).FullName),
("UXMetadataIssues.csv", typeof(UXMetadataIssue).FullName),
};
public AnalysisLogger Logger { get; set; }

Expand Down
8 changes: 7 additions & 1 deletion tools/StaticAnalysis/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public class Program
"HelpIssues.csv",
"MissingAssemblies.csv",
"SignatureIssues.csv",
"ExampleIssues.csv"
"ExampleIssues.csv",
"UXMetadataIssues.csv"
};

private static string ExceptionsDirectory { get; set; }
Expand Down Expand Up @@ -142,6 +143,10 @@ public static void Main(string[] args)
{
Analyzers.Add(new HelpAnalyzer.HelpAnalyzer());
}
if (analyzerName.ToLower().Equals("ux"))
{
Analyzers.Add(new UXMetadataAnalyzer.UXMetadataAnalyzer());
}
if (analyzerName.ToLower().Equals("check-error"))
{
needToCheckIssue = true;
Expand All @@ -154,6 +159,7 @@ public static void Main(string[] args)
Analyzers.Add(new DependencyAnalyzer.DependencyAnalyzer());
Analyzers.Add(new SignatureVerifier.SignatureVerifier());
Analyzers.Add(new HelpAnalyzer.HelpAnalyzer());
Analyzers.Add(new UXMetadataAnalyzer.UXMetadataAnalyzer());
needToCheckIssue = true;
}

Expand Down
5 changes: 5 additions & 0 deletions tools/StaticAnalysis/ReportRecordFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using StaticAnalysis.HelpAnalyzer;
using StaticAnalysis.SignatureVerifier;
using StaticAnalysis.ExampleAnalyzer;
using StaticAnalysis.UXMetadataAnalyzer;

using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -63,6 +64,10 @@ public static IReportRecord Create(string type)
{
return new ExampleIssue();
}
if (type.Equals(typeof(UXMetadataIssue).FullName))
{
return new UXMetadataIssue();
}

return null;
}
Expand Down
2 changes: 2 additions & 0 deletions tools/StaticAnalysis/StaticAnalysis.Netcore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.6" />
<PackageReference Include="NJsonSchema" Version="10.8.0" />
<PackageReference Include="System.Reflection.MetadataLoadContext" Version="5.0.0" />
</ItemGroup>

Expand Down Expand Up @@ -52,6 +53,7 @@
<EmbeddedResource Remove="StaticAnalysis.Test\**" />
<None Remove="StaticAnalysis.Test\**" />
<Content Include="log4net.config" CopyToOutputDirectory="PreserveNewest" />
<Content Include="UXMetadataAnalyzer\PortalInputSchema.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 5673141

Please sign in to comment.