diff --git a/.build/tasks/Create-CompositeResource.build.ps1 b/.build/tasks/Create-CompositeResource.build.ps1 new file mode 100644 index 0000000..f6384b9 --- /dev/null +++ b/.build/tasks/Create-CompositeResource.build.ps1 @@ -0,0 +1,179 @@ +param +( + # Project path + [Parameter()] + [System.String] + $ProjectPath = (property ProjectPath $BuildRoot), + + [Parameter()] + # Base directory of all output (default to 'output') + [System.String] + $OutputDirectory = (property OutputDirectory (Join-Path $BuildRoot 'output')), + + [Parameter()] + [System.String] + $BuiltModuleSubdirectory = (property BuiltModuleSubdirectory ''), + + [Parameter()] + [System.Management.Automation.SwitchParameter] + $VersionedOutputDirectory = (property VersionedOutputDirectory $true), + + [Parameter()] + [System.String] + $ProjectName = (property ProjectName ''), + + [Parameter()] + [System.String] + $PesterOutputFolder = (property PesterOutputFolder 'testResults'), + + [Parameter()] + [System.String] + $PesterOutputFormat = (property PesterOutputFormat ''), + + [Parameter()] + [System.Object[]] + $PesterScript = (property PesterScript ''), + + [Parameter()] + [System.String[]] + $PesterTag = (property PesterTag @()), + + [Parameter()] + [System.String[]] + $PesterExcludeTag = (property PesterExcludeTag @()), + + [Parameter()] + [System.String] + $CodeCoverageThreshold = (property CodeCoverageThreshold ''), + + # Build Configuration object + [Parameter()] + [System.Collections.Hashtable] + $BuildInfo = (property BuildInfo @{ }) +) + + +# Synopsis: Merging several code coverage files together. +task Generate_Composite_Resource_Module { + # Get the vales for task variables, see https://github.com/gaelcolas/Sampler#task-variables. + . Set-SamplerTaskVariable + + "`tOutput Path = '$OutputDirectory'" + + Write-Build White 'Generating Composite Resource Module' + + $result = New-CompositeResourceModule -OutputPath $OutputDirectory + + if ($result) + { + Write-Build Green "Module generation completed." + } + else + { + throw "Error occurred during module generation! Please check the log output." + } + + # $osShortName = Get-OperatingSystemShortName + + # $powerShellVersion = 'PSv.{0}' -f $PSVersionTable.PSVersion + + # $moduleFileName = '{0}.psm1' -f $ProjectName + + # $PesterOutputFolder = Get-SamplerAbsolutePath -Path $PesterOutputFolder -RelativeTo $OutputDirectory + + # "`tPester Output Folder = '$PesterOutputFolder'" + + # $GetCodeCoverageThresholdParameters = @{ + # RuntimeCodeCoverageThreshold = $CodeCoverageThreshold + # BuildInfo = $BuildInfo + # } + + # $CodeCoverageThreshold = Get-CodeCoverageThreshold @GetCodeCoverageThresholdParameters + + # if (-not $CodeCoverageThreshold) + # { + # $CodeCoverageThreshold = 0 + # } + + # "`tCode Coverage Threshold = '$CodeCoverageThreshold'" + + # if ($CodeCoverageThreshold -gt 0) + # { + # $getPesterOutputFileFileNameParameters = @{ + # ProjectName = $ProjectName + # ModuleVersion = $ModuleVersion + # OsShortName = $osShortName + # PowerShellVersion = $powerShellVersion + # } + + # $pesterOutputFileFileName = Get-PesterOutputFileFileName @getPesterOutputFileFileNameParameters + + # $getCodeCoverageOutputFile = @{ + # BuildInfo = $BuildInfo + # PesterOutputFolder = $PesterOutputFolder + # } + + # $CodeCoverageOutputFile = Get-SamplerCodeCoverageOutputFile @getCodeCoverageOutputFile + + # if (-not $CodeCoverageOutputFile) + # { + # $CodeCoverageOutputFile = (Join-Path -Path $PesterOutputFolder -ChildPath "CodeCov_$pesterOutputFileFileName") + # } + + # "`tCode Coverage Output File = $CodeCoverageOutputFile" + + # $CodeCoverageMergedOutputFile = 'CodeCov_Merged.xml' + + # if ($BuildInfo.CodeCoverage.CodeCoverageMergedOutputFile) + # { + # $CodeCoverageMergedOutputFile = $BuildInfo.CodeCoverage.CodeCoverageMergedOutputFile + # } + + # $CodeCoverageMergedOutputFile = Get-SamplerAbsolutePath -Path $CodeCoverageMergedOutputFile -RelativeTo $PesterOutputFolder + + # "`tCode Coverage Merge Output File = $CodeCoverageMergedOutputFile" + + # $CodeCoverageFilePattern = 'Codecov*.xml' + + # if ($BuildInfo.ContainsKey('CodeCoverage') -and $BuildInfo.CodeCoverage.ContainsKey('CodeCoverageFilePattern')) + # { + # $CodeCoverageFilePattern = $BuildInfo.CodeCoverage.CodeCoverageFilePattern + # } + + # "`tCode Coverage File Pattern = $CodeCoverageFilePattern" + + # if (-not [System.String]::IsNullOrEmpty($CodeCoverageFilePattern)) + # { + # $codecovFiles = Get-ChildItem -Path $PesterOutputFolder -Include $CodeCoverageFilePattern -Recurse + # } + + # "`tMerging Code Coverage Files = '{0}'" -f ($codecovFiles.FullName -join ', ') + # "" + + # if (Test-Path -Path $CodeCoverageMergedOutputFile) + # { + # Write-Build Yellow "File $CodeCoverageMergedOutputFile found, deleting file." + + # Remove-Item -Path $CodeCoverageMergedOutputFile -Force + # } + + # Write-Build White "Processing folder: $OutputDirectory" + + # if ($codecovFiles.Count -gt 1) + # { + # Write-Build DarkGray "Started merging $($codecovFiles.Count) code coverage files!" + + # Start-CodeCoverageMerge -Files $codecovFiles -TargetFile $CodeCoverageMergedOutputFile + + # Write-Build Green "Merge completed. Saved merge result to: $CodeCoverageMergedOutputFile" + # } + # else + # { + # throw "Found $($codecovFiles.Count) code coverage file. Need at least two files to merge." + # } + # } + # else + # { + # Write-Build White 'Code coverage is not enabled, skipping.' + # } +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 80194cc..2df2b9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,4 +7,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Added first version +- Added Composite Resource generator code +- Added Sampler task, to use the CRG in a pipeline diff --git a/build.yaml b/build.yaml index 54cfb4e..debae7e 100644 --- a/build.yaml +++ b/build.yaml @@ -6,10 +6,12 @@ # SourcePath: ./Sampler/Sampler.psd1 # Output Directory where ModuleBuilder will build the Module, relative to module manifest # OutputDirectory: ../output/Sampler -BuiltModuleSubdirectory: module +#BuiltModuleSubdirectory: module CopyPaths: - en-US - Dependencies.psd1 + - ../.build/tasks +suffix: suffix.ps1 Encoding: UTF8 # Can be used to manually specify module's semantic version if the preferred method of # using GitVersion is not available, and it is not possible to set the session environment @@ -74,6 +76,7 @@ BuildWorkflow: publish: - publish_module_to_gallery - Publish_Release_To_GitHub + - Create_ChangeLog_GitHub_PR #################################################### # PESTER Configuration # @@ -83,6 +86,7 @@ Pester: OutputFormat: NUnitXML # Excludes one or more paths from being used to calculate code coverage. ExcludeFromCodeCoverage: + - tasks # If no scripts are defined the default is to use all the tests under the project's # tests folder or source folder (if present). Test script paths can be defined to @@ -115,14 +119,6 @@ Pester: #CodeCoverageFilePattern: JaCoCo_Merge.xml # the pattern used to search all pipeline test job artifacts #CodeCoverageMergedOutputFile: JaCoCo_coverage.xml # the file that is created for the merged code coverage -DscTest: - ExcludeTag: - - "Common Tests - New Error-Level Script Analyzer Rules" - Tag: - ExcludeSourceFile: - - output - # - Templates - # Import ModuleBuilder tasks from a specific PowerShell module using the build # task's alias. Wildcard * can be used to specify all tasks that has a similar # prefix and or suffix. The module contain the task must be added as a required @@ -133,7 +129,6 @@ ModuleBuildTasks: Sampler.GitHubTasks: - '*.ib.tasks' - # Invoke-Build Header to be used to 'decorate' the terminal output of the tasks. TaskHeader: | param($Path) @@ -145,3 +140,12 @@ TaskHeader: | Write-Build DarkGray " $Path" Write-Build DarkGray " $($Task.InvocationInfo.ScriptName):$($Task.InvocationInfo.ScriptLineNumber)" "" + +GitHubConfig: + ReleaseAssets: + - 'output/CHANGELOG.md' + GitHubFilesToAdd: + - 'CHANGELOG.md' + GitHubConfigUserName: ykuijs + GitHubConfigUserEmail: ykuijs@hotmail.com + UpdateChangelogOnPrerelease: false diff --git a/source/M365DSC.CRG.psd1 b/source/M365DSC.CRG.psd1 index af83163..4260438 100644 --- a/source/M365DSC.CRG.psd1 +++ b/source/M365DSC.CRG.psd1 @@ -78,7 +78,7 @@ CmdletsToExport = @('New-CompositeResourceModule') VariablesToExport = @() # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. -AliasesToExport = @() +AliasesToExport = '*' # DSC resources to export from this module DscResourcesToExport = @() diff --git a/source/Private/Initialize-Module.ps1 b/source/Private/Initialize-Module.ps1 index 25e58d0..9080b02 100644 --- a/source/Private/Initialize-Module.ps1 +++ b/source/Private/Initialize-Module.ps1 @@ -5,7 +5,7 @@ function Initialize-Module Initializes the module by creating all required files and folders .Description - This function initializes the M365Config module by creating the + This function initializes the M365DSC.CompositeResources module by creating the required folder structure and the module manifest file. .Parameter Version @@ -33,7 +33,7 @@ function Initialize-Module process { # Create the folder structure - $modulePath = Join-Path -Path $OutputPath -ChildPath "M365Config\$Version" + $modulePath = Join-Path -Path $OutputPath -ChildPath "M365DSC.CompositeResources\$Version" if ((Test-Path -Path $modulePath) -eq $false) { $null = New-Item -Path $modulePath -ItemType Directory @@ -74,7 +74,7 @@ function Initialize-Module [void]$moduleManifestString.AppendLine(' }') [void]$moduleManifestString.AppendLine('}') - $moduleManifestFileName = 'M365Config.psd1' + $moduleManifestFileName = 'M365DSC.CompositeResources.psd1' $moduleManifestFilePath = Join-Path -Path $modulePath -ChildPath $moduleManifestFileName # Save the module manifest content to file diff --git a/source/Private/Save-Resource.ps1 b/source/Private/Save-Resource.ps1 index bd6a70d..da19074 100644 --- a/source/Private/Save-Resource.ps1 +++ b/source/Private/Save-Resource.ps1 @@ -46,7 +46,7 @@ function Save-Resource process { - $modulePath = Join-Path -Path $OutputPath -ChildPath "M365Config\$Version" + $modulePath = Join-Path -Path $OutputPath -ChildPath "M365DSC.CompositeResources\$Version" $dscResourcesPath = Join-Path -Path $modulePath -ChildPath 'DscResources' # Save the schema file of the composite resource diff --git a/source/suffix.ps1 b/source/suffix.ps1 new file mode 100644 index 0000000..e5d51fc --- /dev/null +++ b/source/suffix.ps1 @@ -0,0 +1,9 @@ +# Inspired from https://github.com/nightroman/Invoke-Build/blob/64f3434e1daa806814852049771f4b7d3ec4d3a3/Tasks/Import/README.md#example-2-import-from-a-module-with-tasks +Get-ChildItem -Path (Join-Path -Path $PSScriptRoot -ChildPath 'tasks\*') -Include '*.build.*' | + ForEach-Object -Process { + $ModuleName = ([System.IO.FileInfo] $MyInvocation.MyCommand.Name).BaseName + $taskFileAliasName = "$($_.BaseName).$ModuleName.ib.tasks" + Set-Alias -Name $taskFileAliasName -Value $_.FullName + + Export-ModuleMember -Alias $taskFileAliasName + }