2020-02-06 14:22:54 +03:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
|
|
|
# Licensed under the MIT License.
|
2019-05-16 13:56:28 +03:00
|
|
|
|
|
|
|
[CmdletBinding()]
|
|
|
|
param (
|
|
|
|
[Parameter(Mandatory = $False)]
|
2019-06-10 16:19:29 +03:00
|
|
|
[String]$Build = '0.0.1',
|
2019-05-16 13:56:28 +03:00
|
|
|
|
|
|
|
[Parameter(Mandatory = $False)]
|
|
|
|
[String]$Configuration = 'Debug',
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $False)]
|
2019-06-10 16:19:29 +03:00
|
|
|
[String]$ApiKey,
|
2019-05-16 13:56:28 +03:00
|
|
|
|
|
|
|
[Parameter(Mandatory = $False)]
|
|
|
|
[Switch]$CodeCoverage = $False,
|
|
|
|
|
2021-03-15 09:11:08 +03:00
|
|
|
[Parameter(Mandatory = $False)]
|
|
|
|
[Switch]$Benchmark = $False,
|
|
|
|
|
2019-05-16 13:56:28 +03:00
|
|
|
[Parameter(Mandatory = $False)]
|
2019-12-28 17:57:35 +03:00
|
|
|
[String]$ArtifactPath = (Join-Path -Path $PWD -ChildPath out/modules),
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $False)]
|
2021-05-05 18:46:24 +03:00
|
|
|
[String]$AssertStyle = 'AzurePipelines',
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $False)]
|
|
|
|
[String]$TestGroup = $Null
|
2019-05-16 13:56:28 +03:00
|
|
|
)
|
|
|
|
|
2020-02-10 16:57:25 +03:00
|
|
|
Write-Host -Object "[Pipeline] -- PowerShell: v$($PSVersionTable.PSVersion.ToString())" -ForegroundColor Green;
|
2019-06-10 16:19:29 +03:00
|
|
|
Write-Host -Object "[Pipeline] -- PWD: $PWD" -ForegroundColor Green;
|
|
|
|
Write-Host -Object "[Pipeline] -- ArtifactPath: $ArtifactPath" -ForegroundColor Green;
|
|
|
|
Write-Host -Object "[Pipeline] -- BuildNumber: $($Env:BUILD_BUILDNUMBER)" -ForegroundColor Green;
|
|
|
|
Write-Host -Object "[Pipeline] -- SourceBranch: $($Env:BUILD_SOURCEBRANCH)" -ForegroundColor Green;
|
|
|
|
Write-Host -Object "[Pipeline] -- SourceBranchName: $($Env:BUILD_SOURCEBRANCHNAME)" -ForegroundColor Green;
|
2020-02-06 14:22:54 +03:00
|
|
|
Write-Host -Object "[Pipeline] -- Culture: $((Get-Culture).Name), $((Get-Culture).Parent)" -ForegroundColor Green;
|
2019-06-10 16:19:29 +03:00
|
|
|
|
2019-05-16 13:56:28 +03:00
|
|
|
if ($Env:SYSTEM_DEBUG -eq 'true') {
|
|
|
|
$VerbosePreference = 'Continue';
|
|
|
|
}
|
|
|
|
|
2021-04-08 19:19:20 +03:00
|
|
|
$forcePublish = $False;
|
|
|
|
if ($Env:FORCE_PUBLISH -eq 'true') {
|
|
|
|
$forcePublish = $True;
|
|
|
|
}
|
|
|
|
|
2021-01-25 06:34:06 +03:00
|
|
|
if ($Env:BUILD_SOURCEBRANCH -like '*/tags/*' -and $Env:BUILD_SOURCEBRANCHNAME -like 'v1.*') {
|
2019-06-10 16:19:29 +03:00
|
|
|
$Build = $Env:BUILD_SOURCEBRANCHNAME.Substring(1);
|
2019-05-16 13:56:28 +03:00
|
|
|
}
|
|
|
|
|
2019-06-10 16:19:29 +03:00
|
|
|
$version = $Build;
|
|
|
|
$versionSuffix = [String]::Empty;
|
|
|
|
|
|
|
|
if ($version -like '*-*') {
|
|
|
|
[String[]]$versionParts = $version.Split('-', [System.StringSplitOptions]::RemoveEmptyEntries);
|
|
|
|
$version = $versionParts[0];
|
|
|
|
|
|
|
|
if ($versionParts.Length -eq 2) {
|
|
|
|
$versionSuffix = $versionParts[1];
|
|
|
|
}
|
2019-05-24 02:57:41 +03:00
|
|
|
}
|
|
|
|
|
2019-06-10 16:19:29 +03:00
|
|
|
Write-Host -Object "[Pipeline] -- Using version: $version" -ForegroundColor Green;
|
|
|
|
Write-Host -Object "[Pipeline] -- Using versionSuffix: $versionSuffix" -ForegroundColor Green;
|
2019-05-17 14:25:30 +03:00
|
|
|
|
2020-02-22 08:33:04 +03:00
|
|
|
if ($Env:COVERAGE -eq 'true') {
|
2019-07-28 17:17:15 +03:00
|
|
|
$CodeCoverage = $True;
|
|
|
|
}
|
|
|
|
|
2019-05-16 13:56:28 +03:00
|
|
|
# Copy the PowerShell modules files to the destination path
|
|
|
|
function CopyModuleFiles {
|
|
|
|
param (
|
|
|
|
[Parameter(Mandatory = $True)]
|
|
|
|
[String]$Path,
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $True)]
|
|
|
|
[String]$DestinationPath
|
|
|
|
)
|
|
|
|
|
|
|
|
process {
|
|
|
|
$sourcePath = Resolve-Path -Path $Path;
|
|
|
|
|
2022-03-30 14:45:52 +03:00
|
|
|
Get-ChildItem -Path $sourcePath -Recurse -File -Include *.ps1, *.psm1, *.psd1, *.ps1xml, *.yaml | Where-Object -FilterScript {
|
2019-05-16 13:56:28 +03:00
|
|
|
($_.FullName -notmatch '(\.(cs|csproj)|(\\|\/)(obj|bin))')
|
|
|
|
} | ForEach-Object -Process {
|
|
|
|
$filePath = $_.FullName.Replace($sourcePath, $destinationPath);
|
|
|
|
|
|
|
|
$parentPath = Split-Path -Path $filePath -Parent;
|
|
|
|
|
|
|
|
if (!(Test-Path -Path $parentPath)) {
|
|
|
|
$Null = New-Item -Path $parentPath -ItemType Directory -Force;
|
|
|
|
}
|
|
|
|
|
|
|
|
Copy-Item -Path $_.FullName -Destination $filePath -Force;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-19 10:57:11 +03:00
|
|
|
task VersionModule ModuleDependencies, {
|
2019-05-17 14:25:30 +03:00
|
|
|
$modulePath = Join-Path -Path $ArtifactPath -ChildPath PSRule.Rules.Azure;
|
|
|
|
$manifestPath = Join-Path -Path $modulePath -ChildPath PSRule.Rules.Azure.psd1;
|
|
|
|
Write-Verbose -Message "[VersionModule] -- Checking module path: $modulePath";
|
|
|
|
|
2019-06-10 16:19:29 +03:00
|
|
|
if (![String]::IsNullOrEmpty($Build)) {
|
2019-05-16 13:56:28 +03:00
|
|
|
# Update module version
|
|
|
|
if (![String]::IsNullOrEmpty($version)) {
|
|
|
|
Write-Verbose -Message "[VersionModule] -- Updating module manifest ModuleVersion";
|
2019-05-17 14:25:30 +03:00
|
|
|
Update-ModuleManifest -Path $manifestPath -ModuleVersion $version;
|
2019-05-16 13:56:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Update pre-release version
|
2019-06-10 16:19:29 +03:00
|
|
|
if (![String]::IsNullOrEmpty($versionSuffix)) {
|
2019-05-16 13:56:28 +03:00
|
|
|
Write-Verbose -Message "[VersionModule] -- Updating module manifest Prerelease";
|
2019-06-10 16:19:29 +03:00
|
|
|
Update-ModuleManifest -Path $manifestPath -Prerelease $versionSuffix;
|
2019-05-16 13:56:28 +03:00
|
|
|
}
|
|
|
|
}
|
2019-06-10 16:19:29 +03:00
|
|
|
|
2022-01-16 15:36:55 +03:00
|
|
|
$dependencies = Get-Content -Path $PWD/modules.json -Raw | ConvertFrom-Json;
|
2019-06-10 16:19:29 +03:00
|
|
|
$manifest = Test-ModuleManifest -Path $manifestPath;
|
|
|
|
$requiredModules = $manifest.RequiredModules | ForEach-Object -Process {
|
|
|
|
if ($_.Name -eq 'PSRule' -and $Configuration -eq 'Release') {
|
2022-01-16 15:36:55 +03:00
|
|
|
@{ ModuleName = 'PSRule'; ModuleVersion = $dependencies.dependencies.PSRule.version }
|
2019-06-10 16:19:29 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
@{ ModuleName = $_.Name; ModuleVersion = $_.Version }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Update-ModuleManifest -Path $manifestPath -RequiredModules $requiredModules;
|
2022-05-05 13:14:28 +03:00
|
|
|
|
|
|
|
# Update -nodeps manifest
|
|
|
|
$manifestPath = Join-Path -Path $modulePath -ChildPath PSRule.Rules.Azure-nodeps.psd1;
|
|
|
|
if (![String]::IsNullOrEmpty($Build)) {
|
|
|
|
# Update module version
|
|
|
|
if (![String]::IsNullOrEmpty($version)) {
|
|
|
|
Write-Verbose -Message "[VersionModule] -- Updating module manifest ModuleVersion";
|
|
|
|
Update-ModuleManifest -Path $manifestPath -ModuleVersion $version;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Update pre-release version
|
|
|
|
if (![String]::IsNullOrEmpty($versionSuffix)) {
|
|
|
|
Write-Verbose -Message "[VersionModule] -- Updating module manifest Prerelease";
|
|
|
|
Update-ModuleManifest -Path $manifestPath -Prerelease $versionSuffix;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$dependencies = Get-Content -Path $PWD/modules.json -Raw | ConvertFrom-Json;
|
|
|
|
$manifest = Test-ModuleManifest -Path $manifestPath;
|
|
|
|
$requiredModules = $manifest.RequiredModules | ForEach-Object -Process {
|
|
|
|
if ($_.Name -eq 'PSRule' -and $Configuration -eq 'Release') {
|
|
|
|
@{ ModuleName = 'PSRule'; ModuleVersion = $dependencies.dependencies.PSRule.version }
|
|
|
|
}
|
2022-05-05 16:30:31 +03:00
|
|
|
else {
|
|
|
|
@{ ModuleName = $_.Name; ModuleVersion = $_.Version }
|
|
|
|
}
|
2022-05-05 13:14:28 +03:00
|
|
|
};
|
|
|
|
Update-ModuleManifest -Path $manifestPath -RequiredModules $requiredModules;
|
2019-05-16 13:56:28 +03:00
|
|
|
}
|
|
|
|
|
2019-05-19 10:57:11 +03:00
|
|
|
# Synopsis: Publish to PowerShell Gallery
|
2019-05-16 13:56:28 +03:00
|
|
|
task ReleaseModule VersionModule, {
|
2019-05-17 14:25:30 +03:00
|
|
|
$modulePath = (Join-Path -Path $ArtifactPath -ChildPath PSRule.Rules.Azure);
|
|
|
|
Write-Verbose -Message "[ReleaseModule] -- Checking module path: $modulePath";
|
|
|
|
|
|
|
|
if (!(Test-Path -Path $modulePath)) {
|
|
|
|
Write-Error -Message "[ReleaseModule] -- Module path does not exist";
|
|
|
|
}
|
2019-06-10 16:53:22 +03:00
|
|
|
elseif (![String]::IsNullOrEmpty($ApiKey)) {
|
2021-04-08 19:19:20 +03:00
|
|
|
Publish-Module -Path $modulePath -NuGetApiKey $ApiKey -Force:$forcePublish;
|
2019-05-16 13:56:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Synopsis: Install NuGet provider
|
|
|
|
task NuGet {
|
|
|
|
if ($Null -eq (Get-PackageProvider -Name NuGet -ErrorAction Ignore)) {
|
|
|
|
Install-PackageProvider -Name NuGet -Force -Scope CurrentUser;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-19 10:57:11 +03:00
|
|
|
# Synopsis: Install module dependencies
|
2022-01-16 15:36:55 +03:00
|
|
|
task ModuleDependencies Dependencies, {
|
2019-05-19 10:57:11 +03:00
|
|
|
}
|
|
|
|
|
2019-11-09 09:19:07 +03:00
|
|
|
task BuildDotNet {
|
|
|
|
exec {
|
|
|
|
# Build library
|
2022-06-25 14:42:01 +03:00
|
|
|
dotnet build src/SDK -c $Configuration -f netstandard2.0 -p:version=$Build
|
2020-02-22 08:33:04 +03:00
|
|
|
dotnet publish src/PSRule.Rules.Azure -c $Configuration -f netstandard2.0 -o $(Join-Path -Path $PWD -ChildPath out/modules/PSRule.Rules.Azure) -p:version=$Build
|
2019-11-09 09:19:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
task TestDotNet {
|
|
|
|
if ($CodeCoverage) {
|
|
|
|
exec {
|
|
|
|
# Test library
|
|
|
|
dotnet test --collect:"Code Coverage" --logger trx -r (Join-Path $PWD -ChildPath reports/) tests/PSRule.Rules.Azure.Tests
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
exec {
|
|
|
|
# Test library
|
|
|
|
dotnet test --logger trx -r (Join-Path $PWD -ChildPath reports/) tests/PSRule.Rules.Azure.Tests
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-05 00:24:09 +03:00
|
|
|
task BuildDataIndex {
|
|
|
|
dotnet run --project .\src\PSRule.Rules.Azure.BuildTool -- provider
|
2020-09-28 16:53:50 +03:00
|
|
|
}
|
|
|
|
|
2022-05-05 00:24:09 +03:00
|
|
|
task CopyModule {
|
2019-05-16 13:56:28 +03:00
|
|
|
CopyModuleFiles -Path src/PSRule.Rules.Azure -DestinationPath out/modules/PSRule.Rules.Azure;
|
2019-12-02 15:06:23 +03:00
|
|
|
|
2020-09-26 14:34:17 +03:00
|
|
|
# Copy LICENSE
|
|
|
|
Copy-Item -Path LICENSE -Destination out/modules/PSRule.Rules.Azure;
|
|
|
|
|
2019-12-02 15:06:23 +03:00
|
|
|
# Copy third party notices
|
|
|
|
Copy-Item -Path ThirdPartyNotices.txt -Destination out/modules/PSRule.Rules.Azure;
|
2019-05-16 13:56:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Synopsis: Build modules only
|
2019-11-09 09:19:07 +03:00
|
|
|
task BuildModule BuildDotNet, CopyModule
|
2019-05-16 13:56:28 +03:00
|
|
|
|
2022-01-16 15:36:55 +03:00
|
|
|
task TestModule ModuleDependencies, BicepIntegrationTests, {
|
2019-05-16 13:56:28 +03:00
|
|
|
# Run Pester tests
|
2021-08-08 15:08:57 +03:00
|
|
|
$pesterOptions = @{
|
2022-03-30 14:45:52 +03:00
|
|
|
Run = @{
|
|
|
|
Path = (Join-Path -Path $PWD -ChildPath tests/PSRule.Rules.Azure.Tests);
|
2021-08-08 15:08:57 +03:00
|
|
|
PassThru = $True;
|
|
|
|
};
|
|
|
|
TestResult = @{
|
2022-03-30 14:45:52 +03:00
|
|
|
Enabled = $True;
|
2021-08-08 15:08:57 +03:00
|
|
|
OutputFormat = 'NUnitXml';
|
2022-03-30 14:45:52 +03:00
|
|
|
OutputPath = 'reports/pester-unit.xml';
|
2021-08-08 15:08:57 +03:00
|
|
|
};
|
|
|
|
};
|
2019-05-16 13:56:28 +03:00
|
|
|
|
2019-05-19 10:57:11 +03:00
|
|
|
if ($CodeCoverage) {
|
2021-08-08 15:08:57 +03:00
|
|
|
$codeCoverageOptions = @{
|
2022-03-30 14:45:52 +03:00
|
|
|
Enabled = $True;
|
2021-08-08 15:08:57 +03:00
|
|
|
OutputPath = (Join-Path -Path $PWD -ChildPath 'reports/pester-coverage.xml');
|
2022-03-30 14:45:52 +03:00
|
|
|
Path = (Join-Path -Path $PWD -ChildPath 'out/modules/**/*.psm1');
|
2021-08-08 15:08:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
$pesterOptions.Add('CodeCoverage', $codeCoverageOptions);
|
2019-05-19 10:57:11 +03:00
|
|
|
}
|
|
|
|
|
2019-05-16 13:56:28 +03:00
|
|
|
if (!(Test-Path -Path reports)) {
|
|
|
|
$Null = New-Item -Path reports -ItemType Directory -Force;
|
|
|
|
}
|
|
|
|
|
2021-05-05 18:46:24 +03:00
|
|
|
if ($Null -ne $TestGroup) {
|
2021-08-08 15:08:57 +03:00
|
|
|
$pesterOptions.Add('Filter', @{ Tag = $TestGroup });
|
2021-05-05 18:46:24 +03:00
|
|
|
}
|
|
|
|
|
2021-08-08 15:08:57 +03:00
|
|
|
# https://pester.dev/docs/commands/New-PesterConfiguration
|
|
|
|
$pesterConfiguration = New-PesterConfiguration -Hashtable $pesterOptions;
|
|
|
|
|
|
|
|
$results = Invoke-Pester -Configuration $pesterConfiguration;
|
2019-05-16 13:56:28 +03:00
|
|
|
|
|
|
|
# Throw an error if pester tests failed
|
|
|
|
if ($Null -eq $results) {
|
|
|
|
throw 'Failed to get Pester test results.';
|
|
|
|
}
|
|
|
|
elseif ($results.FailedCount -gt 0) {
|
|
|
|
throw "$($results.FailedCount) tests failed.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-18 03:39:35 +03:00
|
|
|
task IntegrationTest ModuleDependencies, {
|
2020-09-28 16:53:50 +03:00
|
|
|
# Run Pester tests
|
2021-08-08 15:08:57 +03:00
|
|
|
$pesterOptions = @{
|
2022-03-30 14:45:52 +03:00
|
|
|
Run = @{
|
|
|
|
Path = (Join-Path -Path $PWD -ChildPath tests/Integration);
|
2021-08-08 15:08:57 +03:00
|
|
|
PassThru = $True;
|
|
|
|
};
|
|
|
|
TestResult = @{
|
2022-03-30 14:45:52 +03:00
|
|
|
Enabled = $True;
|
2021-08-08 15:08:57 +03:00
|
|
|
OutputFormat = 'NUnitXml';
|
2022-03-30 14:45:52 +03:00
|
|
|
OutputPath = 'reports/pester-unit.xml';
|
2021-08-08 15:08:57 +03:00
|
|
|
};
|
|
|
|
};
|
2020-09-28 16:53:50 +03:00
|
|
|
|
|
|
|
if (!(Test-Path -Path reports)) {
|
|
|
|
$Null = New-Item -Path reports -ItemType Directory -Force;
|
|
|
|
}
|
|
|
|
|
2021-08-08 15:08:57 +03:00
|
|
|
# https://pester.dev/docs/commands/New-PesterConfiguration
|
|
|
|
$pesterConfiguration = New-PesterConfiguration -Hashtable $pesterOptions;
|
|
|
|
|
|
|
|
$results = Invoke-Pester -Configuration $pesterConfiguration
|
2020-09-28 16:53:50 +03:00
|
|
|
|
|
|
|
# Throw an error if pester tests failed
|
|
|
|
if ($Null -eq $results) {
|
|
|
|
throw 'Failed to get Pester test results.';
|
|
|
|
}
|
|
|
|
elseif ($results.FailedCount -gt 0) {
|
|
|
|
throw "$($results.FailedCount) tests failed.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-04 04:52:56 +03:00
|
|
|
task BicepIntegrationTests {
|
|
|
|
if ($Env:RUN_BICEP_INTEGRATION -eq 'true') {
|
|
|
|
# Run Pester tests
|
2021-08-08 15:08:57 +03:00
|
|
|
$pesterOptions = @{
|
2022-03-30 14:45:52 +03:00
|
|
|
Run = @{
|
|
|
|
Path = (Join-Path -Path $PWD -ChildPath tests/Bicep);
|
2021-08-08 15:08:57 +03:00
|
|
|
PassThru = $True;
|
|
|
|
};
|
|
|
|
TestResult = @{
|
2022-03-30 14:45:52 +03:00
|
|
|
Enabled = $True;
|
2021-08-08 15:08:57 +03:00
|
|
|
OutputFormat = 'NUnitXml';
|
2022-03-30 14:45:52 +03:00
|
|
|
OutputPath = 'reports/bicep-integration.xml';
|
2021-08-08 15:08:57 +03:00
|
|
|
};
|
|
|
|
};
|
2021-08-04 04:52:56 +03:00
|
|
|
|
|
|
|
if (!(Test-Path -Path reports)) {
|
|
|
|
$Null = New-Item -Path reports -ItemType Directory -Force;
|
|
|
|
}
|
|
|
|
|
2021-08-08 15:08:57 +03:00
|
|
|
# https://pester.dev/docs/commands/New-PesterConfiguration
|
|
|
|
$pesterConfiguration = New-PesterConfiguration -Hashtable $pesterOptions;
|
|
|
|
|
|
|
|
$results = Invoke-Pester -Configuration $pesterConfiguration;
|
2021-08-04 04:52:56 +03:00
|
|
|
|
|
|
|
# Throw an error if pester tests failed
|
|
|
|
if ($Null -eq $results) {
|
|
|
|
throw 'Failed to get Pester test results.';
|
|
|
|
}
|
|
|
|
elseif ($results.FailedCount -gt 0) {
|
|
|
|
throw "$($results.FailedCount) tests failed.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-28 17:57:35 +03:00
|
|
|
# Synopsis: Run validation
|
2022-01-16 15:36:55 +03:00
|
|
|
task Rules Dependencies, {
|
2019-12-28 17:57:35 +03:00
|
|
|
$assertParams = @{
|
2022-03-30 14:45:52 +03:00
|
|
|
Path = './.ps-rule/'
|
|
|
|
Style = $AssertStyle
|
2020-04-12 08:02:39 +03:00
|
|
|
OutputFormat = 'NUnit3'
|
2022-03-30 14:45:52 +03:00
|
|
|
ErrorAction = 'Stop'
|
|
|
|
As = 'Summary'
|
2019-12-28 17:57:35 +03:00
|
|
|
}
|
|
|
|
Import-Module (Join-Path -Path $PWD -ChildPath out/modules/PSRule.Rules.Azure) -Force;
|
2021-05-12 18:36:05 +03:00
|
|
|
Assert-PSRule @assertParams -InputPath $PWD -Module PSRule.Rules.MSFT.OSS -Format File -OutputPath reports/ps-rule-file.xml;
|
2019-12-28 17:57:35 +03:00
|
|
|
|
2020-04-12 08:02:39 +03:00
|
|
|
$rules = Get-PSRule -Module PSRule.Rules.Azure;
|
|
|
|
$rules | Assert-PSRule @assertParams -OutputPath reports/ps-rule-file2.xml;
|
2019-12-28 17:57:35 +03:00
|
|
|
}
|
|
|
|
|
2019-05-16 13:56:28 +03:00
|
|
|
# Synopsis: Run script analyzer
|
2022-01-18 03:39:35 +03:00
|
|
|
task Analyze Build, Dependencies, {
|
2019-05-16 13:56:28 +03:00
|
|
|
Invoke-ScriptAnalyzer -Path out/modules/PSRule.Rules.Azure;
|
|
|
|
}
|
|
|
|
|
2021-01-31 13:26:29 +03:00
|
|
|
# Synopsis: Build documentation
|
|
|
|
task BuildDocs BuildRuleDocs, BuildBaselineDocs
|
|
|
|
|
2019-05-16 13:56:28 +03:00
|
|
|
# Synopsis: Build table of content for rules
|
2022-01-18 03:39:35 +03:00
|
|
|
task BuildRuleDocs Build, Dependencies, {
|
2019-06-12 06:48:32 +03:00
|
|
|
Import-Module (Join-Path -Path $PWD -ChildPath out/modules/PSRule.Rules.Azure) -Force;
|
2021-07-25 11:46:13 +03:00
|
|
|
$Null = './out/modules/PSRule.Rules.Azure' | Invoke-PSDocument -Name module -OutputPath ./docs/en/rules/ -Path ./RuleToc.Doc.ps1;
|
|
|
|
$Null = './out/modules/PSRule.Rules.Azure' | Invoke-PSDocument -Name resource -OutputPath ./docs/en/rules/ -Path ./RuleToc.Doc.ps1;
|
2022-05-31 00:25:05 +03:00
|
|
|
|
|
|
|
$metadata = @{}
|
|
|
|
Get-PSRule -Module PSRule.Rules.Azure -Baseline Azure.All | ForEach-Object {
|
|
|
|
$metadata[$_.Name] = [PSCustomObject]@{
|
|
|
|
Name = $_.Name
|
|
|
|
Ref = $_.Ref
|
|
|
|
Alias = @($_.Alias)
|
|
|
|
Flags = $_.Flags
|
|
|
|
Release = $_.Tag.release
|
|
|
|
RuleSet = $_.Tag.ruleSet
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$metadata | ConvertTo-Json -Depth 5 | Set-Content -Path ./docs/en/rules/metadata.json -Force;
|
2019-05-16 13:56:28 +03:00
|
|
|
}
|
|
|
|
|
2020-06-21 11:14:32 +03:00
|
|
|
# Synopsis: Build table of content for baselines
|
2022-01-18 03:39:35 +03:00
|
|
|
task BuildBaselineDocs Build, Dependencies, {
|
2020-06-21 11:14:32 +03:00
|
|
|
Import-Module (Join-Path -Path $PWD -ChildPath out/modules/PSRule.Rules.Azure) -Force;
|
|
|
|
$baselines = Get-PSRuleBaseline -Module PSRule.Rules.Azure -WarningAction SilentlyContinue;
|
2021-09-11 09:40:29 +03:00
|
|
|
$baselines | ForEach-Object {
|
|
|
|
$baselineDoc = [PSCustomObject]@{
|
2022-03-30 14:45:52 +03:00
|
|
|
Name = $_.Name
|
2021-09-11 09:40:29 +03:00
|
|
|
Metadata = $_.Metadata
|
|
|
|
Synopsis = $_.Synopsis
|
2022-03-30 14:45:52 +03:00
|
|
|
Rules = @(Get-PSRule -Module PSRule.Rules.Azure -Baseline $_.Name -WarningAction SilentlyContinue)
|
2021-09-11 09:40:29 +03:00
|
|
|
}
|
|
|
|
$baselineDoc;
|
|
|
|
} | Invoke-PSDocument -Name baseline -OutputPath ./docs/en/baselines/ -Path ./BaselineToc.Doc.ps1 -Convention 'NameBaseline';
|
2020-06-21 11:14:32 +03:00
|
|
|
}
|
|
|
|
|
2019-05-16 13:56:28 +03:00
|
|
|
# Synopsis: Build help
|
2022-01-16 15:36:55 +03:00
|
|
|
task BuildHelp BuildModule, Dependencies, {
|
2020-01-05 16:21:55 +03:00
|
|
|
if (!(Test-Path out/modules/PSRule.Rules.Azure/en/)) {
|
|
|
|
$Null = New-Item -Path out/modules/PSRule.Rules.Azure/en/ -ItemType Directory -Force;
|
|
|
|
}
|
2020-01-17 01:54:28 +03:00
|
|
|
if (!(Test-Path out/modules/PSRule.Rules.Azure/en-US/)) {
|
|
|
|
$Null = New-Item -Path out/modules/PSRule.Rules.Azure/en-US/ -ItemType Directory -Force;
|
|
|
|
}
|
|
|
|
if (!(Test-Path out/modules/PSRule.Rules.Azure/en-AU/)) {
|
|
|
|
$Null = New-Item -Path out/modules/PSRule.Rules.Azure/en-AU/ -ItemType Directory -Force;
|
|
|
|
}
|
|
|
|
if (!(Test-Path out/modules/PSRule.Rules.Azure/en-GB/)) {
|
|
|
|
$Null = New-Item -Path out/modules/PSRule.Rules.Azure/en-GB/ -ItemType Directory -Force;
|
|
|
|
}
|
2020-01-05 16:21:55 +03:00
|
|
|
|
2021-06-17 16:55:40 +03:00
|
|
|
$Null = Copy-Item -Path docs/en/rules/*.md -Destination out/modules/PSRule.Rules.Azure/en/;
|
2020-03-17 14:37:31 +03:00
|
|
|
|
|
|
|
# Avoid YamlDotNet issue in same app domain
|
|
|
|
exec {
|
|
|
|
$pwshPath = (Get-Process -Id $PID).Path;
|
|
|
|
&$pwshPath -Command {
|
|
|
|
# Generate MAML and about topics
|
|
|
|
Import-Module -Name PlatyPS -Verbose:$False;
|
2021-06-17 16:55:40 +03:00
|
|
|
$Null = New-ExternalHelp -OutputPath 'out/docs/PSRule.Rules.Azure' -Path './docs/commands', './docs/concepts' -Force;
|
2020-03-17 14:37:31 +03:00
|
|
|
|
2022-03-30 14:45:52 +03:00
|
|
|
# Copy generated help into module out path
|
2020-03-17 14:37:31 +03:00
|
|
|
$Null = Copy-Item -Path out/docs/PSRule.Rules.Azure/* -Destination out/modules/PSRule.Rules.Azure/en-US/ -Recurse;
|
|
|
|
$Null = Copy-Item -Path out/docs/PSRule.Rules.Azure/* -Destination out/modules/PSRule.Rules.Azure/en-AU/ -Recurse;
|
|
|
|
$Null = Copy-Item -Path out/docs/PSRule.Rules.Azure/* -Destination out/modules/PSRule.Rules.Azure/en-GB/ -Recurse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(Test-Path -Path 'out/docs/PSRule.Rules.Azure/PSRule.Rules.Azure-help.xml')) {
|
|
|
|
throw 'Failed find generated cmdlet help.';
|
|
|
|
}
|
2019-05-16 13:56:28 +03:00
|
|
|
}
|
|
|
|
|
2019-06-10 16:19:29 +03:00
|
|
|
task ScaffoldHelp Build, BuildRuleDocs, {
|
2019-05-20 00:32:09 +03:00
|
|
|
Import-Module (Join-Path -Path $PWD -ChildPath out/modules/PSRule.Rules.Azure) -Force;
|
2021-06-17 16:55:40 +03:00
|
|
|
Update-MarkdownHelp -Path '.\docs\commands';
|
2019-05-20 00:32:09 +03:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:11:08 +03:00
|
|
|
task Benchmark {
|
|
|
|
if ($Benchmark -or $BuildTask -eq 'Benchmark') {
|
2022-05-05 00:24:09 +03:00
|
|
|
dotnet run --project src/PSRule.Rules.Azure.Benchmark -f netcoreapp3.1 -c Release -- benchmark --output $PWD;
|
2021-03-15 09:11:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-16 15:36:55 +03:00
|
|
|
task Dependencies NuGet, {
|
|
|
|
Import-Module $PWD/scripts/dependencies.psm1;
|
2022-04-27 18:39:42 +03:00
|
|
|
Install-Dependencies -Path $PWD/modules.json -Dev;
|
2022-01-16 15:36:55 +03:00
|
|
|
}
|
|
|
|
|
2022-05-05 00:24:09 +03:00
|
|
|
task ExportData {
|
|
|
|
Import-Module $PWD/scripts/providers.psm1;
|
|
|
|
Update-Providers;
|
2020-09-28 16:53:50 +03:00
|
|
|
}
|
|
|
|
|
2019-05-16 13:56:28 +03:00
|
|
|
# Synopsis: Remove temp files.
|
|
|
|
task Clean {
|
2021-08-09 09:25:06 +03:00
|
|
|
dotnet clean;
|
2022-03-30 14:45:52 +03:00
|
|
|
Remove-Item -Path out, reports -Recurse -Force -ErrorAction SilentlyContinue;
|
2019-05-16 13:56:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
task Build Clean, BuildModule, VersionModule, BuildHelp
|
|
|
|
|
2020-02-22 08:33:04 +03:00
|
|
|
task Test Build, Rules, TestDotNet, TestModule
|
2019-05-16 13:56:28 +03:00
|
|
|
|
2022-04-26 16:12:05 +03:00
|
|
|
task Release ReleaseModule
|
2019-05-16 13:56:28 +03:00
|
|
|
|
2020-02-22 08:33:04 +03:00
|
|
|
# Synopsis: Build and test. Entry point for CI Build stage
|
|
|
|
task . Build, Rules, TestDotNet
|