From 2eaba753187ce26f7c0016b8ea790ca2fa76f025 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Wed, 27 Mar 2019 18:19:50 -0400 Subject: [PATCH] Working with Build Options --- ZertoApiWrapper.build.ps1 | 63 ++++++++++++++++++++++++------ ZertoApiWrapper.build.ps1.old | 32 +++++++++++++++ ZertoApiWrapper.settings.ps1 | 73 +++++++++++++++++++++++++++++++++++ version.txt | 1 + 4 files changed, 157 insertions(+), 12 deletions(-) create mode 100644 ZertoApiWrapper.build.ps1.old create mode 100644 version.txt diff --git a/ZertoApiWrapper.build.ps1 b/ZertoApiWrapper.build.ps1 index 4ae2195..ebcc81e 100644 --- a/ZertoApiWrapper.build.ps1 +++ b/ZertoApiWrapper.build.ps1 @@ -1,17 +1,45 @@ -task . InstallDependencies, Analyze +#Requires -Modules 'InvokeBuild' -task InstallDependencies { - Install-Module Pester -Force - Install-Module PSScriptAnalyzer -Force +. '.\ZertoApiWrapper.settings.ps1' +import-module .\ZertoApiWrapper\ZertoApiWrapper.psd1 + +[CmdletBinding()] +param([switch]$Install, + [string]$Configuration = (property Configuration Release)) + +$targetDir = "temp/$Configuration/ZertoApiWrapper" + +task . Analyze + +<# Synopsis: Ensure platyPS is installed #> +task CheckPlatyPSInstalled { + if ($null -eq (Get-Module -List platyPS)) { + Install-Module -Scope CurrentUser -Repository PSGallery -Name platyPS + } } -task Analyze { +<# Synopsis: Ensure Pester is installed #> +task CheckPesterInstalled { + if ($null -eq (Get-Module -List Pester)) { + Install-Module -Scope CurrentUser -Repository PSGallery -Name Pester + } +} + +<# Synopsis: Ensure PSScriptAnalyzer is installed #> +task CheckPSScriptAnalyzerInstalled { + if ($null -eq (Get-Module -List PSScriptAnalyzer)) { + Install-Module -Scope CurrentUser -Repository PSGallery -Name PSScriptAnalyzer + } +} + +<# Synopsis: Analyze ZertoApiWrapper functions for Code Violations #> +task Analyze CheckPSScriptAnalyzerInstalled, CheckPesterInstalled, CheckPlatyPSInstalled, { $scriptAnalyzerParams = @{ Path = "$BuildRoot\ZertoApiWrapper\" Severity = @('Error', 'Warning') Recurse = $true Verbose = $false - ExcludeRule = 'PSUseDeclaredVarsMoreThanAssignments' + ExcludeRule = @('PSUseDeclaredVarsMoreThanAssignments', 'PSUseShouldProcessForStateChangingFunctions') } $saresults = Invoke-ScriptAnalyzer @scriptAnalyzerParams @@ -21,12 +49,23 @@ task Analyze { } } -task FileTests { - Invoke-Pester "$BuildRoot\Tests\Public\ZertoApiWrapper.Tests.ps1" +$buildMamlParams = @{ + Inputs = { Get-ChildItem docs/*.md } + Outputs = "$targetDir/en-us/ZertoApiWrapper-help.xml" } -task BuildPsd1 { - $functionsToExportPath = "{0}\ZertoApiWrapper\Public\" -f $MyInvocation.MyCommand.PSPath - $functionsToExport = (Get-ChildItem -Path $functionsToExportPath -File).name.Replace('.ps1', '') - $functionsToExport +task BuildMamlHelp @buildMamlParams { + platyPS\New-ExternalHelp .\docs -Force -OutputPath $buildMamlParams.Outputs +} + +task FileTests CheckPesterInstalled, { + Invoke-Pester "$BuildRoot\Tests\Public\ZertoApiWrapper.Tests.ps1" -Show Fails +} + +task UpdateModuleManifest { + $functionsToExportPath = "$BuildRoot\ZertoApiWrapper\Public\" + $functionsToExport = (Get-ChildItem -Path $functionsToExportPath -File).name.Replace('.ps1', '') + $version = Get-Module -Name ZertoApiWrapper | select Version + $buildVersion = $version.Build + } diff --git a/ZertoApiWrapper.build.ps1.old b/ZertoApiWrapper.build.ps1.old new file mode 100644 index 0000000..39640d6 --- /dev/null +++ b/ZertoApiWrapper.build.ps1.old @@ -0,0 +1,32 @@ +task . FileTests, BuildPsd1, Analyze + +task InstallDependencies { + Install-Module Pester -Force + Install-Module PSScriptAnalyzer -Force +} + +task Analyze { + $scriptAnalyzerParams = @{ + Path = "$BuildRoot\ZertoApiWrapper\" + Severity = @('Error', 'Warning') + Recurse = $true + Verbose = $false + ExcludeRule = @('PSUseDeclaredVarsMoreThanAssignments','PSUseShouldProcessForStateChangingFunctions') + } + $saresults = Invoke-ScriptAnalyzer @scriptAnalyzerParams + + if ($saResults) { + $saResults | Format-Table + throw "One or more PSScriptAnalyzer errors/warnings were found" + } +} + +task FileTests { + Invoke-Pester "$BuildRoot\Tests\Public\ZertoApiWrapper.Tests.ps1" +} + +task BuildPsd1 { + $functionsToExportPath = "$BuildRoot\ZertoApiWrapper\Public\" + $functionsToExport = (Get-ChildItem -Path $functionsToExportPath -File).name.Replace('.ps1', '') + $functionsToExport +} diff --git a/ZertoApiWrapper.settings.ps1 b/ZertoApiWrapper.settings.ps1 index e69de29..f18f9da 100644 --- a/ZertoApiWrapper.settings.ps1 +++ b/ZertoApiWrapper.settings.ps1 @@ -0,0 +1,73 @@ +# This file stores variables which are used by the build script + +# Storing all values in a single $Settings variable to make it obvious that the values are coming from this BuildSettings file when accessing them. +$Settings = @{ + + BuildOutput = "$PSScriptRoot\BuildOutput" + Dependency = @('Pester', 'PsScriptAnalyzer', 'platyPS') + SourceFolder = "$PSScriptRoot\ZertoApiWrapper" + #SourceFolder = "$PSScriptRoot\$($env:APPVEYOR_PROJECT_NAME)" + #TestUploadUrl = "https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)" + #CoverallsKey = $env:Coveralls_Key + #Branch = $env:APPVEYOR_REPO_BRANCH + + UnitTestParams = @{ + Script = '.\Tests\Unit' + CodeCoverage = (Get-ChildItem -Path '.\PSCodeHealth\' -File -Filter "*.ps1" -Recurse).FullName | Where-Object { $_ -Match "Public|Private" } + OutputFile = "$PSScriptRoot\BuildOutput\UnitTestsResult.xml" + PassThru = $True + } + + IntegrationTestParams = @{ + Script = '.\Tests\Integration' + OutputFile = "$PSScriptRoot\BuildOutput\IntegrationTestsResult.xml" + PassThru = $True + } + + AnalyzeParams = @{ + Path = "$PSScriptRoot\$($env:APPVEYOR_PROJECT_NAME)" + Severity = 'Error' + Recurse = $True + } + + IsPullRequest = ($env:APPVEYOR_PULL_REQUEST_NUMBER -gt 0) + Version = $env:APPVEYOR_BUILD_VERSION + ManifestPath = '{0}\{1}\{1}.psd1' -f $PSScriptRoot, $env:APPVEYOR_PROJECT_NAME + VersionRegex = "ModuleVersion\s=\s'(?\S+)'" -as [regex] + + ModuleName = $env:APPVEYOR_PROJECT_NAME + HeaderPath = "$PSScriptRoot\header-mkdocs.yml" + MkdocsPath = "$PSScriptRoot\mkdocs.yml" + PublicFunctionDocsPath = "$PSScriptRoot\docs\PublicFunctions" + PlatyPSParams = @{ + Module = $env:APPVEYOR_PROJECT_NAME + OutputFolder = "$PSScriptRoot\docs\PublicFunctions" + NoMetadata = $True + Force = $True + } + PrivateFunctionDocsPath = "$PSScriptRoot\docs\InternalFunctions" + InternalDocsPlatyPSParams = @{ + OutputFolder = "$PSScriptRoot\docs\InternalFunctions" + WarningAction = 'SilentlyContinue' + NoMetadata = $True + Force = $True + } + FunctionsToExclude = @('Write-VerboseOutput', 'Get-SwitchCombination') + + GitHubKey = $env:GitHub_Key + Email = 'MathieuBuisson@users.noreply.github.com' + Name = 'Mathieu Buisson' + ScreenshotPath = "$($env:TEMP)\*Screenshot.png" + PSGalleryKey = $env:PSGallery_Key + OutputModulePath = "$PSScriptRoot\BuildOutput\$($env:APPVEYOR_PROJECT_NAME)" +} + +$ModuleManifestParams = @{ + RootModule = "ZertoApiWrapper" + GUID = '4c0b9e17-141b-4dd5-8549-fb21cccaa325' + Author = 'Wes Carroll' + CompanyName = 'Zerto' + Copyright = "(c) $(Get-Date -Format "yyyy") Wes Carroll. All rights reserved." + Description = 'PowerShell Core Wrapper Module for Zerto Virtual Manager API' + PowerShellVersion = '6.0.0' +} diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.1.0