diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d41dbc..1eb7518 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,7 +48,6 @@ jobs: Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null Install-Module -Name Pester -RequiredVersion 5.7.1 -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber Install-Module -Name PSScriptAnalyzer -RequiredVersion 1.25.0 -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber - Install-Module -Name DependsOn -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber - name: Import module from source shell: pwsh @@ -111,7 +110,6 @@ jobs: Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null Install-Module -Name Pester -RequiredVersion 5.7.1 -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber Install-Module -Name PSScriptAnalyzer -RequiredVersion 1.25.0 -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber - Install-Module -Name DependsOn -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber - name: Import module from source shell: powershell diff --git a/BuildTasks/BuildModule.Task.ps1 b/BuildTasks/BuildModule.Task.ps1 index 1e86093..44480f9 100644 --- a/BuildTasks/BuildModule.Task.ps1 +++ b/BuildTasks/BuildModule.Task.ps1 @@ -1,126 +1,3 @@ - -# namespaces for Move-Statement -using namespace System.Collections.Generic -using namespace System.IO -using namespace System.Management.Automation - - -# Temporarily added this here to be refactored/replaced by LDModuleBuilder Module -function Move-Statement -{ -<# -.SYNOPSIS - Moves statements containing a specified token to the specified index in a file. -.DESCRIPTION - Move-Statement moves statements containing a specified token, to the specified index - in a file. This can be used when building a module to move any using directives and - #Requires statements to the top of a file. -.PARAMETER Path - Specifies the path to an item to get its contents. -.PARAMETER Type - Specifies the type of tokens to examine. Accepted values include "Comment" and "Keyword". -.PARAMETER Token - Specifies the contents to filter on when examining a supplied token. -.PARAMETER Index - Specifies the line to move a statement to. Each line in an item has a corresponding - index, starting from 0. -.EXAMPLE - Move-Statement -Path $Path -Type 'Comment', 'Keyword' -Token '#Requires', 'using' -Index 0 - - Moves any using directives or #Requires statements to the top of a file. -.NOTES - Copy/Paste from LDModuleBuilder -#> - [CmdletBinding(SupportsShouldProcess)] - - param( - [Parameter(Mandatory, - Position = 0, - ValueFromPipeline, - ValueFromPipelineByPropertyName)] - [ValidateNotNullOrEmpty()] - [ValidateScript({ Test-Path -Path $PSItem })] - [string] $Path, - - [Parameter(Position = 1, - ValueFromPipelineByPropertyName)] - [ValidateNotNullOrEmpty()] - [ValidateSet('Comment', 'Keyword')] - [string[]] $Type = ('Comment', 'Keyword'), - - [Parameter(Position = 2, - ValueFromPipelineByPropertyName)] - [ValidateNotNullOrEmpty()] - [string[]] $Token = ('#Requires', 'using'), - - [Parameter(Position = 3, - ValueFromPipelineByPropertyName)] - [ValidateNotNullOrEmpty()] - [int] $Index = 0 - ) - - process - { - try - { - $statements = [SortedSet[String]]::new( - [StringComparer]::InvariantCultureIgnoreCase - ) - - Write-Verbose -Message "Reading content from $Path..." - $content = [List[String]] ([File]::ReadLines($Path)) - - Write-Verbose -Message "Tokenizing content from $Path..." - $tokens = [PSParser]::Tokenize($content, [ref] $null) - - $match = $Token -join '|' - - Write-Verbose -Message 'Matching tokens...' - Write-Verbose -Message "Type = [$Type]; Token = [$Token]" - $keywords = $tokens.Where({ - $PSItem.Type -in $Type -and - $PSItem.Content -imatch "^(?:$match)" - }) - - if (-not $keywords) { - Write-Verbose -Message 'No matching tokens found! Returning...' - return - } - - $offset = 1 - foreach ($keyword in $keywords) - { - $line = $keyword.StartLine - $offset - - Write-Verbose -Message "Moving [$($content[$line])] to Index [$Index]..." - $null = $statements.Add($content[$line]), - $content.RemoveAt($line) - $offset++ - } - - [string[]] $comments, [string[]] $statements = $statements.Where({ - $PSItem -match '^#' - }, 'Split') - - foreach ($item in ($statements, $comments)) - { - $content.Insert($Index, '') - $content.InsertRange($Index, $item) - } - - if ($PSCmdlet.ShouldProcess($Path, $MyInvocation.MyCommand.Name)) - { - Write-Verbose -Message "Writing content to $Path..." - [File]::WriteAllLines($Path, $content) - } - } - catch - { - $PSCmdlet.ThrowTerminatingError($PSItem) - } - } -} - taskx BuildModule @{ Inputs = (Get-ChildItem -Path $Source -Recurse -Filter *.ps1) Outputs = $ModulePath @@ -128,43 +5,7 @@ taskx BuildModule @{ $sb = [Text.StringBuilder]::new() $null = $sb.AppendLine('$Script:PSModuleRoot = $PSScriptRoot') - # Class importer - $root = Join-Path -Path $source -ChildPath 'Classes' - "Load classes from [$root]" - $classFiles = Get-ChildItem -Path $root -Filter '*.ps1' -Recurse | - Where-Object Name -notlike '*.Tests.ps1' - - $classes = @{} - - foreach($file in $classFiles) - { - $name = $file.BaseName - $classes[$name] = @{ - Name = $name - Path = $file.FullName - } - $data = Get-Content $file.fullname - foreach($line in $data) - { - if($line -match "\s+($Name)\s*(:|requires)\s*(?\w*)|\[(?\w+)\]") - { - $classes[$name].Base += @($Matches.baseclass) - } - } - } - - $importOrder = $classes.GetEnumerator() | - Resolve-DependencyOrder -Key {$_.Name} -DependsOn {$_.Value.Base} - - foreach($class in $importOrder) - { - $classPath = $class.Value.Path - "Importing [$classPath]..." - $null = $sb.AppendLine("# .$classPath") - $null = $sb.AppendLine([IO.File]::ReadAllText($classPath)) - } - - foreach ($folder in ($Folders -ne 'Classes')) + foreach ($folder in $Folders) { if (Test-Path -Path "$Source\$folder") { @@ -186,8 +27,5 @@ taskx BuildModule @{ "Creating Module [$ModulePath]..." $null = New-Item -Path (Split-path $ModulePath) -ItemType Directory -ErrorAction SilentlyContinue -Force Set-Content -Path $ModulePath -Value $sb.ToString() -Encoding 'UTF8' - - 'Moving "#Requires" statements and "using" directives...' - Move-Statement -Path $ModulePath -Type 'Comment', 'Keyword' -Token '#Requires', 'using' -Index 0 } } diff --git a/BuildTasks/InvokeBuildInit.ps1 b/BuildTasks/InvokeBuildInit.ps1 index 620e51d..9b4b3c6 100644 --- a/BuildTasks/InvokeBuildInit.ps1 +++ b/BuildTasks/InvokeBuildInit.ps1 @@ -19,7 +19,7 @@ Write-Verbose " ManifestPath [$ManifestPath]" -Verbose $Script:ModulePath = Join-Path -Path $Destination -ChildPath "$ModuleName.psm1" Write-Verbose " ModulePath [$ModulePath]" -Verbose -$Script:Folders = 'Classes', 'Includes', 'Internal', 'Private', 'Public', 'Resources' +$Script:Folders = 'Includes', 'Internal', 'Private', 'Public', 'Resources' Write-Verbose " Folders [$Folders]" -Verbose $Script:TestFile = "$BuildRoot\Output\TestResults_PS$PSVersion`_$TimeStamp.xml" diff --git a/BuildTasks/Pester.Task.ps1 b/BuildTasks/Pester.Task.ps1 index 4fc8f4b..49c2e89 100644 --- a/BuildTasks/Pester.Task.ps1 +++ b/BuildTasks/Pester.Task.ps1 @@ -1,6 +1,4 @@ task Pester { - $requiredPercent = $Script:CodeCoveragePercent - $config = New-PesterConfiguration $config.Run.Path = 'Tests' $config.Run.PassThru = $true @@ -10,27 +8,9 @@ task Pester { $config.TestResult.OutputFormat = 'NUnitXml' $config.TestResult.OutputPath = $testFile - if ($requiredPercent -gt 0.00) - { - $config.CodeCoverage.Enabled = $true - $config.CodeCoverage.Path = 'Output\*\*.psm1' - $config.CodeCoverage.OutputPath = 'Output\codecoverage.xml' - } - $results = Invoke-Pester -Configuration $config if ($results.FailedCount -gt 0) { Write-Error -Message "Failed [$($results.FailedCount)] Pester tests." } - - if ($results.CodeCoverage.NumberOfCommandsAnalyzed -gt 0) - { - $codeCoverage = $results.CodeCoverage.NumberOfCommandsExecuted / - $results.CodeCoverage.NumberOfCommandsAnalyzed - - if ($codeCoverage -lt $requiredPercent) - { - Write-Error ("Failed Code Coverage [{0:P}] below {1:P}" -f $codeCoverage, $requiredPercent) - } - } } diff --git a/PSGraph/Data/Aliases.json b/PSGraph/Data/Aliases.json deleted file mode 100644 index ef88f23..0000000 --- a/PSGraph/Data/Aliases.json +++ /dev/null @@ -1,6 +0,0 @@ -[ - { - "name": "Graph", - "value": "Get-Graph" - } -] \ No newline at end of file diff --git a/PSGraph/PSGraph.psm1 b/PSGraph/PSGraph.psm1 index 3e23bff..4f63830 100644 --- a/PSGraph/PSGraph.psm1 +++ b/PSGraph/PSGraph.psm1 @@ -4,42 +4,6 @@ $Script:PSModuleRoot = $PSScriptRoot Write-Verbose -Message "This file is replaced in the build output, and is only used for debugging." Write-Verbose -Message $PSScriptRoot -# Class importer -# $root = '.\LDAppSettings\Classes' -$root = Join-Path -Path $PSScriptRoot -ChildPath 'Classes' -Write-Verbose "Load classes from [$root]" -$classFiles = Get-ChildItem -Path $root -Filter '*.ps1' -Recurse | - Where-Object Name -notlike '*.Tests.ps1' - -$classes = @{} - -# $file = $classFiles[3] -foreach($file in $classFiles) -{ - $name = $file.BaseName - $classes[$name] = @{ - Name = $name - Path = $file.FullName - } - $data = Get-Content $file.fullname - # $line = $data[0] - foreach($line in $data) - { - if($line -match "\s+($Name)\s*(:|requires)\s*(?\w*)|\[(?\w+)\]") - { - $classes[$name].Base += @($Matches.baseclass) - } - } -} - -$importOrder = $classes.GetEnumerator() | Resolve-DependencyOrder -Key {$_.Name} -DependsOn {$_.Value.Base} - -foreach( $class in $importOrder ) -{ - Write-Verbose $class.Value.Path - . $class.Value.Path -} - $folders = 'Includes', 'Internal', 'Private', 'Public', 'Resources' foreach ($folder in $folders) { diff --git a/build.ps1 b/build.ps1 index 720ee4e..96df987 100644 --- a/build.ps1 +++ b/build.ps1 @@ -8,8 +8,7 @@ $Script:Modules = @( 'BuildHelpers', 'InvokeBuild', 'platyPS', - 'PSScriptAnalyzer', - 'DependsOn' + 'PSScriptAnalyzer' ) # Pinned explicitly: Pester 4.x and 5.x can be installed side by side, which diff --git a/deploy.PSDeploy.ps1 b/deploy.PSDeploy.ps1 deleted file mode 100644 index a585164..0000000 --- a/deploy.PSDeploy.ps1 +++ /dev/null @@ -1,29 +0,0 @@ -# Generic module deployment. -# This stuff should be moved to psake for a cleaner deployment view - -# ASSUMPTIONS: - -# folder structure of: -# - RepoFolder -# - This PSDeploy file -# - ModuleName -# - ModuleName.psd1 - -# Nuget key in $ENV:NugetApiKey - -# Set-BuildEnvironment from BuildHelpers module has populated ENV:BHProjectName - -# find a folder that has psd1 of same name... - -if ($ENV:BHProjectName -and $ENV:BHProjectName.Count -eq 1) -{ - Deploy Module { - By PSGalleryModule { - FromSource output\$ENV:BHProjectName - To PSGallery - WithOptions @{ - ApiKey = $ENV:NugetApiKey - } - } - } -} diff --git a/module.build.ps1 b/module.build.ps1 index 18dd43d..19cddda 100644 --- a/module.build.ps1 +++ b/module.build.ps1 @@ -1,6 +1,5 @@ $Script:ModuleName = Get-ChildItem -Path (Join-Path $PSScriptRoot '*\*.psm1') | Select-Object -ExpandProperty BaseName -$Script:CodeCoveragePercent = 0.0 # 0 to 1 . $PSScriptRoot\BuildTasks\InvokeBuildInit.ps1 task Default Build, Test, UpdateSource diff --git a/requirements.psd1 b/requirements.psd1 deleted file mode 100644 index af14a4c..0000000 --- a/requirements.psd1 +++ /dev/null @@ -1,20 +0,0 @@ -@{ - CreateFolder = @{ - DependencyType = 'Command' - Source = 'MKDIR C:\ProgramData\PSGraphViz -Force -ea 0' - } - - DownloadFile = @{ - DependencyType = 'FileDownload' - Source = 'http://graphviz.org/pub/graphviz/stable/windows/graphviz-2.38.zip' - Target = 'C:\ProgramData\PSGraphViz\psgraphviz.zip' - DependsOn = 'CreateFolder' - } - - Unzip = @{ - DependencyType = 'Command' - Source = 'Unblock-File -Path "C:\ProgramData\PSGraphViz\psgraphviz.zip"', - 'Expand-Archive -Path "C:\ProgramData\PSGraphViz\psgraphviz.zip" -DestinationPath "C:\ProgramData\PSGraphViz"' - DependsOn = 'DownloadFile' - } -}