Refactor baseline doc generate task (#950)

This commit is contained in:
Bernie White 2021-09-11 16:40:29 +10:00 коммит произвёл GitHub
Родитель 320bc03d07
Коммит 194ba27899
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 24 добавлений и 11 удалений

Просмотреть файл

@ -1,9 +1,16 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
Export-PSDocumentConvention 'NameBaseline' -Process {
$PSDocs.Document.InstanceName = $PSDocs.TargetObject.Name;
}
Document 'baseline' {
$baselineName = $InputObject.Name;
$obsolete = $InputObject.metadata.annotations.obsolete -eq $True;
$baselineName = $PSDocs.TargetObject.Name;
$obsolete = $PSDocs.TargetObject.metadata.annotations.obsolete -eq $True;
Write-Verbose -Message "[Baseline] -- Processing baseline: $baselineName";
Write-Verbose -Message "[Baseline] -- Baseline is obsolete: $obsolete";
Title $baselineName;
@ -11,16 +18,16 @@ Document 'baseline' {
'Obsolete' | BlockQuote
}
Import-Module ./out/modules/PSRule.Rules.Azure;
$rules = @(Get-PSRule -Module PSRule.Rules.Azure -Baseline $baselineName -WarningAction SilentlyContinue);
$rules = $PSDocs.TargetObject.Rules | Sort-Object -Property RuleName;
$ruleCount = $rules.Length;
$InputObject.Synopsis;
$PSDocs.TargetObject.Synopsis;
Section 'Rules' {
"The following rules are included within ``$baselineName``. This baseline includes a total of $ruleCount rules."
Write-Verbose -Message "[Baseline] -- Found $ruleCount rules.";
$rules | Sort-Object -Property RuleName | Table -Property @{ Name = 'Name'; Expression = {
Section 'Rules' -If { $ruleCount -gt 0 } {
"The following rules are included within ``$baselineName``. This baseline includes a total of $ruleCount rules.";
$rules | Table -Property @{ Name = 'Name'; Expression = {
"[$($_.RuleName)](../rules/$($_.RuleName).md)"
}}, Synopsis, @{ Name = 'Severity'; Expression = {
$_.Info.Annotations.severity

Просмотреть файл

@ -407,9 +407,15 @@ task BuildRuleDocs Build, PSRule, PSDocs, {
task BuildBaselineDocs Build, PSRule, PSDocs, {
Import-Module (Join-Path -Path $PWD -ChildPath out/modules/PSRule.Rules.Azure) -Force;
$baselines = Get-PSRuleBaseline -Module PSRule.Rules.Azure -WarningAction SilentlyContinue;
$Null = $baselines | ForEach-Object {
$_ | Invoke-PSDocument -Name baseline -InstanceName $_.Name -OutputPath ./docs/en/baselines/ -Path ./BaselineToc.Doc.ps1;
}
$baselines | ForEach-Object {
$baselineDoc = [PSCustomObject]@{
Name = $_.Name
Metadata = $_.Metadata
Synopsis = $_.Synopsis
Rules = @(Get-PSRule -Module PSRule.Rules.Azure -Baseline $_.Name -WarningAction SilentlyContinue)
}
$baselineDoc;
} | Invoke-PSDocument -Name baseline -OutputPath ./docs/en/baselines/ -Path ./BaselineToc.Doc.ps1 -Convention 'NameBaseline';
}
# Synopsis: Build help