From 2d3c78426cb3ac04348ffc6a860fa2c740c67078 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sun, 29 Jan 2023 00:58:50 -0800 Subject: [PATCH 01/92] Fix failing GitHub Actions CI --- .github/workflows/github.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 43bb7df4..8f549147 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -235,7 +235,7 @@ jobs: publish: needs: test - if: ${{ success() && startsWith( 'refs/tags/', env.GITHUB_REF ) }} + if: ${{ success() && startsWith( 'refs/tags/', github.ref ) }} runs-on: ubuntu-latest @@ -261,8 +261,8 @@ jobs: - name: Set Release Tag Name shell: pwsh run: | - $tagName = ("${{ env.GITHUB_REF }}" -replace '^refs/tags/').Trim() - "TagName=$tagname" | Add-Content -Path '${{ env.GITHUB_ENV }}' + $tagName = ("${{ github.ref }}" -replace '^refs/tags/').Trim() + "TagName=$tagname" | Add-Content -Path '${{ github.env }}' - name: Download Artifacts uses: actions/download-artifact@v2.0.9 From 78811673eee1b6bf9f6012c475179b8a1b5c23f1 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sun, 5 Feb 2023 23:07:18 -0800 Subject: [PATCH 02/92] Remove dependency on pester info file --- .github/workflows/github.yml | 101 +++++++++++------------------------ 1 file changed, 31 insertions(+), 70 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 8f549147..497f098f 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -36,14 +36,14 @@ jobs: FilePath: '$GITHUB_WORKSPACE/Changelog.md' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Generate Changelog shell: pwsh run: ./Build/New-Changelog.ps1 -Path "${{ env.FilePath }}" -ApiKey "${{ secrets.GITHUB_TOKEN }}" - name: Upload Changelog - uses: actions/upload-artifact@v2.2.3 + uses: actions/upload-artifact@v3 with: name: Changelog.md path: $FilePath @@ -51,6 +51,8 @@ jobs: build: name: 'Build Module' runs-on: ubuntu-latest + outputs: + pester_min_version: ${{ steps.pestermin.outputs.pester_min_version }} env: FileSystemDeploymentPath: '$GITHUB_WORKSPACE/Deploy/FileSystem' @@ -59,36 +61,21 @@ jobs: NupkgPath: '' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - name: Install Dependencies + - name: Get Pester min version + id: pestermin shell: pwsh run: | - $Params = @{ - Scope = 'CurrentUser' - Force = $true - } - - Write-Host "Installing Modules" - $Params.Name = @( 'PSDeploy', 'BuildHelpers', 'PlatyPS' ) - $Params | Out-String | Write-Host - Install-Module @Params - - $Params.Name = 'Pester' - $Params.SkipPublisherCheck = $true - $Params.MinimumVersion = $Params.MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version - $Params | Out-String | Write-Host - Install-Module @Params - - $Params.MinimumVersion | Set-Content -Path "${{ env.PesterInfoFilePath }}" - - $Params.Remove('SkipPublisherCheck') - $Params.Remove('MinimumVersion') - - $Params.Name = 'EZOut' - $Params.AllowClobber = $true - $Params | Out-String | Write-Host - Install-Module @Params + $MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version + Write-Output "pester_min_version=$MinimumVersion" >> $GITHUB_OUTPUT + Write-Host "Minimum Pester Version: $MinimumVersion" + + - name: Install and cache PowerShell modules + uses: potatoqualitee/psmodulecache@v5.2 + with: + modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ steps.vars.outputs.pester_min_version }}, EZOut + shell: pwsh - name: Setup Environment shell: pwsh @@ -99,17 +86,11 @@ jobs: run: ./Build/Build-Module.ps1 - name: Upload Module Artifact - uses: actions/upload-artifact@v2.2.3 + uses: actions/upload-artifact@v3 with: name: $ModuleArtifactName path: $BuiltModulePath - - name: Upload Pester Version Artifact - uses: actions/upload-artifact@v2.2.3 - with: - name: $PesterInfoFileName - path: $PesterInfoFilePath - - name: Generate Nupkg shell: pwsh run: | @@ -117,7 +98,7 @@ jobs: ./Deploy/Publish.ps1 -Key 'filesystem' -Path '${{ env.FileSystemDeploymentPath }}' -OutputDirectory '${{ env.FileSystemDeploymentPath }}' - name: Upload Nupkg Artifact - uses: actions/upload-artifact@v2.2.3 + uses: actions/upload-artifact@v3 with: name: $NupkgArtifactName path: $NupkgPath @@ -144,34 +125,20 @@ jobs: ModuleFolders: '' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - name: Install Dependencies + - name: Get Pester min version shell: pwsh run: | - $Params = @{ - Scope = 'CurrentUser' - Force = $true - } - - Write-Host "Installing Modules" - $Params.Name = @( 'PSDeploy', 'BuildHelpers', 'PlatyPS' ) - $Params | Out-String | Write-Host - Install-Module @Params - - $Params.Name = 'Pester' - $Params.SkipPublisherCheck = $true - $Params.MinimumVersion = $Params.MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version - $Params | Out-String | Write-Host - Install-Module @Params - - $Params.Remove('SkipPublisherCheck') - $Params.Remove('MinimumVersion') - - $Params.Name = 'EZOut' - $Params.AllowClobber = $true - $Params | Out-String | Write-Host - Install-Module @Params + $MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version + Write-Output "pester_min_version=$MinimumVersion" >> $GITHUB_OUTPUT + Write-Host "Minimum Pester Version: $MinimumVersion" + + - name: Install and cache PowerShell modules + uses: potatoqualitee/psmodulecache@v5.2 + with: + modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ steps.vars.outputs.pester_min_version }}, EZOut + shell: pwsh - name: Setup Environment shell: pwsh @@ -187,18 +154,12 @@ jobs: name: $NupkgArtifactName path: $PackageDownloadPath - - name: Download Pester Version Information - uses: actions/download-artifact@v2.0.9 - with: - name: $PesterInfoFileName - path: $PesterInfoFilePath - - name: Install Module from Nupkg shell: pwsh run: | $pesterParams = @{ Name = 'Pester' - MinimumVersion = Get-Content -Path "${{ env.PesterInfoFilePath }}" + MinimumVersion = Get-Content -Path "${{ needs.build.outputs.pester_min_version }}" ProviderName = 'NuGet' Path = '${{ env.PackageDownloadPath }}' Force = $true @@ -246,7 +207,7 @@ jobs: TagName: '' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Download Module Artifact uses: actions/download-artifact@v2.0.9 From 066dd193ab3cc997472dfde7538214ad09b46d3e Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sun, 5 Feb 2023 23:09:30 -0800 Subject: [PATCH 03/92] Correct referenced step id --- .github/workflows/github.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 497f098f..7b703ef6 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -74,7 +74,7 @@ jobs: - name: Install and cache PowerShell modules uses: potatoqualitee/psmodulecache@v5.2 with: - modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ steps.vars.outputs.pester_min_version }}, EZOut + modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, "Pester:${{ steps.pestermin.outputs.pester_min_version }}"", EZOut shell: pwsh - name: Setup Environment @@ -128,6 +128,7 @@ jobs: - uses: actions/checkout@v3 - name: Get Pester min version + id: pestermin shell: pwsh run: | $MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version @@ -137,7 +138,7 @@ jobs: - name: Install and cache PowerShell modules uses: potatoqualitee/psmodulecache@v5.2 with: - modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ steps.vars.outputs.pester_min_version }}, EZOut + modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ steps.pestermin.outputs.pester_min_version }}, EZOut shell: pwsh - name: Setup Environment From ef879110d62fa647bf196356b1cf69ed32cb46cc Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 00:31:10 -0800 Subject: [PATCH 04/92] Add format.ps1xml file back to complete manifest Remove more unnecessary references to pesterinfo file Remove unused dependencies file Adjust version of Pester in readme --- .github/workflows/github.yml | 9 +- .gitignore | 1 - PSKoans/Dependencies.psd1 | 3 - PSKoans/PSKoans.format.ps1xml | 1510 +++++++++++++++++++++++++++++++++ README.md | 2 +- 5 files changed, 1515 insertions(+), 10 deletions(-) delete mode 100644 PSKoans/Dependencies.psd1 create mode 100644 PSKoans/PSKoans.format.ps1xml diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 7b703ef6..bb619474 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -20,8 +20,6 @@ on: env: NupkgArtifactName: 'PSKoans.nupkg' ModuleArtifactName: 'PSKoans' - PesterInfoFileName: 'PesterVersion.txt' - PesterInfoFilePath: '$GITHUB_WORKSPACE/PesterVersion.txt' jobs: @@ -51,6 +49,7 @@ jobs: build: name: 'Build Module' runs-on: ubuntu-latest + outputs: pester_min_version: ${{ steps.pestermin.outputs.pester_min_version }} @@ -67,14 +66,14 @@ jobs: id: pestermin shell: pwsh run: | - $MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version + $MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version.ToString() Write-Output "pester_min_version=$MinimumVersion" >> $GITHUB_OUTPUT Write-Host "Minimum Pester Version: $MinimumVersion" - name: Install and cache PowerShell modules uses: potatoqualitee/psmodulecache@v5.2 with: - modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, "Pester:${{ steps.pestermin.outputs.pester_min_version }}"", EZOut + modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ steps.pestermin.outputs.pester_min_version }}, EZOut shell: pwsh - name: Setup Environment @@ -131,7 +130,7 @@ jobs: id: pestermin shell: pwsh run: | - $MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version + $MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version.ToString() Write-Output "pester_min_version=$MinimumVersion" >> $GITHUB_OUTPUT Write-Host "Minimum Pester Version: $MinimumVersion" diff --git a/.gitignore b/.gitignore index 8fd24e87..d69e534e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ .vs/ .DS_Store/ *.temppoint.* -*.format.ps1xml PSKoans.psproj PSKoans/*/PSKoans-help.xml diff --git a/PSKoans/Dependencies.psd1 b/PSKoans/Dependencies.psd1 deleted file mode 100644 index 4dd191c4..00000000 --- a/PSKoans/Dependencies.psd1 +++ /dev/null @@ -1,3 +0,0 @@ -@{ - Pester = '4.3.1' -} diff --git a/PSKoans/PSKoans.format.ps1xml b/PSKoans/PSKoans.format.ps1xml new file mode 100644 index 00000000..cb351ae7 --- /dev/null +++ b/PSKoans/PSKoans.format.ps1xml @@ -0,0 +1,1510 @@ + + + + + + Prompt.Preface + + + + + + $moduleName = 'PSKoans' + + do { + $lm = Get-Module -Name $moduleName -ErrorAction Ignore + if (-not $lm) { continue } + if ($lm.FormatPartsLoaded) { break } + $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { + foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { + $ParentNode = $partNodeName.Node.ParentNode + "$($ParentNode.Name)={ + $($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" + } + }) -join [Environment]::NewLine + New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | + Import-Module -Global + $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") + + if (-not $lm.OnRemove) { + $lm.OnRemove = $onRemove + } else { + $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) + } + $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force + + } while ($false) + + +@(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' -NoClear) -join '' + + Welcome, seeker of enlightenment. + Let us observe your karma... + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' ) -join '' + + + + + + + + + + Prompt.Describe + + + + + + $moduleName = 'PSKoans' + + do { + $lm = Get-Module -Name $moduleName -ErrorAction Ignore + if (-not $lm) { continue } + if ($lm.FormatPartsLoaded) { break } + $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { + foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { + $ParentNode = $partNodeName.Node.ParentNode + "$($ParentNode.Name)={ + $($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" + } + }) -join [Environment]::NewLine + New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | + Import-Module -Global + $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") + + if (-not $lm.OnRemove) { + $lm.OnRemove = $onRemove + } else { + $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) + } + $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force + + } while ($false) + + +@(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Error' -NoClear) -join '' + + + + 'Describing "{0}" has damaged your karma.' -f $_ + + + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Error' ) -join '' + + + + + + + + + + Prompt.Expectation + + + + + + $moduleName = 'PSKoans' + + do { + $lm = Get-Module -Name $moduleName -ErrorAction Ignore + if (-not $lm) { continue } + if ($lm.FormatPartsLoaded) { break } + $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { + foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { + $ParentNode = $partNodeName.Node.ParentNode + "$($ParentNode.Name)={ + $($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" + } + }) -join [Environment]::NewLine + New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | + Import-Module -Global + $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") + + if (-not $lm.OnRemove) { + $lm.OnRemove = $onRemove + } else { + $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) + } + $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force + + } while ($false) + + +@(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' -NoClear) -join '' + + You have not yet reached enlightenment. + + The answers you seek... + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' ) -join '' + + + + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Error' -NoClear) -join '' + + + Expectation + + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Error' ) -join '' + + + + + + + + + + Prompt.Meditation + + + + + + $moduleName = 'PSKoans' + + do { + $lm = Get-Module -Name $moduleName -ErrorAction Ignore + if (-not $lm) { continue } + if ($lm.FormatPartsLoaded) { break } + $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { + foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { + $ParentNode = $partNodeName.Node.ParentNode + "$($ParentNode.Name)={ + $($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" + } + }) -join [Environment]::NewLine + New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | + Import-Module -Global + $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") + + if (-not $lm.OnRemove) { + $lm.OnRemove = $onRemove + } else { + $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) + } + $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force + + } while ($false) + + +@(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' -NoClear) -join '' + + Please meditate on the following code: + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' ) -join '' + + + + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Error' -NoClear) -join '' + + + + @" +{0} It "{1}" +{2} +"@ -f [char]0xd7, $_.It, $_.Meditation + + + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Error' ) -join '' + + + + + + + + + + Prompt.Koan + + + + + + $moduleName = 'PSKoans' + + do { + $lm = Get-Module -Name $moduleName -ErrorAction Ignore + if (-not $lm) { continue } + if ($lm.FormatPartsLoaded) { break } + $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { + foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { + $ParentNode = $partNodeName.Node.ParentNode + "$($ParentNode.Name)={ + $($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" + } + }) -join [Environment]::NewLine + New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | + Import-Module -Global + $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") + + if (-not $lm.OnRemove) { + $lm.OnRemove = $onRemove + } else { + $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) + } + $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force + + } while ($false) + + +@(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Emphasis' -NoClear) -join '' + + + + & (Get-Module -Name PSKoans) { + $ReplacementPattern = '$1 {0} ' -f [char]0x258c + ($script:MeditationStrings | Get-Random) -replace '^|(\r?\n)', $ReplacementPattern + } + + + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Emphasis' ) -join '' + + + + + + + + + + Prompt.TopicList + + + + + + $moduleName = 'PSKoans' + + do { + $lm = Get-Module -Name $moduleName -ErrorAction Ignore + if (-not $lm) { continue } + if ($lm.FormatPartsLoaded) { break } + $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { + foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { + $ParentNode = $partNodeName.Node.ParentNode + "$($ParentNode.Name)={ + $($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" + } + }) -join [Environment]::NewLine + New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | + Import-Module -Global + $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") + + if (-not $lm.OnRemove) { + $lm.OnRemove = $onRemove + } else { + $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) + } + $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force + + } while ($false) + + +@(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' -NoClear) -join '' + + + + $TopicList = $_.Topics -replace '^', ' - ' -join [Environment]::NewLine + $TopicOrTopics = if ($_.Count -gt 1) { 'topics' } else { 'topic' } + $_.FormatString -f $TopicOrTopics, $TopicList + + + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' ) -join '' + + + + + + + + + + Prompt.ProgressPreamble + + + + + + $moduleName = 'PSKoans' + + do { + $lm = Get-Module -Name $moduleName -ErrorAction Ignore + if (-not $lm) { continue } + if ($lm.FormatPartsLoaded) { break } + $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { + foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { + $ParentNode = $partNodeName.Node.ParentNode + "$($ParentNode.Name)={ + $($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" + } + }) -join [Environment]::NewLine + New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | + Import-Module -Global + $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") + + if (-not $lm.OnRemove) { + $lm.OnRemove = $onRemove + } else { + $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) + } + $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force + + } while ($false) + + +@(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' -NoClear) -join '' + + + + -not $_.Complete + + + @" + You examine the path beneath your feet... +"@ + + + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' ) -join '' + + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' -NoClear) -join '' + + + + $_.Complete + + + @" + You cast your gaze back upon the path that you have walked... +"@ + + + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' ) -join '' + + + + + + + + Prompt.ProgressBar + + + + + + + + $moduleName = 'PSKoans' + + do { + $lm = Get-Module -Name $moduleName -ErrorAction Ignore + if (-not $lm) { continue } + if ($lm.FormatPartsLoaded) { break } + $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { + foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { + $ParentNode = $partNodeName.Node.ParentNode + "$($ParentNode.Name)={ + $($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" + } + }) -join [Environment]::NewLine + New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | + Import-Module -Global + $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") + + if (-not $lm.OnRemove) { + $lm.OnRemove = $onRemove + } else { + $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) + } + $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force + + } while ($false) + + +@(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Progress' -NoClear) -join '' + + + + $ConsoleWidth = ($host.UI.RawUI.WindowSize.Width, $host.UI.RawUI.BufferSize.Width, 80).Where{ $_ -ge 30 }[0] + $TopicProgressAmount = "{0}/{1}" -f $_.Completed, $_.Total + $ProgressWidth = $ConsoleWidth * $_.Width - ($_.Name.Length + $TopicProgressAmount.Length + 7) + + [int] $PortionDone = ($_.Completed / $_.Total) * $ProgressWidth + + " [{3}]: [{0}{1}] {2}" -f @( + "$([char]0x25a0)" * $PortionDone + "$([char]0x2015)" * ($ProgressWidth - $PortionDone) + $TopicProgressAmount + $_.Name + ) + + + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Progress' ) -join '' + + + + + + + + Prompt.End + + + + + + + + $moduleName = 'PSKoans' + + do { + $lm = Get-Module -Name $moduleName -ErrorAction Ignore + if (-not $lm) { continue } + if ($lm.FormatPartsLoaded) { break } + $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { + foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { + $ParentNode = $partNodeName.Node.ParentNode + "$($ParentNode.Name)={ + $($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" + } + }) -join [Environment]::NewLine + New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | + Import-Module -Global + $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") + + if (-not $lm.OnRemove) { + $lm.OnRemove = $onRemove + } else { + $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) + } + $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force + + } while ($false) + + +@(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' -NoClear) -join '' + + Run 'Show-Karma -Contemplate' to begin your meditations. + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' ) -join '' + + + + + + + + Prompt.Details + + + + + + + $moduleName = 'PSKoans' + + do { + $lm = Get-Module -Name $moduleName -ErrorAction Ignore + if (-not $lm) { continue } + if ($lm.FormatPartsLoaded) { break } + $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { + foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { + $ParentNode = $partNodeName.Node.ParentNode + "$($ParentNode.Name)={ + $($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" + } + }) -join [Environment]::NewLine + New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | + Import-Module -Global + $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") + + if (-not $lm.OnRemove) { + $lm.OnRemove = $onRemove + } else { + $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) + } + $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force + + } while ($false) + + +@(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' -NoClear) -join '' + + + + + $_.Block.Name -and + $_.Block.Name -ne $global:_Koan_Block_Name + + + + function Get-Depth { + param($Block) + + if (-not $Block) { + 0 + return + } + + if (-not $Block.Parent) { + 1 + } + else { + 1 + (Get-Depth -Block $Block.Parent) + } + } + + $global:_Koan_Block_Name = $_.Block.Name + $Depth = Get-Depth $_.Block + $Indent = " " * (4 * $Depth) + + '{0}|{1}| {2}{3}' -f $Indent, [char]0x39e, $_.Block.Name, [Environment]::NewLine + + + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' ) -join '' + + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Passed' -NoClear) -join '' + + + + $_.Passed + + + function Get-Depth { + param($Block) + + if (-not $Block) { + 0 + return + } + + if (-not $Block.Parent) { + 1 + } + else { + 1 + (Get-Depth -Block $Block.Parent) + } + } + + $IndentSpaces = 2 + 4 * (Get-Depth $_.Block) + $Indent = " " * $IndentSpaces + + '{0}[{1}] It {2}' -f $Indent, [char]0x25b8, $_.Name + + + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Passed' ) -join '' + + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Error' -NoClear) -join '' + + + + -not $_.Passed + + + function Get-Depth { + param($Block) + + if (-not $Block) { + 0 + return + } + + if (-not $Block.Parent) { + 1 + } + else { + 1 + (Get-Depth -Block $Block.Parent) + } + } + + $Depth = Get-Depth $_.Block + $IndentSpaces = 2 + 4 * $Depth + $Indent = " " * $IndentSpaces + + '{0}[{1}] It {2}' -f $Indent, [char]0xd7, $_.Name + + + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Error' ) -join '' + + + + + + + + ${PSKoans_Format-RichText} + + + + + + + <# + .Synopsis + Formats the text color of output + .Description + Formats the text color of output + + * ForegroundColor + * BackgroundColor + * Bold + * Underline + .Notes + Stylized Output works in two contexts at present: + * Rich consoles (Windows Terminal, PowerShell.exe, Pwsh.exe) (when $host.UI.SupportsVirtualTerminal) + * Web pages (Based off the presence of a $Request variable, or when $host.UI.SupportsHTML (you must add this property to $host.UI)) + #> + [Management.Automation.Cmdlet("Format","Object")] + [ValidateScript({ + $canUseANSI = $host.UI.SupportsVirtualTerminal + $canUseHTML = $Request -or $host.UI.SupportsHTML -or $OutputMode -eq 'HTML' + if (-not ($canUseANSI -or $canUseHTML)) { return $false} + return $true + })] + [OutputType([string])] + param( + # The input object + [Parameter(ValueFromPipeline)] + [PSObject] + $InputObject, + + # The foreground color + [string]$ForegroundColor, + + # The background color + [string]$BackgroundColor, + + # If set, will render as bold + [switch]$Bold, + + # If set, will render as italic. + [Alias('Italics')] + [switch]$Italic, + + # If set, will render as faint + [switch]$Faint, + + # If set, will render as hidden text. + [switch]$Hide, + + # If set, will render as blinking (not supported in all terminals or HTML) + [switch]$Blink, + + # If set, will render as strikethru + [Alias('Strikethrough', 'Crossout')] + [switch]$Strikethru, + + # If set, will underline text + [switch]$Underline, + + # If set, will double underline text. + [switch]$DoubleUnderline, + + # If set, will invert text + [switch]$Invert, + + # If provided, will create a hyperlink to a given uri + [Alias('Hyperlink', 'Href')] + [uri] + $Link, + + # If set, will not clear formatting + [switch]$NoClear, + + # The alignment. Defaulting to Left. + # Setting an alignment will pad the remaining space on each line. + [ValidateSet('Left','Right','Center')] + [string] + $Alignment, + + # The length of a line. By default, the buffer width + [int]$LineLength = $($host.UI.RawUI.BufferSize.Width) + ) + + begin { + $canUseANSI = $host.UI.SupportsVirtualTerminal + $canUseHTML = $Request -or $host.UI.SupportsHTML -or $OutputMode -eq 'HTML' + $knownStreams = @{ + Output='';Error='BrightRed';Warning='BrightYellow'; + Verbose='BrightCyan';Debug='Yellow';Progress='Cyan'; + Success='BrightGreen';Failure='Red';Default=''} + + $ansiCode = [Regex]::new(@' + (?<ANSI_Code> + (?-i)\e # An Escape + \[ # Followed by a bracket + (?<ParameterBytes>[\d\:\;\<\=\>\?]{0,}) # Followed by zero or more parameter + bytes + (?<IntermediateBytes>[\s\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/]{0,}) # Followed by zero or more + intermediate bytes + (?<FinalByte>[\@ABCDEFGHIJKLMNOPQRSTUVWXYZ\[\\\]\^_\`abcdefghijklmnopqrstuvwxyz\{\|\}\~]) # Followed by a final byte + + ) +'@) + $esc = [char]0x1b + $standardColors = 'Black', 'Red', 'Green', 'Yellow', 'Blue','Magenta', 'Cyan', 'White' + $brightColors = 'BrightBlack', 'BrightRed', 'BrightGreen', 'BrightYellow', 'BrightBlue','BrightMagenta', 'BrightCyan', 'BrightWhite' + + $allOutput = @() + + $n =0 + $cssClasses = @() + $colorAttributes = + @(:nextColor foreach ($hc in $ForegroundColor,$BackgroundColor) { + $n++ + if (-not $hc) { continue } + if ($hc[0] -eq $esc) { + if ($canUseANSI) { + $hc; continue + } + } + + $ansiStartPoint = if ($n -eq 1) { 30 } else { 40 } + if ($knownStreams.ContainsKey($hc)) { + $i = $brightColors.IndexOf($knownStreams[$hc]) + if ($canUseHTML) { + $cssClasses += $hc + } else { + if ($i -ge 0 -and $canUseANSI) { + '' + $esc + "[1;$($ansiStartPoint + $i)m" + } else { + $i = $standardColors.IndexOf($knownStreams[$hc]) + if ($i -ge 0 -and $canUseANSI) { + '' + $esc + "[1;$($ansiStartPoint + $i)m" + } elseif ($i -le 0 -and $canUseANSI) { + '' + $esc + "[$($ansistartpoint + 8):5m" + } + } + } + continue nextColor + } + elseif ($standardColors -contains $hc) { + for ($i = 0; $i -lt $standardColors.Count;$i++) { + if ($standardColors[$i] -eq $hc) { + if ($canUseANSI -and -not $canUseHTML) { + '' + $esc + "[$($ansiStartPoint + $i)m" + } else { + $cssClasses += $standardColors[$i] + } + continue nextColor + } + } + } elseif ($brightColors -contains $hc) { + for ($i = 0; $i -lt $brightColors.Count;$i++) { + if ($brightColors[$i] -eq $hc) { + if ($canUseANSI -and -not $canUseHTML) { + '' + $esc + "[1;$($ansiStartPoint + $i)m" + } else { + $cssClasses += $standardColors[$i] + } + continue nextColor + } + } + } + elseif ($psStyle -and $psStyle.Formatting.$hc -and + $psStyle.Formatting.$hc -match '^\e') { + if ($canUseANSI -and -not $canUseHTML) { + $psStyle.Formatting.$hc + } else { + $cssClasses += "formatting-$hc" + } + } + elseif (-not $n -and $psStyle -and $psStyle.Foreground.$hc -and + $psStyle.Foreground.$hc -match '^\e' ) { + if ($canUseANSI -and -not $canUseHTML) { + $psStyle.Foreground.$hc + } else { + $cssClasses += "foreground-$hc" + } + } + elseif ($n -and $psStyle -and $psStyle.Background.$hc -and + $psStyle.Background.$hc -match '^\e') { + if ($canUseANSI -and -not $canUseHTML) { + $psStyle.Background.$hc + } else { + $cssClasses += "background-$hc" + } + } + + + + if ($hc -and $hc -notmatch '^[\#\e]') { + $placesToLook= + @(if ($hc.Contains('.')) { + $module, $setting = $hc -split '\.', 2 + $theModule = Get-Module $module + $theModule.PrivateData.Color, + $theModule.PrivateData.Colors, + $theModule.PrivateData.Colour, + $theModule.PrivateData.Colours, + $theModule.PrivateData.EZOut, + $global:PSColors, + $global:PSColours + } else { + $setting = $hc + $moduleColorSetting = $theModule.PrivateData.PSColors.$setting + }) + + foreach ($place in $placesToLook) { + if (-not $place) { continue } + foreach ($propName in $setting -split '\.') { + $place = $place.$propName + if (-not $place) { break } + } + if ($place -and "$place".StartsWith('#') -and 4,7 -contains "$place".Length) { + $hc = $place + continue + } + } + if (-not $hc.StartsWith -or -not $hc.StartsWith('#')) { + continue + } + } + $r,$g,$b = if ($hc.Length -eq 7) { + [int]::Parse($hc[1..2]-join'', 'HexNumber') + [int]::Parse($hc[3..4]-join '', 'HexNumber') + [int]::Parse($hc[5..6] -join'', 'HexNumber') + }elseif ($hc.Length -eq 4) { + [int]::Parse($hc[1], 'HexNumber') * 16 + [int]::Parse($hc[2], 'HexNumber') * 16 + [int]::Parse($hc[3], 'HexNumber') * 16 + } + + if ($canUseHTML) { + if ($n -eq 1) { "color:$hc" } + elseif ($n -eq 2) { "background-color:$hc"} + } + elseif ($canUseANSI) { + if ($n -eq 1) { $esc+"[38;2;$r;$g;${b}m" } + elseif ($n -eq 2) { $esc+"[48;2;$r;$g;${b}m" } + } + + }) + + $styleAttributes = @() + $colorAttributes + + $styleAttributes += @( + if ($Bold) { + if ($canUseHTML) {"font-weight:bold"} + elseif ($canUseANSI) { '' + $esc + "[1m" } + } + if ($Faint) { + if ($canUseHTML) { "opacity:.5" } + elseif ($canUseANSI) { '' + $esc + "[2m" } + } + if ($Italic) { + if ($canUseHTML) { "font-weight:bold" } + elseif ($canUseANSI) {'' + $esc + "[3m" } + } + + if ($Underline -and -not $doubleUnderline) { + if ($canUseHTML) { "text-decoration:underline"} + elseif ($canUseANSI) {'' +$esc + "[4m" } + } + + if ($Blink) { + if ($canUseANSI) { '' +$esc + "[5m" } + } + + if ($invert) { + if ($canUseHTML) {"filter:invert(100%)"} + elseif ($canUseANSI) { '' + $esc + "[7m"} + } + + if ($hide) { + if ($canUseHTML) {"opacity:0"} + elseif ($canUseANSI) { '' + $esc + "[8m"} + } + + if ($Strikethru) { + if ($canUseHTML) {"text-decoration: line-through"} + elseif ($canUseANSI) { '' +$esc + "[9m" } + } + + if ($DoubleUnderline) { + if ($canUseHTML) { "border-bottom: 3px double;"} + elseif ($canUseANSI) {'' +$esc + "[21m" } + } + + if ($Alignment -and $canUseHTML) { + "display:block;text-align:$($Alignment.ToLower())" + } + + if ($Link) { + if ($canUseHTML) { + # Hyperlinks need to be a nested element + # so we will not add it to style attributes for HTML + } + elseif ($canUseANSI) { + # For ANSI, + '' + $esc + ']8m;;' + $Link + $esc + '\' + } + } + + ) + + $header = + if ($canUseHTML) { + "<span$( + if ($styleAttributes) { " style='$($styleAttributes -join ';')'"} + )$( + if ($cssClasses) { " class='$($cssClasses -join ' ')'"} + )>" + $( + if ($Link) { + "<a href='$link'>" + } + ) + } elseif ($canUseANSI) { + $styleAttributes -join '' + } + } + + process { + $inputObjectAsString = + "$(if ($inputObject) { $inputObject | Out-String})".Trim() + + $inputObjectAsString = + if ($Alignment -and -not $canUseHTML) { + (@(foreach ($inputObjectLine in ($inputObjectAsString -split '(?>\r\n|\n)')) { + $inputObjectLength = $ansiCode.Replace($inputObjectLine, '').Length + if ($inputObjectLength -lt $LineLength) { + if ($Alignment -eq 'Left') { + $inputObjectLine + } elseif ($Alignment -eq 'Right') { + (' ' * ($LineLength - $inputObjectLength)) + $inputObjectLine + } else { + $half = ($LineLength - $inputObjectLength)/2 + (' ' * [Math]::Floor($half)) + $inputObjectLine + + (' ' * [Math]::Ceiling($half)) + } + } + else { + $inputObjectLine + } + }) -join [Environment]::NewLine) + [Environment]::newline + } else { + $inputObjectAsString + } + + $allOutput += + if ($header) { + "$header" + $inputObjectAsString + } + elseif ($inputObject) { + $inputObjectAsString + } + } + + end { + + if (-not $NoClear) { + $allOutput += + if ($canUseHTML) { + if ($Link) { + "</a>" + } + "</span>" + } + elseif ($canUseANSI) { + if ($Bold -or $Faint -or $colorAttributes -match '\[1;') { + "$esc[22m" + } + if ($Italic) { + "$esc[23m" + } + if ($Underline -or $doubleUnderline) { + "$esc[24m" + } + if ($Blink) { + "$esc[25m" + } + if ($Invert) { + "$esc[27m" + } + if ($hide) { + "$esc[28m" + } + if ($Strikethru) { + "$esc[29m" + } + if ($ForegroundColor) { + "$esc[39m" + } + if ($BackgroundColor) { + "$esc[49m" + } + + if ($Link) { + "$esc]8;;$esc\" + } + + if (-not ($Underline -or $Bold -or $Invert -or $ForegroundColor -or $BackgroundColor)) { + '' + $esc + '[0m' + } + } + } + + $allOutput -join '' + } + + + + + + + + + + + List + + PSKoans.CompleteResult + + + + + + + KoansPassed + + + TotalKoans + + + RequestedTopic + + + Complete + + + + + + + + PSKoans.CompleteResult + + PSKoans.CompleteResult + + + + + + + + $_.RequestedTopic + + + @{ + FormatString = @" + Congratulations! You have taken the first steps towards enlightenment. + + You have completed the {0}: +{1} +"@ + Topics = $_.RequestedTopic + } + + Prompt.TopicList + + + $moduleName = 'PSKoans' + + do { + $lm = Get-Module -Name $moduleName -ErrorAction Ignore + if (-not $lm) { continue } + if ($lm.FormatPartsLoaded) { break } + $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { + foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { + $ParentNode = $partNodeName.Node.ParentNode + "$($ParentNode.Name)={ + $($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" + } + }) -join [Environment]::NewLine + New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | + Import-Module -Global + $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") + + if (-not $lm.OnRemove) { + $lm.OnRemove = $onRemove + } else { + $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) + } + $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force + + } while ($false) + + +@(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' -NoClear) -join '' + + Congratulations! You have made great progress towards enlightenment. + + The journey to mastery is never-ending; if at any point you feel the need to + revisit a topic, you can simply call "Reset-PSKoan -Topic $name" to reset + that specific topic and work through it once again. + + May your newfound knowledge serve you well, and may you find myriad ways to + pass it along to others in turn. + + Mountains are, once again, merely mountains. + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' ) -join '' + + + + + 1 + Prompt.Koan + + + $_ + Prompt.ProgressPreamble + + + + $_.RequestedTopic.Count -gt 1 + + + @{ + Completed = $_.CurrentTopic.Completed + Total = $_.CurrentTopic.Total + Name = $_.CurrentTopic.Name + Width = 0.5 + } + + Prompt.ProgressBar + + + + $_.RequestedTopic.Count -eq 1 + + + @{ + Completed = $_.CurrentTopic.Completed + Total = $_.CurrentTopic.Total + Name = $_.CurrentTopic.Name + Width = 0.8 + } + + Prompt.ProgressBar + + + + + -not $_.RequestedTopic -or + $_.RequestedTopic.Count -gt 1 + + + + @{ + Completed = $_.KoansPassed + Total = $_.TotalKoans + Name = 'Total' + Width = 0.8 + } + + Prompt.ProgressBar + + + + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' -NoClear) -join '' + + If you would like to further your studies in this manner, consider investing in + "PowerShell by Mistake" by Don Jones - https://leanpub.com/powershell-by-mistake + + @(& ${PSKoans_Format-RichText} -ForegroundColor 'PSKoans.Meditation.Text' ) -join '' + + + + + + + + PSKoans.KoanInfo + + PSKoans.KoanInfo + + + + + + + + + + + + + + + Topic + + + Module + + + Position + + + + + + + + List + + PSKoans.Result + + + + + + + Describe + + + It + + + Expectation + + + Meditation + + + KoansPassed + + + TotalKoans + + + CurrentTopic + + + + + + + + Meditation + + PSKoans.Result + + + + + + + 1 + Prompt.Preface + + + $_.Describe + Prompt.Describe + + + $_ + Prompt.Expectation + + + $_ + Prompt.Meditation + + + 1 + Prompt.Koan + + + + $_.RequestedTopic + + + @{ + Topics = $_.RequestedTopic + FormatString = @" + You must meditate further on your selected {0}: +{1} +"@ + } + + Prompt.TopicList + + + $_ + Prompt.ProgressPreamble + + + + $_.RequestedTopic.Count -ne 1 + + + @{ + Completed = $_.CurrentTopic.Completed + Total = $_.CurrentTopic.Total + Name = $_.CurrentTopic.Name + Width = 0.5 + } + + Prompt.ProgressBar + + + + $_.RequestedTopic.Count -eq 1 + + @{ + Completed = $_.CurrentTopic.Completed + Total = $_.CurrentTopic.Total + Name = $_.CurrentTopic.Name + Width = 0.8 + } + + Prompt.ProgressBar + + + + + -not $_.RequestedTopic -or + $_.RequestedTopic.Count -gt 1 + + + + @{ + Completed = $_.KoansPassed + Total = $_.TotalKoans + Name = 'Total' + Width = 0.8 + } + + Prompt.ProgressBar + + + 1 + Prompt.End + + + + + + + + Detailed + + PSKoans.Result + + + + + + + $_ + Prompt.Expectation + + + $_ + Prompt.Meditation + + + 1 + Prompt.Koan + + + + $_.RequestedTopic + + + @{ + Topics = $_.RequestedTopic + FormatString = @" + You must meditate further on your selected {0}: +{1} +"@ + } + + Prompt.TopicList + + + $_ + Prompt.ProgressPreamble + + + + $_.Results + + Prompt.Details + + + + $_.RequestedTopic.Count -ne 1 + + + @{ + Completed = $_.CurrentTopic.Completed + Total = $_.CurrentTopic.Total + Name = $_.CurrentTopic.Name + Width = 0.5 + Newline = $true + } + + Prompt.ProgressBar + + + + $_.RequestedTopic.Count -eq 1 + + + @{ + Completed = $_.CurrentTopic.Completed + Total = $_.CurrentTopic.Total + Name = $_.CurrentTopic.Name + Width = 0.8 + } + + Prompt.ProgressBar + + + + + -not $_.RequestedTopic -or + $_.RequestedTopic.Count -gt 1 + + + + @{ + Completed = $_.KoansPassed + Total = $_.TotalKoans + Name = 'Total' + Width = 0.8 + } + + Prompt.ProgressBar + + + + + + + + diff --git a/README.md b/README.md index 10870051..9b10b660 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ View the PSKoans [Command Reference Documentation][reference-docs]. - PowerShell version 5.1 / PowerShell 6+ - NuGet (Windows only) -- Pester v4.x +- Pester v5.x Windows only: If you've never installed PowerShell modules before, you need to first install the NuGet PackageProvider to enable modules to be installed: From e15f0308989232be579e4cc686294b1bcca0aeb5 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 00:34:58 -0800 Subject: [PATCH 05/92] Add sanity output check --- .github/workflows/github.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index bb619474..21c8c660 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -134,6 +134,11 @@ jobs: Write-Output "pester_min_version=$MinimumVersion" >> $GITHUB_OUTPUT Write-Host "Minimum Pester Version: $MinimumVersion" + - name: Get Pester min value from output + shell: pwsh + run: | + Write-Host ${{ steps.pestermin.outputs.pester_min_version }} + - name: Install and cache PowerShell modules uses: potatoqualitee/psmodulecache@v5.2 with: From b7dffdb8d7d9561bc9ae5e5aa325153fd9f80366 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 00:35:59 -0800 Subject: [PATCH 06/92] Move sanity test to build job --- .github/workflows/github.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 21c8c660..3cae9e0b 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -70,6 +70,11 @@ jobs: Write-Output "pester_min_version=$MinimumVersion" >> $GITHUB_OUTPUT Write-Host "Minimum Pester Version: $MinimumVersion" + - name: Get Pester min value from output + shell: pwsh + run: | + Write-Host ${{ steps.pestermin.outputs.pester_min_version }} + - name: Install and cache PowerShell modules uses: potatoqualitee/psmodulecache@v5.2 with: @@ -134,11 +139,6 @@ jobs: Write-Output "pester_min_version=$MinimumVersion" >> $GITHUB_OUTPUT Write-Host "Minimum Pester Version: $MinimumVersion" - - name: Get Pester min value from output - shell: pwsh - run: | - Write-Host ${{ steps.pestermin.outputs.pester_min_version }} - - name: Install and cache PowerShell modules uses: potatoqualitee/psmodulecache@v5.2 with: From 1cd0fcd0f55e32ee4bce11950133a7aedb33024d Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 00:40:27 -0800 Subject: [PATCH 07/92] Switch from github_output to github_env --- .github/workflows/github.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 3cae9e0b..19e404c4 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -67,18 +67,18 @@ jobs: shell: pwsh run: | $MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version.ToString() - Write-Output "pester_min_version=$MinimumVersion" >> $GITHUB_OUTPUT + Write-Output "pester_min_version=$MinimumVersion" >> $GITHUB_ENV Write-Host "Minimum Pester Version: $MinimumVersion" - - name: Get Pester min value from output + - name: Get Pester min value from env shell: pwsh run: | - Write-Host ${{ steps.pestermin.outputs.pester_min_version }} + Write-Host $pester_min_version - name: Install and cache PowerShell modules uses: potatoqualitee/psmodulecache@v5.2 with: - modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ steps.pestermin.outputs.pester_min_version }}, EZOut + modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:$pester_min_version, EZOut shell: pwsh - name: Setup Environment @@ -136,13 +136,13 @@ jobs: shell: pwsh run: | $MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version.ToString() - Write-Output "pester_min_version=$MinimumVersion" >> $GITHUB_OUTPUT + Write-Output "pester_min_version=$MinimumVersion" >> $GITHUB_ENV Write-Host "Minimum Pester Version: $MinimumVersion" - name: Install and cache PowerShell modules uses: potatoqualitee/psmodulecache@v5.2 with: - modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ steps.pestermin.outputs.pester_min_version }}, EZOut + modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:$pester_min_version, EZOut shell: pwsh - name: Setup Environment From 08186882d3d9dccbbb5147d351466084c62ea858 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 00:50:53 -0800 Subject: [PATCH 08/92] Change back to Output according to documentation https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context --- .github/workflows/github.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 19e404c4..af0e1fb9 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -67,13 +67,13 @@ jobs: shell: pwsh run: | $MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version.ToString() - Write-Output "pester_min_version=$MinimumVersion" >> $GITHUB_ENV + Write-Output "pester_min_version=$MinimumVersion" >> $GITHUB_OUTPUT Write-Host "Minimum Pester Version: $MinimumVersion" - - name: Get Pester min value from env + - name: Get Pester min value from output shell: pwsh run: | - Write-Host $pester_min_version + Write-Host ${{ steps.pestermin.outputs.pester_min_version }} - name: Install and cache PowerShell modules uses: potatoqualitee/psmodulecache@v5.2 From 3347b8c450e311aba97d3b23f0395bec612aca13 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 00:56:06 -0800 Subject: [PATCH 09/92] Use GITHUB_ENV based on documentation https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files --- .github/workflows/github.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index af0e1fb9..4f12f590 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -67,13 +67,13 @@ jobs: shell: pwsh run: | $MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version.ToString() - Write-Output "pester_min_version=$MinimumVersion" >> $GITHUB_OUTPUT + Write-Output "pester_min_version=$MinimumVersion" >> $GITHUB_ENV Write-Host "Minimum Pester Version: $MinimumVersion" - - name: Get Pester min value from output + - name: Get Pester min value from env shell: pwsh run: | - Write-Host ${{ steps.pestermin.outputs.pester_min_version }} + Write-Host "Minimum Pester Version: ${{ env.pester_min_version }}" - name: Install and cache PowerShell modules uses: potatoqualitee/psmodulecache@v5.2 From 4fd8501255d32f48c01b49af3f817ffcf711c9e3 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 01:03:16 -0800 Subject: [PATCH 10/92] Switch to using proper Powershell --- .github/workflows/github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 4f12f590..efd97677 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -67,7 +67,7 @@ jobs: shell: pwsh run: | $MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version.ToString() - Write-Output "pester_min_version=$MinimumVersion" >> $GITHUB_ENV + Write-Output "pester_min_version=$MinimumVersion" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append Write-Host "Minimum Pester Version: $MinimumVersion" - name: Get Pester min value from env From 0a1ab8c06486335df06b4c4b0d0e83c4142a667e Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 01:04:45 -0800 Subject: [PATCH 11/92] Propogate proper pwsh env var setting --- .github/workflows/github.yml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index efd97677..2daf363c 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -70,15 +70,10 @@ jobs: Write-Output "pester_min_version=$MinimumVersion" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append Write-Host "Minimum Pester Version: $MinimumVersion" - - name: Get Pester min value from env - shell: pwsh - run: | - Write-Host "Minimum Pester Version: ${{ env.pester_min_version }}" - - name: Install and cache PowerShell modules uses: potatoqualitee/psmodulecache@v5.2 with: - modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:$pester_min_version, EZOut + modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ env.pester_min_version }}, EZOut shell: pwsh - name: Setup Environment @@ -136,13 +131,13 @@ jobs: shell: pwsh run: | $MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version.ToString() - Write-Output "pester_min_version=$MinimumVersion" >> $GITHUB_ENV + Write-Output "pester_min_version=$MinimumVersion" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append Write-Host "Minimum Pester Version: $MinimumVersion" - name: Install and cache PowerShell modules uses: potatoqualitee/psmodulecache@v5.2 with: - modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:$pester_min_version, EZOut + modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ env.pester_min_version }}, EZOut shell: pwsh - name: Setup Environment From 9206937451c59abf2bf60f7e6ac5e0a7031637dc Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 01:08:01 -0800 Subject: [PATCH 12/92] Add setting for GitHub actions in Initialize-Environment --- Build/Initialize-Environment.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Build/Initialize-Environment.ps1 b/Build/Initialize-Environment.ps1 index 9576a58d..f28011db 100644 --- a/Build/Initialize-Environment.ps1 +++ b/Build/Initialize-Environment.ps1 @@ -4,7 +4,7 @@ Set-BuildEnvironment $ProjectRoot = Resolve-Path -Path "$PSScriptRoot/.." Write-Host "##vso[task.setvariable variable=ProjectRoot]$ProjectRoot" - +Write-Output "PROJECTROOT=$ProjectRoot" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append $Lines = '-' * 70 Write-Host $Lines From d4c49134cc64c0e6ba82e015f13dedc93a53a5d9 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 01:13:06 -0800 Subject: [PATCH 13/92] Add -Force for copying PSKoans path --- Build/Build-Module.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Build/Build-Module.ps1 b/Build/Build-Module.ps1 index 1ee5a3b8..76a42c4d 100644 --- a/Build/Build-Module.ps1 +++ b/Build/Build-Module.ps1 @@ -36,5 +36,5 @@ catch { # Build external help files from Platyps MD files New-ExternalHelp -Path "$env:PROJECTROOT/docs/" -OutputPath "$env:PROJECTROOT/PSKoans/en" -Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $env:BUILTMODULEPATH -Recurse -PassThru | +Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $env:BUILTMODULEPATH -Force -Recurse -PassThru | Where-Object { -not $_.PSIsContainer } From 6e1597b9d9c5b8cf02f5d9bc958092f325cefc91 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 01:23:29 -0800 Subject: [PATCH 14/92] Find out exact location of BuiltModule Path Also show what is located in $env:PROJECTROOT/PSKoans and what is in $env:BUILTMODULEPATH --- Build/Build-Module.ps1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Build/Build-Module.ps1 b/Build/Build-Module.ps1 index 76a42c4d..c242d2e8 100644 --- a/Build/Build-Module.ps1 +++ b/Build/Build-Module.ps1 @@ -36,5 +36,11 @@ catch { # Build external help files from Platyps MD files New-ExternalHelp -Path "$env:PROJECTROOT/docs/" -OutputPath "$env:PROJECTROOT/PSKoans/en" -Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $env:BUILTMODULEPATH -Force -Recurse -PassThru | +Get-ChildItem -Path $env:PROJECTROOT -Recurse + +Get-ChildItem -Path $env:BUILTMODULEPATH -Recurse + +Write-Host "BuiltModulePath: $env:BUILTMODULEPATH" + +Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $env:BUILTMODULEPATH -Recurse -PassThru | Where-Object { -not $_.PSIsContainer } From 9b1e741115546375532e653d5df5f1404bdb23a6 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 01:33:27 -0800 Subject: [PATCH 15/92] Access BuiltModulePath from env GitHub env acts differently when set in the yml --- Build/Build-Module.ps1 | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/Build/Build-Module.ps1 b/Build/Build-Module.ps1 index c242d2e8..d05680b4 100644 --- a/Build/Build-Module.ps1 +++ b/Build/Build-Module.ps1 @@ -36,11 +36,30 @@ catch { # Build external help files from Platyps MD files New-ExternalHelp -Path "$env:PROJECTROOT/docs/" -OutputPath "$env:PROJECTROOT/PSKoans/en" -Get-ChildItem -Path $env:PROJECTROOT -Recurse +if($null -eq $env:BUILTMODULEPATH -and $null -ne $BuiltModulePath) { + Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $BuiltModulePath -Recurse -PassThru | + Where-Object { -not $_.PSIsContainer } +} elseif ($null -eq $BuiltModulePath -and $null -ne $env:BUILTMODULEPATH) { + Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $env:BUILTMODULEPATH -Recurse -PassThru | + Where-Object { -not $_.PSIsContainer } +} else { + Write-Error "Missing BuiltModulePath environment variable." +} -Get-ChildItem -Path $env:BUILTMODULEPATH -Recurse +Write-Host "=============================PROJECT ROOT=============================" +Get-ChildItem -Path $env:PROJECTROOT -Recurse +Write-Host "=============================Built Module Path=============================" Write-Host "BuiltModulePath: $env:BUILTMODULEPATH" -Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $env:BUILTMODULEPATH -Recurse -PassThru | - Where-Object { -not $_.PSIsContainer } +Get-ChildItem -Path $env:BUILTMODULEPATH -Recurse + +if($null -eq $env:BUILTMODULEPATH -and $null -ne $BuiltModulePath) { + Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $BuiltModulePath -Recurse -PassThru | + Where-Object { -not $_.PSIsContainer } +} elseif ($null -eq $BuiltModulePath -and $null -ne $env:BUILTMODULEPATH) { + Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $env:BUILTMODULEPATH -Recurse -PassThru | + Where-Object { -not $_.PSIsContainer } +} else { + Write-Error "Missing BuiltModulePath environment variable." +} From 8c677d9eaa062a7ca52b68fec8ca6f7943cbc958 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 01:36:53 -0800 Subject: [PATCH 16/92] Forgot to delete upper portion Also adds printout of all env variables --- Build/Build-Module.ps1 | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Build/Build-Module.ps1 b/Build/Build-Module.ps1 index d05680b4..fc364390 100644 --- a/Build/Build-Module.ps1 +++ b/Build/Build-Module.ps1 @@ -36,15 +36,7 @@ catch { # Build external help files from Platyps MD files New-ExternalHelp -Path "$env:PROJECTROOT/docs/" -OutputPath "$env:PROJECTROOT/PSKoans/en" -if($null -eq $env:BUILTMODULEPATH -and $null -ne $BuiltModulePath) { - Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $BuiltModulePath -Recurse -PassThru | - Where-Object { -not $_.PSIsContainer } -} elseif ($null -eq $BuiltModulePath -and $null -ne $env:BUILTMODULEPATH) { - Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $env:BUILTMODULEPATH -Recurse -PassThru | - Where-Object { -not $_.PSIsContainer } -} else { - Write-Error "Missing BuiltModulePath environment variable." -} +Get-ChildItem env: Write-Host "=============================PROJECT ROOT=============================" Get-ChildItem -Path $env:PROJECTROOT -Recurse From 6d5a5cf0665536bca7583d7a8837a57d8e8613c2 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 01:44:06 -0800 Subject: [PATCH 17/92] Fix reference to GITHUB_WORKSPACE env var --- .github/workflows/github.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 2daf363c..20cf32de 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -31,7 +31,7 @@ jobs: runs-on: ubuntu-latest env: - FilePath: '$GITHUB_WORKSPACE/Changelog.md' + FilePath: '$env:GITHUB_WORKSPACE/Changelog.md' steps: - uses: actions/checkout@v3 @@ -54,8 +54,8 @@ jobs: pester_min_version: ${{ steps.pestermin.outputs.pester_min_version }} env: - FileSystemDeploymentPath: '$GITHUB_WORKSPACE/Deploy/FileSystem' - BuiltModulePath: '$GITHUB_WORKSPACE/Deploy/PSKoans' + FileSystemDeploymentPath: '$env:GITHUB_WORKSPACE/Deploy/FileSystem' + BuiltModulePath: '$env:GITHUB_WORKSPACE/Deploy/PSKoans' # This needs to be set by the script which creates the nupkg NupkgPath: '' @@ -116,7 +116,7 @@ jobs: runs-on: ${{ matrix.os }} env: - PackageDownloadPath: '$GITHUB_WORKSPACE/Module' + PackageDownloadPath: '$env:GITHUB_WORKSPACE/Module' PSRepositoryName: 'FileSystem' # The following variables MUST be set in Invoke-ModuleTests.ps1 TestFile: '' @@ -183,8 +183,8 @@ jobs: - name: Generate Code Coverage uses: danielpalme/ReportGenerator-GitHub-Action@4.8.8 with: - reports: '$GITHUB_WORKSPACE\$CodeCoverageFile' - targetdir: '$GITHUB_WORKSPACE\coveragereports' + reports: '$env:GITHUB_WORKSPACE\$CodeCoverageFile' + targetdir: '$env:GITHUB_WORKSPACE\coveragereports' sourcedirs: $SourceFolders title: PSKoans Code Coverage @@ -192,7 +192,7 @@ jobs: uses: actions/upload-artifact@v2.2.3 with: name: 'Code Coverage Reports' - path: '$GITHUB_WORKSPACE\coveragereports' + path: '$env:GITHUB_WORKSPACE\coveragereports' publish: needs: test @@ -201,8 +201,8 @@ jobs: runs-on: ubuntu-latest env: - BuiltModulePath: '$GITHUB_WORKSPACE/Deploy/PSKoans' - GalleryDeploymentPath: '$GITHUB_WORKSPACE/Deploy/PSGallery' + BuiltModulePath: '$env:GITHUB_WORKSPACE/Deploy/PSKoans' + GalleryDeploymentPath: '$env:GITHUB_WORKSPACE/Deploy/PSGallery' # This variable must be set by the script TagName: '' @@ -228,11 +228,11 @@ jobs: - name: Download Artifacts uses: actions/download-artifact@v2.0.9 with: - path: '$GITHUB_WORKSPACE/artifacts' + path: '$env:GITHUB_WORKSPACE/artifacts' - name: Update Release with Artifacts & Changelog uses: Roang-zero1/github-create-release-action@v2.1.0 with: created_tag: $TagName - changelog_file: '$GITHUB_WORKSPACE/artifacts/Changelog.md' + changelog_file: '$env:GITHUB_WORKSPACE/artifacts/Changelog.md' release_title: 'PSKoans Release $TagName' From 5e6dac348a93d3102db11dc1b2edb9c6b3a6872a Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 01:48:58 -0800 Subject: [PATCH 18/92] More debugging potential ways of getting var --- Build/Build-Module.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Build/Build-Module.ps1 b/Build/Build-Module.ps1 index fc364390..ac82ee4e 100644 --- a/Build/Build-Module.ps1 +++ b/Build/Build-Module.ps1 @@ -36,13 +36,13 @@ catch { # Build external help files from Platyps MD files New-ExternalHelp -Path "$env:PROJECTROOT/docs/" -OutputPath "$env:PROJECTROOT/PSKoans/en" -Get-ChildItem env: - -Write-Host "=============================PROJECT ROOT=============================" -Get-ChildItem -Path $env:PROJECTROOT -Recurse +# Get-ChildItem env: +# Write-Host "=============================PROJECT ROOT=============================" +# Get-ChildItem -Path $env:PROJECTROOT -Recurse +Write-Host "Which works?`n1: $env:PROJECTROOT`n2:$ProjectRoot" Write-Host "=============================Built Module Path=============================" -Write-Host "BuiltModulePath: $env:BUILTMODULEPATH" +Write-Host "BuiltModulePath: $env:BUILTMODULEPATH`nOr maybe: $BuiltModulePath" Get-ChildItem -Path $env:BUILTMODULEPATH -Recurse From feb563024ebba582f4ed4cf51291f7373fdfe4fb Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 07:33:58 -0800 Subject: [PATCH 19/92] Pass in vars into pwsh env It seems that scripts need to have their environment variables passed in from the actions yaml --- .github/workflows/github.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 20cf32de..e6093d59 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -79,10 +79,16 @@ jobs: - name: Setup Environment shell: pwsh run: ./Build/Initialize-Environment.ps1 + env: + BUILD_SOURCEBRANCHNAME: ${{ env.GITHUB_REF_NAME}} + BUILD_SOURCEBRANCH: ${{ env.GITHUB_REF }} - name: Build Module shell: pwsh run: ./Build/Build-Module.ps1 + env: + BUILTMODULEPATH: $BuiltModulePath + BHProjectName: ${{ env.BHProjectName }} - name: Upload Module Artifact uses: actions/upload-artifact@v3 From 887e1e6953769ca558c2fd086d7500a93dd40dc1 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 07:36:53 -0800 Subject: [PATCH 20/92] Remove auto-filled variable from being set --- .github/workflows/github.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index e6093d59..d8012838 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -88,7 +88,6 @@ jobs: run: ./Build/Build-Module.ps1 env: BUILTMODULEPATH: $BuiltModulePath - BHProjectName: ${{ env.BHProjectName }} - name: Upload Module Artifact uses: actions/upload-artifact@v3 From d2e0797a99dac53745a7afb2a24bcb4e66985e0b Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 07:39:52 -0800 Subject: [PATCH 21/92] Fix reference to env variable being passed in --- .github/workflows/github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index d8012838..e6246b6d 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -87,7 +87,7 @@ jobs: shell: pwsh run: ./Build/Build-Module.ps1 env: - BUILTMODULEPATH: $BuiltModulePath + BUILTMODULEPATH: ${{ env.BuiltModulePath }} - name: Upload Module Artifact uses: actions/upload-artifact@v3 From 3c56d9c459c44c3f9ab1b79b277e1c87f1629241 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 07:47:08 -0800 Subject: [PATCH 22/92] Add another env variable to script Also clean up some of the unused debugging Flattens if/else now that I know which var is the correct one --- .github/workflows/github.yml | 1 + Build/Build-Module.ps1 | 19 ++++--------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index e6246b6d..c727e512 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -88,6 +88,7 @@ jobs: run: ./Build/Build-Module.ps1 env: BUILTMODULEPATH: ${{ env.BuiltModulePath }} + GITHUB_WORKSPACE: ${{ env.GITHUB_WORKSPACE }} - name: Upload Module Artifact uses: actions/upload-artifact@v3 diff --git a/Build/Build-Module.ps1 b/Build/Build-Module.ps1 index ac82ee4e..154ea02f 100644 --- a/Build/Build-Module.ps1 +++ b/Build/Build-Module.ps1 @@ -36,22 +36,11 @@ catch { # Build external help files from Platyps MD files New-ExternalHelp -Path "$env:PROJECTROOT/docs/" -OutputPath "$env:PROJECTROOT/PSKoans/en" -# Get-ChildItem env: +Write-Host "=============================PROJECT ROOT=============================" +Get-ChildItem -Path $env:PROJECTROOT -Recurse -# Write-Host "=============================PROJECT ROOT=============================" -# Get-ChildItem -Path $env:PROJECTROOT -Recurse -Write-Host "Which works?`n1: $env:PROJECTROOT`n2:$ProjectRoot" Write-Host "=============================Built Module Path=============================" -Write-Host "BuiltModulePath: $env:BUILTMODULEPATH`nOr maybe: $BuiltModulePath" - Get-ChildItem -Path $env:BUILTMODULEPATH -Recurse -if($null -eq $env:BUILTMODULEPATH -and $null -ne $BuiltModulePath) { - Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $BuiltModulePath -Recurse -PassThru | - Where-Object { -not $_.PSIsContainer } -} elseif ($null -eq $BuiltModulePath -and $null -ne $env:BUILTMODULEPATH) { - Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $env:BUILTMODULEPATH -Recurse -PassThru | - Where-Object { -not $_.PSIsContainer } -} else { - Write-Error "Missing BuiltModulePath environment variable." -} +Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $env:BUILTMODULEPATH -Recurse -PassThru | + Where-Object { -not $_.PSIsContainer } \ No newline at end of file From b6e9378f50633886d15306a8f1428a615168bb1f Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 07:56:15 -0800 Subject: [PATCH 23/92] Expand variable within variable Also add some output statements for clarity --- Build/Build-Module.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Build/Build-Module.ps1 b/Build/Build-Module.ps1 index 154ea02f..76e40d45 100644 --- a/Build/Build-Module.ps1 +++ b/Build/Build-Module.ps1 @@ -37,10 +37,12 @@ catch { New-ExternalHelp -Path "$env:PROJECTROOT/docs/" -OutputPath "$env:PROJECTROOT/PSKoans/en" Write-Host "=============================PROJECT ROOT=============================" +Write-Host "ProjectRoot: $env:ProjectRoot" Get-ChildItem -Path $env:PROJECTROOT -Recurse Write-Host "=============================Built Module Path=============================" -Get-ChildItem -Path $env:BUILTMODULEPATH -Recurse +Write-Host "BuiltModulePath: $env:BUILTMODULEPATH`nGITHUB_WORKSPACE: $env:GITHUB_WORKSPACE" +Get-ChildItem -Path $($env:BUILTMODULEPATH.Replace('$env:GITHUB_WORKSPACE', $env:GITHUB_WORKSPACE)) -Recurse Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $env:BUILTMODULEPATH -Recurse -PassThru | Where-Object { -not $_.PSIsContainer } \ No newline at end of file From 53f564b6a29da8d495f58e692930597df1fb49a7 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 07:59:47 -0800 Subject: [PATCH 24/92] Pass in another env variable Also, store the calculated path variable for use in later copying --- .github/workflows/github.yml | 1 + Build/Build-Module.ps1 | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index c727e512..862b92e3 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -87,6 +87,7 @@ jobs: shell: pwsh run: ./Build/Build-Module.ps1 env: + PROJECTROOT: ${{ env.ProjectRoot }} BUILTMODULEPATH: ${{ env.BuiltModulePath }} GITHUB_WORKSPACE: ${{ env.GITHUB_WORKSPACE }} diff --git a/Build/Build-Module.ps1 b/Build/Build-Module.ps1 index 76e40d45..8faf57da 100644 --- a/Build/Build-Module.ps1 +++ b/Build/Build-Module.ps1 @@ -42,7 +42,9 @@ Get-ChildItem -Path $env:PROJECTROOT -Recurse Write-Host "=============================Built Module Path=============================" Write-Host "BuiltModulePath: $env:BUILTMODULEPATH`nGITHUB_WORKSPACE: $env:GITHUB_WORKSPACE" -Get-ChildItem -Path $($env:BUILTMODULEPATH.Replace('$env:GITHUB_WORKSPACE', $env:GITHUB_WORKSPACE)) -Recurse -Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $env:BUILTMODULEPATH -Recurse -PassThru | +$BuiltModulePath = $env:BUILTMODULEPATH.Replace('$env:GITHUB_WORKSPACE', $env:GITHUB_WORKSPACE) +Get-ChildItem -Path $BuiltModulePath -Recurse + +Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $BuiltModulePath -Recurse -PassThru | Where-Object { -not $_.PSIsContainer } \ No newline at end of file From 62dc63579fb1c58dbb5023a66d6b6cab7c25ab32 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 08:05:36 -0800 Subject: [PATCH 25/92] Determine the value for PROJECTROOT I am trying to understand how the env variables sometime pass in correct and sometimes are only seemingly visible (when viewing the action output) but not when trying to reference them in code. --- .github/workflows/github.yml | 7 ++++++- Build/Build-Module.ps1 | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 862b92e3..17c09f09 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -83,11 +83,16 @@ jobs: BUILD_SOURCEBRANCHNAME: ${{ env.GITHUB_REF_NAME}} BUILD_SOURCEBRANCH: ${{ env.GITHUB_REF }} + - name: Print ProjectRoot + shell: pwsh + run: | + Write-Host "ProjectRoot: ${{ env.PROJECTROOT }}" + - name: Build Module shell: pwsh run: ./Build/Build-Module.ps1 env: - PROJECTROOT: ${{ env.ProjectRoot }} + PROJECTROOT: ${{ env.PROJECTROOT }} BUILTMODULEPATH: ${{ env.BuiltModulePath }} GITHUB_WORKSPACE: ${{ env.GITHUB_WORKSPACE }} diff --git a/Build/Build-Module.ps1 b/Build/Build-Module.ps1 index 8faf57da..5475a543 100644 --- a/Build/Build-Module.ps1 +++ b/Build/Build-Module.ps1 @@ -3,6 +3,7 @@ Get-PackageProvider -Name NuGet -ForceBootstrap > $null # Create format.ps1xml file & "$PSScriptRoot/../PSKoans.ezformat.ps1" +Write-Host "ProjectRoot: $env:PROJECTROOT" Import-Module "$env:PROJECTROOT/PSKoans" @@ -37,7 +38,7 @@ catch { New-ExternalHelp -Path "$env:PROJECTROOT/docs/" -OutputPath "$env:PROJECTROOT/PSKoans/en" Write-Host "=============================PROJECT ROOT=============================" -Write-Host "ProjectRoot: $env:ProjectRoot" +Write-Host "ProjectRoot: $env:PROJECTROOT" Get-ChildItem -Path $env:PROJECTROOT -Recurse Write-Host "=============================Built Module Path=============================" From 30e63b81cebe49bc316b76b2dfcff45c34fc8429 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 08:08:59 -0800 Subject: [PATCH 26/92] Remove debugging and fully qualify env variables --- .github/workflows/github.yml | 13 ++++--------- Build/Build-Module.ps1 | 8 -------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 17c09f09..21719dd4 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -83,11 +83,6 @@ jobs: BUILD_SOURCEBRANCHNAME: ${{ env.GITHUB_REF_NAME}} BUILD_SOURCEBRANCH: ${{ env.GITHUB_REF }} - - name: Print ProjectRoot - shell: pwsh - run: | - Write-Host "ProjectRoot: ${{ env.PROJECTROOT }}" - - name: Build Module shell: pwsh run: ./Build/Build-Module.ps1 @@ -99,8 +94,8 @@ jobs: - name: Upload Module Artifact uses: actions/upload-artifact@v3 with: - name: $ModuleArtifactName - path: $BuiltModulePath + name: ${{ env.ModuleArtifactName }} + path: ${{ env.BuiltModulePath }} - name: Generate Nupkg shell: pwsh @@ -111,8 +106,8 @@ jobs: - name: Upload Nupkg Artifact uses: actions/upload-artifact@v3 with: - name: $NupkgArtifactName - path: $NupkgPath + name: ${{ env.NupkgArtifactName }} + path: ${{ env.NupkgPath }} test: name: "Test Module" diff --git a/Build/Build-Module.ps1 b/Build/Build-Module.ps1 index 5475a543..ac47d0a0 100644 --- a/Build/Build-Module.ps1 +++ b/Build/Build-Module.ps1 @@ -3,7 +3,6 @@ Get-PackageProvider -Name NuGet -ForceBootstrap > $null # Create format.ps1xml file & "$PSScriptRoot/../PSKoans.ezformat.ps1" -Write-Host "ProjectRoot: $env:PROJECTROOT" Import-Module "$env:PROJECTROOT/PSKoans" @@ -37,13 +36,6 @@ catch { # Build external help files from Platyps MD files New-ExternalHelp -Path "$env:PROJECTROOT/docs/" -OutputPath "$env:PROJECTROOT/PSKoans/en" -Write-Host "=============================PROJECT ROOT=============================" -Write-Host "ProjectRoot: $env:PROJECTROOT" -Get-ChildItem -Path $env:PROJECTROOT -Recurse - -Write-Host "=============================Built Module Path=============================" -Write-Host "BuiltModulePath: $env:BUILTMODULEPATH`nGITHUB_WORKSPACE: $env:GITHUB_WORKSPACE" - $BuiltModulePath = $env:BUILTMODULEPATH.Replace('$env:GITHUB_WORKSPACE', $env:GITHUB_WORKSPACE) Get-ChildItem -Path $BuiltModulePath -Recurse From d9804aa0582fc4a4232d4708c6265d6638781bdd Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 08:13:16 -0800 Subject: [PATCH 27/92] Expand variable within variable for generating NuGet pkg --- .github/workflows/github.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 21719dd4..f75ff6b1 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -100,8 +100,9 @@ jobs: - name: Generate Nupkg shell: pwsh run: | - ./Build/Register-FileSystemRepository.ps1 -Path '${{ env.FileSystemDeploymentPath }}' -Name 'FileSystem' - ./Deploy/Publish.ps1 -Key 'filesystem' -Path '${{ env.FileSystemDeploymentPath }}' -OutputDirectory '${{ env.FileSystemDeploymentPath }}' + $FileSystemDeploymentPath = ${{ env.FileSystemDeploymentPath }}.Replace('$env:GITHUB_WORKSPACE', ${{ env:GITHUB_WORKSPACE}}) + ./Build/Register-FileSystemRepository.ps1 -Path $FileSystemDeploymentPath -Name 'FileSystem' + ./Deploy/Publish.ps1 -Key 'filesystem' -Path $FileSystemDeploymentPath -OutputDirectory $FileSystemDeploymentPath - name: Upload Nupkg Artifact uses: actions/upload-artifact@v3 From 8bc02456f8a584422d32de9948b4edda30dc571f Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 08:16:39 -0800 Subject: [PATCH 28/92] Attempt to fix invalid workspace --- .github/workflows/github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index f75ff6b1..9a33096d 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -100,7 +100,7 @@ jobs: - name: Generate Nupkg shell: pwsh run: | - $FileSystemDeploymentPath = ${{ env.FileSystemDeploymentPath }}.Replace('$env:GITHUB_WORKSPACE', ${{ env:GITHUB_WORKSPACE}}) + $FileSystemDeploymentPath = $env.FileSystemDeploymentPath.Replace('$env:GITHUB_WORKSPACE', $env:GITHUB_WORKSPACE) ./Build/Register-FileSystemRepository.ps1 -Path $FileSystemDeploymentPath -Name 'FileSystem' ./Deploy/Publish.ps1 -Key 'filesystem' -Path $FileSystemDeploymentPath -OutputDirectory $FileSystemDeploymentPath From 71b9b6416fcf51564e9bcfe3ddf82fc7f4d026e9 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 08:23:00 -0800 Subject: [PATCH 29/92] Properly expand github env variable --- .github/workflows/github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 9a33096d..dea8955f 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -100,7 +100,7 @@ jobs: - name: Generate Nupkg shell: pwsh run: | - $FileSystemDeploymentPath = $env.FileSystemDeploymentPath.Replace('$env:GITHUB_WORKSPACE', $env:GITHUB_WORKSPACE) + $FileSystemDeploymentPath = ${{ env.FileSystemDeploymentPath }}.Replace('$env:GITHUB_WORKSPACE', ${{ env:GITHUB_WORKSPACE }}) ./Build/Register-FileSystemRepository.ps1 -Path $FileSystemDeploymentPath -Name 'FileSystem' ./Deploy/Publish.ps1 -Key 'filesystem' -Path $FileSystemDeploymentPath -OutputDirectory $FileSystemDeploymentPath From 9fbead62e5f4d0b0d82c7f677e140991d74c9cc4 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 08:28:41 -0800 Subject: [PATCH 30/92] Expand variable at creation --- .github/workflows/github.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index dea8955f..58772aee 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -54,8 +54,8 @@ jobs: pester_min_version: ${{ steps.pestermin.outputs.pester_min_version }} env: - FileSystemDeploymentPath: '$env:GITHUB_WORKSPACE/Deploy/FileSystem' - BuiltModulePath: '$env:GITHUB_WORKSPACE/Deploy/PSKoans' + FileSystemDeploymentPath: '${{ env:GITHUB_WORKSPACE }}/Deploy/FileSystem' + BuiltModulePath: '${{ env:GITHUB_WORKSPACE }}/Deploy/PSKoans' # This needs to be set by the script which creates the nupkg NupkgPath: '' @@ -100,9 +100,8 @@ jobs: - name: Generate Nupkg shell: pwsh run: | - $FileSystemDeploymentPath = ${{ env.FileSystemDeploymentPath }}.Replace('$env:GITHUB_WORKSPACE', ${{ env:GITHUB_WORKSPACE }}) - ./Build/Register-FileSystemRepository.ps1 -Path $FileSystemDeploymentPath -Name 'FileSystem' - ./Deploy/Publish.ps1 -Key 'filesystem' -Path $FileSystemDeploymentPath -OutputDirectory $FileSystemDeploymentPath + ./Build/Register-FileSystemRepository.ps1 -Path ${{ env.FileSystemDeploymentPath }} -Name 'FileSystem' + ./Deploy/Publish.ps1 -Key 'filesystem' -Path ${{ env.FileSystemDeploymentPath }} -OutputDirectory ${{ env.FileSystemDeploymentPath }} - name: Upload Nupkg Artifact uses: actions/upload-artifact@v3 From 8cd78978be341ac20113fb1f490228dba009226b Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 08:35:04 -0800 Subject: [PATCH 31/92] Fix workspace issues by assigned env vars to script --- .github/workflows/github.yml | 12 ++++++++---- Build/Build-Module.ps1 | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 58772aee..33c8084b 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -54,8 +54,8 @@ jobs: pester_min_version: ${{ steps.pestermin.outputs.pester_min_version }} env: - FileSystemDeploymentPath: '${{ env:GITHUB_WORKSPACE }}/Deploy/FileSystem' - BuiltModulePath: '${{ env:GITHUB_WORKSPACE }}/Deploy/PSKoans' + FileSystemDeploymentPath: /Deploy/FileSystem + BuiltModulePath: /Deploy/PSKoans # This needs to be set by the script which creates the nupkg NupkgPath: '' @@ -100,8 +100,12 @@ jobs: - name: Generate Nupkg shell: pwsh run: | - ./Build/Register-FileSystemRepository.ps1 -Path ${{ env.FileSystemDeploymentPath }} -Name 'FileSystem' - ./Deploy/Publish.ps1 -Key 'filesystem' -Path ${{ env.FileSystemDeploymentPath }} -OutputDirectory ${{ env.FileSystemDeploymentPath }} + $FileSystemDeploymentPath = "$env:GITHUB_WORKSPACE/$env:FileSystemDeploymentPath" + ./Build/Register-FileSystemRepository.ps1 -Path $FileSystemDeploymentPath -Name 'FileSystem' + ./Deploy/Publish.ps1 -Key 'filesystem' -Path $FileSystemDeploymentPath -OutputDirectory $FileSystemDeploymentPath + env: + GITHUB_WORKSPACE: ${{ env.GITHUB_WORKSPACE}} + FileSystemDeploymentPath: ${{ env.FileSystemDeploymentPath }} - name: Upload Nupkg Artifact uses: actions/upload-artifact@v3 diff --git a/Build/Build-Module.ps1 b/Build/Build-Module.ps1 index ac47d0a0..a4b61d9d 100644 --- a/Build/Build-Module.ps1 +++ b/Build/Build-Module.ps1 @@ -36,8 +36,8 @@ catch { # Build external help files from Platyps MD files New-ExternalHelp -Path "$env:PROJECTROOT/docs/" -OutputPath "$env:PROJECTROOT/PSKoans/en" -$BuiltModulePath = $env:BUILTMODULEPATH.Replace('$env:GITHUB_WORKSPACE', $env:GITHUB_WORKSPACE) -Get-ChildItem -Path $BuiltModulePath -Recurse +$BuiltModulePath = "$env:GITHUB_WORKSPACE/$env:BUILTMODULEPATH" +Get-ChildItem -Path "$BuiltModulePath" -Recurse Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $BuiltModulePath -Recurse -PassThru | Where-Object { -not $_.PSIsContainer } \ No newline at end of file From 218c5751ae727f2ba5ab7b0bd78b2de6e1385954 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 09:19:39 -0800 Subject: [PATCH 32/92] Made RequiredVersion accessible Also allowed for more than 1 required or nested module going forward --- Deploy/Publish.ps1 | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Deploy/Publish.ps1 b/Deploy/Publish.ps1 index 62c5a944..77acd61e 100644 --- a/Deploy/Publish.ps1 +++ b/Deploy/Publish.ps1 @@ -14,14 +14,24 @@ $env:NugetApiKey = $Key if ($OutputDirectory) { Import-Module "$PSScriptRoot/PSKoans" - $Module = Get-Module -Name PSKoans - $Dependencies = @( - $Module.RequiredModules.Name - $Module.NestedModules.Name - ).Where{ $_ } + $PSKoansModule = Get-Module -Name PSKoans + $Dependencies = @() + $PSKoansModule.RequiredModules | ForEach-Object { + $Dependencies += @{ + Name = $_.Name + Version = $_.Version + } + } + $PSKoansModule.NestedModules | ForEach-Object { + $Dependencies += @{ + Name = $_.Name + Version = $_.Version + } + } + foreach ($Module in $Dependencies) { - Publish-Module -Name $Module -Repository FileSystem -NugetApiKey "Test-Publish" + Publish-Module -Name $Module.Name -RequiredVersion $Module.Version -Repository FileSystem -NugetApiKey "Test-Publish" } } From ce0fc645e3cbef9ca567747ca880f6e06999729f Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 09:25:42 -0800 Subject: [PATCH 33/92] Remove debug remnant Also try to correctly specify module output location --- .github/workflows/github.yml | 2 +- Build/Build-Module.ps1 | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 33c8084b..79afd9ee 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -95,7 +95,7 @@ jobs: uses: actions/upload-artifact@v3 with: name: ${{ env.ModuleArtifactName }} - path: ${{ env.BuiltModulePath }} + path: ${{ env.GITHUB_WORKSPACE }}/${{ env.BuiltModulePath }} - name: Generate Nupkg shell: pwsh diff --git a/Build/Build-Module.ps1 b/Build/Build-Module.ps1 index a4b61d9d..ff7d91d2 100644 --- a/Build/Build-Module.ps1 +++ b/Build/Build-Module.ps1 @@ -37,7 +37,6 @@ catch { New-ExternalHelp -Path "$env:PROJECTROOT/docs/" -OutputPath "$env:PROJECTROOT/PSKoans/en" $BuiltModulePath = "$env:GITHUB_WORKSPACE/$env:BUILTMODULEPATH" -Get-ChildItem -Path "$BuiltModulePath" -Recurse Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $BuiltModulePath -Recurse -PassThru | Where-Object { -not $_.PSIsContainer } \ No newline at end of file From af95d8c4c3a54f1a66811726002421c8b15845b0 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 09:34:29 -0800 Subject: [PATCH 34/92] Attempt to prove the caching works properly --- .github/workflows/github.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 79afd9ee..d7dcab2f 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -151,6 +151,11 @@ jobs: modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ env.pester_min_version }}, EZOut shell: pwsh + - name: Show the previous action works + shell: pwsh + run: | + Get-Module -Name PSDeploy, BuildHelpers, PlatyPS, EZOut -ListAvailable + - name: Setup Environment shell: pwsh run: ./Build/Initialize-Environment.ps1 From e1bf74470f24232adfa8cf158e2ba5b30a045bb0 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 09:39:19 -0800 Subject: [PATCH 35/92] Update workflow file again --- .github/workflows/github.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index d7dcab2f..47f1b136 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -153,8 +153,7 @@ jobs: - name: Show the previous action works shell: pwsh - run: | - Get-Module -Name PSDeploy, BuildHelpers, PlatyPS, EZOut -ListAvailable + run: Get-Module -Name PSDeploy, BuildHelpers, PlatyPS, EZOut -ListAvailable - name: Setup Environment shell: pwsh From 4e53a20c896d9a0f7e369fd9e48462e06609924c Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 09:40:22 -0800 Subject: [PATCH 36/92] Move test from test job to build job --- .github/workflows/github.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 47f1b136..d3e5b176 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -76,6 +76,10 @@ jobs: modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ env.pester_min_version }}, EZOut shell: pwsh + - name: Show the previous action works + shell: pwsh + run: Get-Module -Name PSDeploy, BuildHelpers, PlatyPS, EZOut -ListAvailable + - name: Setup Environment shell: pwsh run: ./Build/Initialize-Environment.ps1 @@ -151,10 +155,6 @@ jobs: modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ env.pester_min_version }}, EZOut shell: pwsh - - name: Show the previous action works - shell: pwsh - run: Get-Module -Name PSDeploy, BuildHelpers, PlatyPS, EZOut -ListAvailable - - name: Setup Environment shell: pwsh run: ./Build/Initialize-Environment.ps1 From 30c5d29927494d91779fd2ada21b4b5bc772ab35 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 09:51:37 -0800 Subject: [PATCH 37/92] Add Pester to output --- .github/workflows/github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index d3e5b176..76be2b0a 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -78,7 +78,7 @@ jobs: - name: Show the previous action works shell: pwsh - run: Get-Module -Name PSDeploy, BuildHelpers, PlatyPS, EZOut -ListAvailable + run: Get-Module -Name PSDeploy, BuildHelpers, PlatyPS, Pester, EZOut -ListAvailable - name: Setup Environment shell: pwsh From 492df63f470c5561921a7bad8b53a917b5ab8ef9 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 10:03:42 -0800 Subject: [PATCH 38/92] Temporarily remove module cacher It appears to have an issue restoring the PlatyPS module. Switching to manual always-install option --- .github/workflows/github.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 76be2b0a..982e63b1 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -69,12 +69,18 @@ jobs: $MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version.ToString() Write-Output "pester_min_version=$MinimumVersion" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append Write-Host "Minimum Pester Version: $MinimumVersion" - - - name: Install and cache PowerShell modules - uses: potatoqualitee/psmodulecache@v5.2 - with: - modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ env.pester_min_version }}, EZOut - shell: pwsh + + - name: Install from PSGallery + shell: pwsh + run: | + Set-PSRepository PSGallery -InstallationPolicy Trusted + Install-Module PSDeploy, BuildHelpers, PlatyPS, Pester:${{ env.pester_min_version }}, EZOut + + # - name: Install and cache PowerShell modules + # uses: potatoqualitee/psmodulecache@v5.2 + # with: + # modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ env.pester_min_version }}, EZOut + # shell: pwsh - name: Show the previous action works shell: pwsh From 45701796f2f001c0ebb6dc9b0958d0d38a02198b Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 10:19:20 -0800 Subject: [PATCH 39/92] Use correct install-module syntax for versions --- .github/workflows/github.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 982e63b1..d8175475 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -74,7 +74,9 @@ jobs: shell: pwsh run: | Set-PSRepository PSGallery -InstallationPolicy Trusted - Install-Module PSDeploy, BuildHelpers, PlatyPS, Pester:${{ env.pester_min_version }}, EZOut + Install-Module PSDeploy, BuildHelpers, PlatyPS, EZOut + Install-Module Pester -MinimumVersion $env:pester_min_version + env: pester_min_version: ${{ env.pester_min_version }} # - name: Install and cache PowerShell modules # uses: potatoqualitee/psmodulecache@v5.2 From 2b4b6ed55a9103087828819c0ab27cd0448238a8 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 10:20:23 -0800 Subject: [PATCH 40/92] Fix syntax error And fix missing whitespace --- .github/workflows/github.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index d8175475..f7a1b5df 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -76,7 +76,8 @@ jobs: Set-PSRepository PSGallery -InstallationPolicy Trusted Install-Module PSDeploy, BuildHelpers, PlatyPS, EZOut Install-Module Pester -MinimumVersion $env:pester_min_version - env: pester_min_version: ${{ env.pester_min_version }} + env: + pester_min_version: ${{ env.pester_min_version }} # - name: Install and cache PowerShell modules # uses: potatoqualitee/psmodulecache@v5.2 @@ -92,7 +93,7 @@ jobs: shell: pwsh run: ./Build/Initialize-Environment.ps1 env: - BUILD_SOURCEBRANCHNAME: ${{ env.GITHUB_REF_NAME}} + BUILD_SOURCEBRANCHNAME: ${{ env.GITHUB_REF_NAME }} BUILD_SOURCEBRANCH: ${{ env.GITHUB_REF }} - name: Build Module From 17a9f4c650c7f6cb991b03fc0f7751efd6885666 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 10:53:57 -0800 Subject: [PATCH 41/92] Fix reference to env variable in test job --- .github/workflows/github.yml | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index f7a1b5df..35725f7c 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -54,8 +54,8 @@ jobs: pester_min_version: ${{ steps.pestermin.outputs.pester_min_version }} env: - FileSystemDeploymentPath: /Deploy/FileSystem - BuiltModulePath: /Deploy/PSKoans + FileSystemDeploymentPath: Deploy/FileSystem + BuiltModulePath: Deploy/PSKoans # This needs to be set by the script which creates the nupkg NupkgPath: '' @@ -85,10 +85,6 @@ jobs: # modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ env.pester_min_version }}, EZOut # shell: pwsh - - name: Show the previous action works - shell: pwsh - run: Get-Module -Name PSDeploy, BuildHelpers, PlatyPS, Pester, EZOut -ListAvailable - - name: Setup Environment shell: pwsh run: ./Build/Initialize-Environment.ps1 @@ -140,7 +136,7 @@ jobs: runs-on: ${{ matrix.os }} env: - PackageDownloadPath: '$env:GITHUB_WORKSPACE/Module' + PackageDownloadPath: '/Module' PSRepositoryName: 'FileSystem' # The following variables MUST be set in Invoke-ModuleTests.ps1 TestFile: '' @@ -158,11 +154,20 @@ jobs: Write-Output "pester_min_version=$MinimumVersion" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append Write-Host "Minimum Pester Version: $MinimumVersion" - - name: Install and cache PowerShell modules - uses: potatoqualitee/psmodulecache@v5.2 - with: - modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ env.pester_min_version }}, EZOut - shell: pwsh + - name: Install from PSGallery + shell: pwsh + run: | + Set-PSRepository PSGallery -InstallationPolicy Trusted + Install-Module PSDeploy, BuildHelpers, PlatyPS, EZOut + Install-Module Pester -MinimumVersion $env:pester_min_version + env: + pester_min_version: ${{ env.pester_min_version }} + + # - name: Install and cache PowerShell modules + # uses: potatoqualitee/psmodulecache@v5.2 + # with: + # modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ env.pester_min_version }}, EZOut + # shell: pwsh - name: Setup Environment shell: pwsh @@ -170,7 +175,9 @@ jobs: - name: Register FileSystem Repository shell: pwsh - run: ./Build/Register-FileSystemRepository.ps1 -Path '${{ env.PackageDownloadPath }}' -Name '${{ env.PSRepositoryName }}' + run: | + $PackageDownloadPath = "$env:GITHUB_WORKSPACE/$env:PackageDownloadPath" + ./Build/Register-FileSystemRepository.ps1 -Path $PackageDownloadPath -Name ${{ env.PSRepositoryName }} - name: Download Module Nupkg uses: actions/download-artifact@v2.0.9 From d7b99a0b24f39e4e525d37261db43a0167b1f5da Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 11:02:59 -0800 Subject: [PATCH 42/92] More explicit environment access --- .github/workflows/github.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 35725f7c..9d3e7234 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -104,7 +104,7 @@ jobs: uses: actions/upload-artifact@v3 with: name: ${{ env.ModuleArtifactName }} - path: ${{ env.GITHUB_WORKSPACE }}/${{ env.BuiltModulePath }} + path: "${{ env.GITHUB_WORKSPACE }}/${{ env.BuiltModulePath }}" - name: Generate Nupkg shell: pwsh @@ -178,27 +178,35 @@ jobs: run: | $PackageDownloadPath = "$env:GITHUB_WORKSPACE/$env:PackageDownloadPath" ./Build/Register-FileSystemRepository.ps1 -Path $PackageDownloadPath -Name ${{ env.PSRepositoryName }} + env: + GITHUB_WORKSPACE: ${{ env.GITHUB_WORKSPACE }} + PackageDownloadPath: ${{ env.PackageDownloadPath }} - name: Download Module Nupkg uses: actions/download-artifact@v2.0.9 with: - name: $NupkgArtifactName - path: $PackageDownloadPath + name: ${{ env.NupkgArtifactName }} + path: "${{ env.GITHUB_WORKSPACE }}/${{ env.PackageDownloadPath }}" - name: Install Module from Nupkg shell: pwsh run: | + $PackageDownloadPath = "$env:GITHUB_WORKSPACE/$env:PackageDownloadPath" $pesterParams = @{ Name = 'Pester' MinimumVersion = Get-Content -Path "${{ needs.build.outputs.pester_min_version }}" ProviderName = 'NuGet' - Path = '${{ env.PackageDownloadPath }}' + Path = $PackageDownloadPath Force = $true Source = 'PSGallery' } Register-PackageSource -Name PSGallery -ProviderName NuGet -Location https://www.powershellgallery.com/api/v2 -Force Save-Package @pesterParams | Select-Object -Property Name, Version, Status, Source - Install-Module PSKoans -Repository ${{ env.PSRepositoryName }} -Force -Scope CurrentUser + Install-Module PSKoans -Repository ${{ env:PSRepositoryName }} -Force -Scope CurrentUser + env: + GITHUB_WORKSPACE: ${{ env.GITHUB_WORKSPACE }} + PackageDownloadPath: ${{ env.PackageDownloadPath }} + PSRepositoryName: ${{ env.PSRepositoryName }} - name: Run Pester Tests shell: pwsh From 6a670e1db5c6cd18de5c983b3a38bbed94e7a5a7 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 11:07:25 -0800 Subject: [PATCH 43/92] Fix failing workflow due to incorrect syntax --- .github/workflows/github.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 9d3e7234..1878781b 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -136,7 +136,7 @@ jobs: runs-on: ${{ matrix.os }} env: - PackageDownloadPath: '/Module' + PackageDownloadPath: 'Module' PSRepositoryName: 'FileSystem' # The following variables MUST be set in Invoke-ModuleTests.ps1 TestFile: '' @@ -202,7 +202,7 @@ jobs: } Register-PackageSource -Name PSGallery -ProviderName NuGet -Location https://www.powershellgallery.com/api/v2 -Force Save-Package @pesterParams | Select-Object -Property Name, Version, Status, Source - Install-Module PSKoans -Repository ${{ env:PSRepositoryName }} -Force -Scope CurrentUser + Install-Module PSKoans -Repository $env:PSRepositoryName -Force -Scope CurrentUser env: GITHUB_WORKSPACE: ${{ env.GITHUB_WORKSPACE }} PackageDownloadPath: ${{ env.PackageDownloadPath }} From ff59daa6b6a9d329bb20773b607d967f8483563f Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 11:19:32 -0800 Subject: [PATCH 44/92] Adjust path var reference Based on: https://github.com/actions/upload-artifact --- .github/workflows/github.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 1878781b..d18d1f39 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -104,7 +104,7 @@ jobs: uses: actions/upload-artifact@v3 with: name: ${{ env.ModuleArtifactName }} - path: "${{ env.GITHUB_WORKSPACE }}/${{ env.BuiltModulePath }}" + path: ${{ github.workspace }}/${{ env.BuiltModulePath }} - name: Generate Nupkg shell: pwsh @@ -186,7 +186,7 @@ jobs: uses: actions/download-artifact@v2.0.9 with: name: ${{ env.NupkgArtifactName }} - path: "${{ env.GITHUB_WORKSPACE }}/${{ env.PackageDownloadPath }}" + path: "${{ github.workspace }}/${{ env.PackageDownloadPath }}" - name: Install Module from Nupkg shell: pwsh From 458cc95298f77f56f5fd064f22650d86e9458e90 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 11:26:25 -0800 Subject: [PATCH 45/92] Adjust path var reference Based on: https://github.com/actions/upload-artifact --- .github/workflows/github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index d18d1f39..fef979bf 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -217,7 +217,7 @@ jobs: uses: MirageNet/nunit-reporter@v1.0.5 with: access-token: ${{ secrets.GITHUB_TOKEN }} - path: '$GITHUB_WORKSPACE\$TestResults' + path: '${{ github.workspace }}\$TestResults' - name: Generate Code Coverage uses: danielpalme/ReportGenerator-GitHub-Action@4.8.8 From 04bb82ed57e27a1e85a87a97768d018066a279e2 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 11:26:40 -0800 Subject: [PATCH 46/92] Remove usage of outputs and needs from build job --- .github/workflows/github.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index fef979bf..9e7c47c5 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -50,9 +50,6 @@ jobs: name: 'Build Module' runs-on: ubuntu-latest - outputs: - pester_min_version: ${{ steps.pestermin.outputs.pester_min_version }} - env: FileSystemDeploymentPath: Deploy/FileSystem BuiltModulePath: Deploy/PSKoans @@ -194,7 +191,7 @@ jobs: $PackageDownloadPath = "$env:GITHUB_WORKSPACE/$env:PackageDownloadPath" $pesterParams = @{ Name = 'Pester' - MinimumVersion = Get-Content -Path "${{ needs.build.outputs.pester_min_version }}" + MinimumVersion = Get-Content -Path $env:pester_min_version ProviderName = 'NuGet' Path = $PackageDownloadPath Force = $true @@ -207,6 +204,7 @@ jobs: GITHUB_WORKSPACE: ${{ env.GITHUB_WORKSPACE }} PackageDownloadPath: ${{ env.PackageDownloadPath }} PSRepositoryName: ${{ env.PSRepositoryName }} + pester_min_version: ${{ env.pester_min_version }} - name: Run Pester Tests shell: pwsh From 81efe4cf296aa5ae1b8a3f1a1ef1129a51c999e6 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Mon, 6 Feb 2023 11:31:50 -0800 Subject: [PATCH 47/92] Remove residual file access --- .github/workflows/github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 9e7c47c5..04389970 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -191,7 +191,7 @@ jobs: $PackageDownloadPath = "$env:GITHUB_WORKSPACE/$env:PackageDownloadPath" $pesterParams = @{ Name = 'Pester' - MinimumVersion = Get-Content -Path $env:pester_min_version + MinimumVersion = $env:pester_min_version ProviderName = 'NuGet' Path = $PackageDownloadPath Force = $true From 0c0eebb2453ea67b99349e43ce90bc23e9e3377d Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Wed, 15 Feb 2023 08:55:41 -0800 Subject: [PATCH 48/92] Revert back to caching ps modules The platyPS module needed to match case exactly --- .github/workflows/github.yml | 38 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 04389970..4c3ef090 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -67,20 +67,11 @@ jobs: Write-Output "pester_min_version=$MinimumVersion" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append Write-Host "Minimum Pester Version: $MinimumVersion" - - name: Install from PSGallery - shell: pwsh - run: | - Set-PSRepository PSGallery -InstallationPolicy Trusted - Install-Module PSDeploy, BuildHelpers, PlatyPS, EZOut - Install-Module Pester -MinimumVersion $env:pester_min_version - env: - pester_min_version: ${{ env.pester_min_version }} - - # - name: Install and cache PowerShell modules - # uses: potatoqualitee/psmodulecache@v5.2 - # with: - # modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ env.pester_min_version }}, EZOut - # shell: pwsh + - name: Install and cache PowerShell modules + uses: potatoqualitee/psmodulecache@v5.2 + with: + modules-to-cache: PSDeploy, BuildHelpers, platyPS, Pester:${{ env.pester_min_version }}, EZOut + shell: pwsh - name: Setup Environment shell: pwsh @@ -151,20 +142,11 @@ jobs: Write-Output "pester_min_version=$MinimumVersion" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append Write-Host "Minimum Pester Version: $MinimumVersion" - - name: Install from PSGallery - shell: pwsh - run: | - Set-PSRepository PSGallery -InstallationPolicy Trusted - Install-Module PSDeploy, BuildHelpers, PlatyPS, EZOut - Install-Module Pester -MinimumVersion $env:pester_min_version - env: - pester_min_version: ${{ env.pester_min_version }} - - # - name: Install and cache PowerShell modules - # uses: potatoqualitee/psmodulecache@v5.2 - # with: - # modules-to-cache: PSDeploy, BuildHelpers, PlatyPS, Pester:${{ env.pester_min_version }}, EZOut - # shell: pwsh + - name: Install and cache PowerShell modules + uses: potatoqualitee/psmodulecache@v5.2 + with: + modules-to-cache: PSDeploy, BuildHelpers, platyPS, Pester:${{ env.pester_min_version }}, EZOut + shell: pwsh - name: Setup Environment shell: pwsh From 6bb1876e03e04caed7edd4bd23e8b25f79b85b19 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Wed, 15 Feb 2023 08:57:52 -0800 Subject: [PATCH 49/92] Fix for tests executed from ModuleHelp.tests --- PSKoans/Private/Assert-UnblockedFile.ps1 | 18 ++++++++++++++++++ .../Private/ConvertFrom-WildcardPattern.ps1 | 3 +++ PSKoans/Private/Get-KoanAst.ps1 | 9 ++++++++- PSKoans/Private/Get-KoanAttribute.ps1 | 8 ++++++++ PSKoans/Private/Get-KoanIt.ps1 | 3 +++ PSKoans/Private/Invoke-Koan.ps1 | 3 +++ ...BlockTest.ps1 => Measure-KoanTestBlock.ps1} | 16 ++++++++++++++++ PSKoans/Private/New-KoanRunspace.ps1 | 1 + PSKoans/Private/New-PSKoanErrorRecord.ps1 | 3 +++ PSKoans/Private/Update-PSKoanFile.ps1 | 15 ++++----------- PSKoans/Private/Write-ConsoleLine.ps1 | 6 ++++++ 11 files changed, 73 insertions(+), 12 deletions(-) rename PSKoans/Private/{Measure-KoanBlockTest.ps1 => Measure-KoanTestBlock.ps1} (50%) diff --git a/PSKoans/Private/Assert-UnblockedFile.ps1 b/PSKoans/Private/Assert-UnblockedFile.ps1 index 00c4913e..a02f424e 100644 --- a/PSKoans/Private/Assert-UnblockedFile.ps1 +++ b/PSKoans/Private/Assert-UnblockedFile.ps1 @@ -14,9 +14,27 @@ function Assert-UnblockedFile { .PARAMETER FileInfo An instance of System.IO.FileInfo to test. + .PARAMETER PassThru + If `-PassThru` is specified, the command will emit the input path value back to the output stream. + .INPUTS System.IO.FileInfo + + .NOTES + Author: Joel Sallow (@vexx32) + .EXAMPLE + PS> Get-ChildItem -Recurse -Filter *.Koans.ps1 | Assert-UnblockedFile + If the file is not in use, nothing happens and nothing is returned. If in use, an exception is thrown. + + .EXAMPLE + PS> Get-ChildItem -Recurse -Filter *.Koans.ps1 | Assert-UnblockedFile -PassThru + Directory: C:\GitHub\PSKoans\PSKoans\Koans\Cmdlets 1 + LastWriteTime Length Name + ------------- ------ ---- + 1/29/2023 12:36:33 AM 1.22kb AboutCompareObject.Koans.ps1 + ... + The file was not in use, so no exception was thrown. Since we specified -PassThru, each FileInfo passed in is returned back to the output stream. #> [CmdletBinding()] diff --git a/PSKoans/Private/ConvertFrom-WildcardPattern.ps1 b/PSKoans/Private/ConvertFrom-WildcardPattern.ps1 index 1d65b991..0ce13b6f 100644 --- a/PSKoans/Private/ConvertFrom-WildcardPattern.ps1 +++ b/PSKoans/Private/ConvertFrom-WildcardPattern.ps1 @@ -12,6 +12,9 @@ function ConvertFrom-WildcardPattern { .PARAMETER Pattern Zero or more wildcard patterns to convert. + .NOTES + Author: Joel Sallow (@vexx32) + .EXAMPLE ConvertFrom-WildcardPattern -Pattern AboutComp*, diff --git a/PSKoans/Private/Get-KoanAst.ps1 b/PSKoans/Private/Get-KoanAst.ps1 index 5136553e..401b36c0 100644 --- a/PSKoans/Private/Get-KoanAst.ps1 +++ b/PSKoans/Private/Get-KoanAst.ps1 @@ -3,7 +3,7 @@ using namespace System.Management.Automation.Language function Get-KoanAst { <# .SYNOPSIS - Get the AST for a Koan. + Get the Abstract Syntax Tree (AST) for a Koan. .DESCRIPTION Parse the content of a Koan file into an AST. Ignores "using module" statements. @@ -11,6 +11,13 @@ function Get-KoanAst { .PARAMETER Path The path to a Koan file. + .NOTES + Author: Joel Sallow (@vexx32) + + .EXAMPLE + Get-KoanAst -Path C:\userKoanDir\Foundations\AboutArrays.Koans.ps1 + + Returns the Ast from the AboutArrays.Koans.ps1 file. #> [CmdletBinding()] diff --git a/PSKoans/Private/Get-KoanAttribute.ps1 b/PSKoans/Private/Get-KoanAttribute.ps1 index 07640c6e..cc7c3036 100644 --- a/PSKoans/Private/Get-KoanAttribute.ps1 +++ b/PSKoans/Private/Get-KoanAttribute.ps1 @@ -7,6 +7,14 @@ function Get-KoanAttribute { .DESCRIPTION Modified koan file parser that avoids "using module" statements. Semantic checks for using module include invoking "Get-Module -ListAvailable" which adds a considerable delay when parsing individual files. + .PARAMETER Path + The path to a Koan file. + .EXAMPLE + Get-KoanAttribute -Path C:\userKoanDir\Foundations\AboutArrays.Koans.ps1 + + Returns the KoanAttributeInfo from the AboutArrays.Koans.ps1 file. + .NOTES + Author: Joel Sallow (@vexx32) #> [CmdletBinding()] diff --git a/PSKoans/Private/Get-KoanIt.ps1 b/PSKoans/Private/Get-KoanIt.ps1 index 9e36cacc..0d5d2f70 100644 --- a/PSKoans/Private/Get-KoanIt.ps1 +++ b/PSKoans/Private/Get-KoanIt.ps1 @@ -11,6 +11,9 @@ function Get-KoanIt { .PARAMETER Path The path to the file to search. + .NOTES + Author: Joel Sallow (@vexx32) + .EXAMPLE Get-KoanIt -Path C:\userKoanDir\Foundations\AboutArrays.Koans.ps1 diff --git a/PSKoans/Private/Invoke-Koan.ps1 b/PSKoans/Private/Invoke-Koan.ps1 index f385ebbb..7debff3d 100644 --- a/PSKoans/Private/Invoke-Koan.ps1 +++ b/PSKoans/Private/Invoke-Koan.ps1 @@ -10,6 +10,9 @@ .PARAMETER ParameterSplat Defines the hashtable that will be splatted into Invoke-Pester in the new PowerShell instance. + .NOTES + Author: Joel Sallow (@vexx32) + .EXAMPLE Invoke-Koan @{ Script = '.\AboutArrays.Koans.ps1'; PassThru = $true; Show = 'None' } diff --git a/PSKoans/Private/Measure-KoanBlockTest.ps1 b/PSKoans/Private/Measure-KoanTestBlock.ps1 similarity index 50% rename from PSKoans/Private/Measure-KoanBlockTest.ps1 rename to PSKoans/Private/Measure-KoanTestBlock.ps1 index 7304cf91..4a85db93 100644 --- a/PSKoans/Private/Measure-KoanBlockTest.ps1 +++ b/PSKoans/Private/Measure-KoanTestBlock.ps1 @@ -1,3 +1,19 @@ +<# + .SYNOPSIS + Counts the number of tests in the given Koan block or file. + .DESCRIPTION + Recursively counts all the tests within a Koan file by counting the tests + in all the blocks of the file. + .PARAMETER Block + The block, or file, of Koans to measure. + .EXAMPLE + Measure-KoanTestBlock C:\userKoanDir\Foundations\AboutArrays.Koans.ps1 + + 16 + .NOTES + Author: Joel Sallow (@vexx32) + +#> function Measure-KoanTestBlock { [CmdletBinding()] param( diff --git a/PSKoans/Private/New-KoanRunspace.ps1 b/PSKoans/Private/New-KoanRunspace.ps1 index b39beda9..7e67ea05 100644 --- a/PSKoans/Private/New-KoanRunspace.ps1 +++ b/PSKoans/Private/New-KoanRunspace.ps1 @@ -14,6 +14,7 @@ function New-KoanRunspace { $script:KoanRunspace = New-KoanRunspace .NOTES + Author: Joel Swallow (@vexx32)) Run scripts in a new scope to avoid scope bleed wherever possible, with the `$ps.AddScript($script, $true) overload. #> [CmdletBinding()] diff --git a/PSKoans/Private/New-PSKoanErrorRecord.ps1 b/PSKoans/Private/New-PSKoanErrorRecord.ps1 index e2b7fd9a..e88df0e2 100644 --- a/PSKoans/Private/New-PSKoanErrorRecord.ps1 +++ b/PSKoans/Private/New-PSKoanErrorRecord.ps1 @@ -26,6 +26,9 @@ function New-PSKoanErrorRecord { .PARAMETER TargetObject The object or command which raised the exception, or caused the exception to be raised. + .NOTES + Author: Joel Sallow (@vexx32) + .EXAMPLE $ErrorDetails = @{ ExceptionType = 'System.IO.FileNotFoundException' diff --git a/PSKoans/Private/Update-PSKoanFile.ps1 b/PSKoans/Private/Update-PSKoanFile.ps1 index 3e4e00d0..bb6debe5 100644 --- a/PSKoans/Private/Update-PSKoanFile.ps1 +++ b/PSKoans/Private/Update-PSKoanFile.ps1 @@ -11,6 +11,9 @@ function Update-PSKoanFile { .PARAMETER Topic Updates the specified topic from the module. + .NOTES + Author: Joel Sallow (@vexx32) + .EXAMPLE Update-PSKoanFile -Topic AboutArrays @@ -24,17 +27,7 @@ function Update-PSKoanFile { [Alias('Koan', 'File')] [SupportsWildcards()] [string[]] - $Topic, - - [Parameter()] - [SupportsWildcards()] - [string[]] - $Module, - - [Parameter()] - [SupportsWildcards()] - [string[]] - $IncludeModule + $Topic ) $PSBoundParameters.Remove('Confirm') > $null diff --git a/PSKoans/Private/Write-ConsoleLine.ps1 b/PSKoans/Private/Write-ConsoleLine.ps1 index 1d88a22a..43c3d984 100644 --- a/PSKoans/Private/Write-ConsoleLine.ps1 +++ b/PSKoans/Private/Write-ConsoleLine.ps1 @@ -4,6 +4,12 @@ Writes text to the console. .DESCRIPTION Cuts text to console-appropriate widths for viewing, where possible. + .PARAMETER InputString + The text to be displayed to the console. + .PARAMETER Title + Whether the text to display is the title. + .NOTES + Author: Joel Sallow (@vexx32) .EXAMPLE Write-ConsoleLine $String From 5c3d2c3c2af7ed56d3ac71f39558bd9b045472fa Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Wed, 15 Feb 2023 08:58:41 -0800 Subject: [PATCH 50/92] Update Measure-Koan for first-time execution With using pester 5+ some of the old setup no longer works. This should fix that. --- PSKoans/Private/Measure-Koan.ps1 | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/PSKoans/Private/Measure-Koan.ps1 b/PSKoans/Private/Measure-Koan.ps1 index 3fbc7169..c51468fc 100644 --- a/PSKoans/Private/Measure-Koan.ps1 +++ b/PSKoans/Private/Measure-Koan.ps1 @@ -39,25 +39,22 @@ ) -join [System.IO.Path]::PathSeparator } process { - Write-Verbose "Discovering koans in [$($KoanInfo.Name -join '], [')]" + Write-Verbose "Discovering koans in [$($KoanInfo.Topic -join '], [')]" $Result = & (Get-Module Pester) { [CmdletBinding()] param( $Path, - $ExcludePath, $SessionState ) - - $_Pester_State_Backup = $state.PSObject.Copy() - $state.Stack = [System.Collections.Stack]@() + + $state = if($null -eq $state) { @{ Stack = [System.Collections.Stack]@() } } + $_Pester_State_Backup = if($null -ne $state.PSObject) {$state.PSObject.Copy()} try { - Reset-TestSuiteState - # to avoid Describe thinking that we run in interactive mode $invokedViaInvokePester = $true - $fileList = Find-File -Path $Path -ExcludePath $ExcludePath -Extension '.Koans.ps1' + $fileList = Find-File -Path $Path -Extension '.Koans.ps1' $containers = foreach ($file in $fileList) { New-BlockContainerObject -File (Get-Item $file) } From cff5e2611b8e46a973b1f5cf45fe9e7b9957b2d7 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Wed, 15 Feb 2023 08:58:57 -0800 Subject: [PATCH 51/92] Fix for Update-PSKoanFile.tests --- Tests/Functions/Private/Update-PSKoanFile.Tests.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/Functions/Private/Update-PSKoanFile.Tests.ps1 b/Tests/Functions/Private/Update-PSKoanFile.Tests.ps1 index 357df55b..e3a86e11 100644 --- a/Tests/Functions/Private/Update-PSKoanFile.Tests.ps1 +++ b/Tests/Functions/Private/Update-PSKoanFile.Tests.ps1 @@ -28,12 +28,6 @@ Describe 'Update-PSKoanFile' { __ | Should -Be 2 } - Context 'first' { - It 'koan 3' { - __ | Should -Be 3 - } - } - Context 'second' { It 'koan 4' { __ | Should -Be 4 @@ -56,6 +50,12 @@ Describe 'Update-PSKoanFile' { __ | Should -Be 2 } + Context 'first' { + It 'koan 3' { + __ | Should -Be 3 + } + } + Context 'second' { It 'koan 4' { 4 | Should -Be 4 From 5144398f4f27cf0cd425f4bb43c45d18e2fd3ddf Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Wed, 15 Feb 2023 08:59:57 -0800 Subject: [PATCH 52/92] Update tests to use -ModuleName As part of the upgrade to pester 5 --- Tests/Functions/Public/Get-Karma.Tests.ps1 | 20 +++++++++---------- Tests/Functions/Public/Get-PSKoan.Tests.ps1 | 4 ++++ .../Public/Get-PSKoanLocation.Tests.ps1 | 6 +++--- .../Public/Get-PSKoanSetting.Tests.ps1 | 4 ++-- .../Public/Move-PSKoanLibrary.Tests.ps1 | 16 ++++++++------- .../Public/Register-Advice.Tests.ps1 | 12 +++++------ 6 files changed, 33 insertions(+), 29 deletions(-) diff --git a/Tests/Functions/Public/Get-Karma.Tests.ps1 b/Tests/Functions/Public/Get-Karma.Tests.ps1 index 7a25cce1..ec7b66cc 100644 --- a/Tests/Functions/Public/Get-Karma.Tests.ps1 +++ b/Tests/Functions/Public/Get-Karma.Tests.ps1 @@ -23,6 +23,7 @@ Describe 'Get-Karma' { Failed = @() } } + Update-PSKoan -Confirm:$false $Result = Get-Karma } @@ -52,18 +53,19 @@ Describe 'Get-Karma' { BeforeAll { Mock 'Measure-Koan' -ModuleName 'PSKoans' - Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'User' } - Mock 'Update-PSKoan' { throw 'Prevent recursion' } - Mock 'Write-Warning' + Mock 'Update-PSKoan' -MockWith { throw 'Prevent recursion' } -ModuleName 'PSKoans' + Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'User' } -ModuleName 'PSKoans' + Mock 'Write-Warning' -ModuleName 'PSKoans' } It 'should attempt to populate koans and then recurse to reassess' { { Get-Karma } | Should -Throw -ExpectedMessage 'Prevent recursion' - Should -Invoke 'Update-PSKoan' -Scope Context + Should -Invoke 'Update-PSKoan' -Scope Context -ModuleName 'PSKoans' } It 'displays a warning before initiating a reset' { - Should -Invoke 'Write-Warning' -Scope Context + { Get-Karma } | Should -Throw + Should -Invoke 'Write-Warning' -Scope Context -ModuleName 'PSKoans' } It 'throws an error if a Topic is specified that matches nothing' { @@ -74,13 +76,13 @@ Describe 'Get-Karma' { Context 'With -ListTopics Parameter' { BeforeAll { - Mock 'Get-PSKoan' + Mock 'Get-PSKoan' -ModuleName 'PSKoans' } It 'lists all the koan topics' { Get-Karma -ListTopics - Should -Invoke 'Get-PSKoan' + Should -Invoke 'Get-PSKoan' -ModuleName 'PSKoans' } } @@ -104,10 +106,6 @@ Describe 'Get-Karma' { Context 'Behaviour When All Koans Are Completed' { BeforeAll { - Mock 'Get-PSKoanLocation' { - Join-Path -Path $TestDrive -ChildPath 'CompletedKoan' - } - Mock 'Measure-Koan' -ModuleName 'PSKoans' -MockWith { 2 } $TestFile = Join-Path -Path (Get-PSKoanLocation) -ChildPath 'Group\SelectedTopicTest.Koans.ps1' diff --git a/Tests/Functions/Public/Get-PSKoan.Tests.ps1 b/Tests/Functions/Public/Get-PSKoan.Tests.ps1 index 93bca379..8d2c3d5b 100644 --- a/Tests/Functions/Public/Get-PSKoan.Tests.ps1 +++ b/Tests/Functions/Public/Get-PSKoan.Tests.ps1 @@ -7,6 +7,10 @@ Describe 'Get-PSKoan' { Join-Path $TestDrive 'PSKoans' } + Mock 'Get-PSKoanLocation' { + Join-Path $TestDrive 'PSKoans' + } -ModuleName 'PSKoans' + Update-PSKoan -Confirm:$false # Stage test module diff --git a/Tests/Functions/Public/Get-PSKoanLocation.Tests.ps1 b/Tests/Functions/Public/Get-PSKoanLocation.Tests.ps1 index d62e5be0..e9668492 100644 --- a/Tests/Functions/Public/Get-PSKoanLocation.Tests.ps1 +++ b/Tests/Functions/Public/Get-PSKoanLocation.Tests.ps1 @@ -7,7 +7,7 @@ Describe 'Get-PSKoanLocation' { BeforeAll { Mock 'Get-PSKoanSetting' -ParameterFilter { $Name -eq 'KoanLocation' } -MockWith { '~/PSKoans' - } + } -ModuleName 'PSKoans' $Result = Get-PSKoanLocation } @@ -17,14 +17,14 @@ Describe 'Get-PSKoanLocation' { } It 'calls Get-PSKoanSetting with -Name "KoanLocation"' { - Should -Invoke 'Get-PSKoanSetting' -Scope Context + Should -Invoke 'Get-PSKoanSetting' -Scope Context -ModuleName 'PSKoans' } } Context 'No Value Available' { BeforeAll { - Mock 'Get-PSKoanSetting' -ParameterFilter { $Name -eq 'KoanLocation' } + Mock 'Get-PSKoanSetting' -ParameterFilter { $Name -eq 'KoanLocation' } -ModuleName 'PSKoans' } It 'throws an error if no value can be retrieved' { diff --git a/Tests/Functions/Public/Get-PSKoanSetting.Tests.ps1 b/Tests/Functions/Public/Get-PSKoanSetting.Tests.ps1 index e5b5e3ef..e758c532 100644 --- a/Tests/Functions/Public/Get-PSKoanSetting.Tests.ps1 +++ b/Tests/Functions/Public/Get-PSKoanSetting.Tests.ps1 @@ -22,7 +22,7 @@ Describe 'Get-PSKoanSetting' { Context 'Settings file does not exist' { BeforeAll { - Mock 'Set-PSKoanSetting' -ParameterFilter { $Settings -is [hashtable] } + Mock 'Set-PSKoanSetting' -ParameterFilter { $Settings -is [hashtable] } -ModuleName 'PSKoans' $DefaultSettings = InModuleScope 'PSKoans' { $script:DefaultSettings } } ` @@ -34,7 +34,7 @@ Describe 'Get-PSKoanSetting' { } It 'calls Set-PSKoanSetting to set the default settings' { - Should -Invoke 'Set-PSKoanSetting' -Scope Context + Should -Invoke 'Set-PSKoanSetting' -Scope Context -ModuleName 'PSKoans' } } diff --git a/Tests/Functions/Public/Move-PSKoanLibrary.Tests.ps1 b/Tests/Functions/Public/Move-PSKoanLibrary.Tests.ps1 index 4763e628..ccc75ae5 100644 --- a/Tests/Functions/Public/Move-PSKoanLibrary.Tests.ps1 +++ b/Tests/Functions/Public/Move-PSKoanLibrary.Tests.ps1 @@ -7,11 +7,13 @@ Describe 'Move-PSKoanLibrary' { BeforeAll { $OriginalPath = New-Item -Path 'TestDrive:/PSKoans' -ItemType Directory | Select-Object -ExpandProperty FullName - $TestPath = New-Item -ItemType Directory -Path 'TestDrive:/TestPath' | Join-Path -ChildPath 'Koans' + $TestPath = New-Item -ItemType Directory -Path 'TestDrive:/TestPath' | + Select-Object -ExpandProperty FullName | + Join-Path -ChildPath 'Koans' - Mock 'Get-PSKoanLocation' { $OriginalPath } - Mock 'Set-PSKoanLocation' -ParameterFilter { $Path -eq $TestPath } - Mock 'Move-Item' -ParameterFilter { $Path -eq $OriginalPath } -MockWith { $Destination } + Mock 'Get-PSKoanLocation' { $OriginalPath } -ModuleName 'PSKoans' + Mock 'Set-PSKoanLocation' -ParameterFilter { $Path -eq $TestPath } -ModuleName 'PSKoans' + Mock 'Move-Item' -ParameterFilter { $Path -eq $OriginalPath } -MockWith { $Destination } -ModuleName 'PSKoans' } It 'should output the new location' { @@ -19,15 +21,15 @@ Describe 'Move-PSKoanLibrary' { } It 'should call Get-PSKoanLocation' { - Should -Invoke 'Get-PSKoanLocation' -Scope Context + Should -Invoke 'Get-PSKoanLocation' -Scope Context -ModuleName 'PSKoans' } It 'should call Move-Item' { - Should -Invoke 'Move-Item' -Scope Context + Should -Invoke 'Move-Item' -Scope Context -ModuleName 'PSKoans' } It 'should call Set-PSKoanLocation' { - Should -Invoke 'Set-PSKoanLocation' -Scope Context + Should -Invoke 'Set-PSKoanLocation' -Scope Context -ModuleName 'PSKoans' } } diff --git a/Tests/Functions/Public/Register-Advice.Tests.ps1 b/Tests/Functions/Public/Register-Advice.Tests.ps1 index 326a1931..866cd199 100644 --- a/Tests/Functions/Public/Register-Advice.Tests.ps1 +++ b/Tests/Functions/Public/Register-Advice.Tests.ps1 @@ -5,9 +5,9 @@ Describe "Register-Advice" { Context "Profile Folder/File Missing" { BeforeAll { - Mock New-Item -Verifiable - Mock Test-Path { $false } -Verifiable - Mock Set-Content -ParameterFilter { $Value -eq "Show-Advice" } -Verifiable + Mock New-Item -Verifiable -ModuleName 'PSKoans' + Mock Test-Path { $false } -Verifiable -ModuleName 'PSKoans' + Mock Set-Content -Verifiable -ModuleName 'PSKoans' } It 'should create the $profile if it does not exist' { @@ -19,9 +19,9 @@ Describe "Register-Advice" { Context "Profile Already Exists" { BeforeAll { - Mock 'Test-Path' { $true } -Verifiable - Mock 'Select-String' { $false } -Verifiable - Mock 'Add-Content' -Verifiable + Mock 'Test-Path' { $true } -Verifiable -ModuleName 'PSKoans' + Mock 'Select-String' { $false } -Verifiable -ModuleName 'PSKoans' + Mock 'Add-Content' -Verifiable -ModuleName 'PSKoans' } It "adds content to the profile if it already exists (Get|Set)-Advice" { From eff73b2a38ca4a21351e9e17d4447c43e1a6c6c9 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Wed, 15 Feb 2023 09:18:45 -0800 Subject: [PATCH 53/92] Update tests to use ModuleName splatting --- .../Private/Get-KoanAttribute.Tests.ps1 | 11 +++--- Tests/Functions/Public/Get-Karma.Tests.ps1 | 36 ++++++++++--------- .../Public/Get-PSKoanLocation.Tests.ps1 | 11 ++++-- .../Public/Get-PSKoanSetting.Tests.ps1 | 8 +++-- .../Public/Move-PSKoanLibrary.Tests.ps1 | 17 +++++---- .../Public/Register-Advice.Tests.ps1 | 27 ++++++++------ Tests/Functions/Public/Show-Advice.Tests.ps1 | 13 ++++--- 7 files changed, 75 insertions(+), 48 deletions(-) diff --git a/Tests/Functions/Private/Get-KoanAttribute.Tests.ps1 b/Tests/Functions/Private/Get-KoanAttribute.Tests.ps1 index 2ba7d11f..1c560ead 100644 --- a/Tests/Functions/Private/Get-KoanAttribute.Tests.ps1 +++ b/Tests/Functions/Private/Get-KoanAttribute.Tests.ps1 @@ -3,6 +3,9 @@ Describe 'Get-KoanAttribute' { BeforeAll { + $module = @{ + ModuleName = 'PSKoans' + } $filePath = @{ Path = Join-Path $TestDrive -ChildPath 'AboutSomething.Koans.ps1' } @@ -11,7 +14,7 @@ Describe 'Get-KoanAttribute' { Context 'Content has no errors' { BeforeAll { - Mock 'Get-KoanAst' -ModuleName 'PSKoans' { + Mock 'Get-KoanAst' @module { { [Koan(Position = 1)] param() @@ -50,7 +53,7 @@ Describe 'Get-KoanAttribute' { Context 'Module declared' { BeforeAll { - Mock 'Get-KoanAst' -ModuleName 'PSKoans' { + Mock 'Get-KoanAst' @module { { [Koan(Position = 1, Module = 'Name')] param() @@ -80,7 +83,7 @@ Describe 'Get-KoanAttribute' { Context 'Full attribute name used' { BeforeAll { - Mock 'Get-KoanAst' -ModuleName 'PSKoans' { + Mock 'Get-KoanAst' @module { { [KoanAttribute(Position = 1)] param( ) @@ -134,7 +137,7 @@ Describe 'Get-KoanAttribute' { Context 'Attribute is missing' { BeforeAll { - Mock 'Get-KoanAst' -ModuleName 'PSKoans' { + Mock 'Get-KoanAst' @module { { param() diff --git a/Tests/Functions/Public/Get-Karma.Tests.ps1 b/Tests/Functions/Public/Get-Karma.Tests.ps1 index ec7b66cc..2ba3b291 100644 --- a/Tests/Functions/Public/Get-Karma.Tests.ps1 +++ b/Tests/Functions/Public/Get-Karma.Tests.ps1 @@ -1,8 +1,10 @@ #Requires -Modules PSKoans Describe 'Get-Karma' { - BeforeAll { + $module = @{ + ModuleName = 'PSKoans' + } $originalLocation = Get-PSKoanLocation Set-PSKoanLocation -Path (Join-Path $TestDrive -ChildPath 'PSKoans') Update-PSKoan -Confirm:$false @@ -15,8 +17,8 @@ Describe 'Get-Karma' { Context 'Default Behaviour' { BeforeAll { - Mock 'Measure-Koan' -MockWith { 4 } -ModuleName 'PSKoans' - Mock 'Invoke-Koan' -ModuleName 'PSKoans' { + Mock 'Measure-Koan' -MockWith { 4 } @module + Mock 'Invoke-Koan' @module { [PSCustomObject]@{ PassedCount = 0 FailedCount = 4 @@ -34,11 +36,11 @@ Describe 'Get-Karma' { } It 'calls Measure-Koan on each file to count koans' { - Should -Invoke 'Measure-Koan' -Scope Context -ModuleName 'PSKoans' + Should -Invoke 'Measure-Koan' -Scope Context @module } It 'calls Invoke-Koan on each topic file until it fails a test' { - Should -Invoke 'Invoke-Koan' -Times 1 -ModuleName 'PSKoans' -Scope Context + Should -Invoke 'Invoke-Koan' -Times 1 @module -Scope Context } It 'populates the $script:CurrentTopic variable' { @@ -52,20 +54,20 @@ Describe 'Get-Karma' { Context 'With Nonexistent Koans Folder / No Koans Found' { BeforeAll { - Mock 'Measure-Koan' -ModuleName 'PSKoans' - Mock 'Update-PSKoan' -MockWith { throw 'Prevent recursion' } -ModuleName 'PSKoans' - Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'User' } -ModuleName 'PSKoans' - Mock 'Write-Warning' -ModuleName 'PSKoans' + Mock 'Measure-Koan' @module + Mock 'Update-PSKoan' -MockWith { throw 'Prevent recursion' } @module + Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'User' } @module + Mock 'Write-Warning' @module } It 'should attempt to populate koans and then recurse to reassess' { { Get-Karma } | Should -Throw -ExpectedMessage 'Prevent recursion' - Should -Invoke 'Update-PSKoan' -Scope Context -ModuleName 'PSKoans' + Should -Invoke 'Update-PSKoan' -Scope Context @module } It 'displays a warning before initiating a reset' { { Get-Karma } | Should -Throw - Should -Invoke 'Write-Warning' -Scope Context -ModuleName 'PSKoans' + Should -Invoke 'Write-Warning' -Scope Context @module } It 'throws an error if a Topic is specified that matches nothing' { @@ -76,21 +78,21 @@ Describe 'Get-Karma' { Context 'With -ListTopics Parameter' { BeforeAll { - Mock 'Get-PSKoan' -ModuleName 'PSKoans' + Mock 'Get-PSKoan' @module } It 'lists all the koan topics' { Get-Karma -ListTopics - Should -Invoke 'Get-PSKoan' -ModuleName 'PSKoans' + Should -Invoke 'Get-PSKoan' @module } } Context 'With -Topic Parameter' { BeforeAll { - Mock 'Measure-Koan' -ModuleName 'PSKoans' { [int]::MaxValue } - Mock 'Invoke-Koan' -ModuleName 'PSKoans' + Mock 'Measure-Koan' @module { [int]::MaxValue } + Mock 'Invoke-Koan' @module } It 'calls Invoke-Koan on only the topics selected: ' -TestCases @( @@ -99,14 +101,14 @@ Describe 'Get-Karma' { ) { Get-Karma -Topic $Topic - Should -Invoke 'Invoke-Koan' -Times @($Topic).Count -ModuleName 'PSKoans' + Should -Invoke 'Invoke-Koan' -Times @($Topic).Count @module } } Context 'Behaviour When All Koans Are Completed' { BeforeAll { - Mock 'Measure-Koan' -ModuleName 'PSKoans' -MockWith { 2 } + Mock 'Measure-Koan' @module -MockWith { 2 } $TestFile = Join-Path -Path (Get-PSKoanLocation) -ChildPath 'Group\SelectedTopicTest.Koans.ps1' New-Item -Path (Split-Path $TestFile -Parent) -ItemType Directory -Force diff --git a/Tests/Functions/Public/Get-PSKoanLocation.Tests.ps1 b/Tests/Functions/Public/Get-PSKoanLocation.Tests.ps1 index e9668492..40d9dbb3 100644 --- a/Tests/Functions/Public/Get-PSKoanLocation.Tests.ps1 +++ b/Tests/Functions/Public/Get-PSKoanLocation.Tests.ps1 @@ -1,13 +1,18 @@ #Requires -Modules PSKoans Describe 'Get-PSKoanLocation' { + BeforeAll { + $module = @{ + ModuleName = 'PSKoans' + } + } Context 'Normal Behaviour' { BeforeAll { Mock 'Get-PSKoanSetting' -ParameterFilter { $Name -eq 'KoanLocation' } -MockWith { '~/PSKoans' - } -ModuleName 'PSKoans' + } @module $Result = Get-PSKoanLocation } @@ -17,14 +22,14 @@ Describe 'Get-PSKoanLocation' { } It 'calls Get-PSKoanSetting with -Name "KoanLocation"' { - Should -Invoke 'Get-PSKoanSetting' -Scope Context -ModuleName 'PSKoans' + Should -Invoke 'Get-PSKoanSetting' -Scope Context @module } } Context 'No Value Available' { BeforeAll { - Mock 'Get-PSKoanSetting' -ParameterFilter { $Name -eq 'KoanLocation' } -ModuleName 'PSKoans' + Mock 'Get-PSKoanSetting' -ParameterFilter { $Name -eq 'KoanLocation' } @module } It 'throws an error if no value can be retrieved' { diff --git a/Tests/Functions/Public/Get-PSKoanSetting.Tests.ps1 b/Tests/Functions/Public/Get-PSKoanSetting.Tests.ps1 index e758c532..06288589 100644 --- a/Tests/Functions/Public/Get-PSKoanSetting.Tests.ps1 +++ b/Tests/Functions/Public/Get-PSKoanSetting.Tests.ps1 @@ -3,6 +3,10 @@ Describe 'Get-PSKoanSetting' { BeforeAll { + $module = @{ + ModuleName = 'PSKoans' + } + $configFilePath = 'TestDrive:/config.json' InModuleScope 'PSKoans' -Parameters @{ Path = $configFilePath } { param($Path) @@ -22,7 +26,7 @@ Describe 'Get-PSKoanSetting' { Context 'Settings file does not exist' { BeforeAll { - Mock 'Set-PSKoanSetting' -ParameterFilter { $Settings -is [hashtable] } -ModuleName 'PSKoans' + Mock 'Set-PSKoanSetting' -ParameterFilter { $Settings -is [hashtable] } @module $DefaultSettings = InModuleScope 'PSKoans' { $script:DefaultSettings } } ` @@ -34,7 +38,7 @@ Describe 'Get-PSKoanSetting' { } It 'calls Set-PSKoanSetting to set the default settings' { - Should -Invoke 'Set-PSKoanSetting' -Scope Context -ModuleName 'PSKoans' + Should -Invoke 'Set-PSKoanSetting' -Scope Context @module } } diff --git a/Tests/Functions/Public/Move-PSKoanLibrary.Tests.ps1 b/Tests/Functions/Public/Move-PSKoanLibrary.Tests.ps1 index ccc75ae5..1aacf824 100644 --- a/Tests/Functions/Public/Move-PSKoanLibrary.Tests.ps1 +++ b/Tests/Functions/Public/Move-PSKoanLibrary.Tests.ps1 @@ -1,6 +1,11 @@ #Requires -Modules PSKoans Describe 'Move-PSKoanLibrary' { + BeforeAll { + $module = @{ + ModuleName = 'PSKoans' + } + } Context 'Unit Tests with Mocks' { @@ -11,9 +16,9 @@ Describe 'Move-PSKoanLibrary' { Select-Object -ExpandProperty FullName | Join-Path -ChildPath 'Koans' - Mock 'Get-PSKoanLocation' { $OriginalPath } -ModuleName 'PSKoans' - Mock 'Set-PSKoanLocation' -ParameterFilter { $Path -eq $TestPath } -ModuleName 'PSKoans' - Mock 'Move-Item' -ParameterFilter { $Path -eq $OriginalPath } -MockWith { $Destination } -ModuleName 'PSKoans' + Mock 'Get-PSKoanLocation' { $OriginalPath } @module + Mock 'Set-PSKoanLocation' -ParameterFilter { $Path -eq $TestPath } @module + Mock 'Move-Item' -ParameterFilter { $Path -eq $OriginalPath } -MockWith { $Destination } @module } It 'should output the new location' { @@ -21,15 +26,15 @@ Describe 'Move-PSKoanLibrary' { } It 'should call Get-PSKoanLocation' { - Should -Invoke 'Get-PSKoanLocation' -Scope Context -ModuleName 'PSKoans' + Should -Invoke 'Get-PSKoanLocation' -Scope Context @module } It 'should call Move-Item' { - Should -Invoke 'Move-Item' -Scope Context -ModuleName 'PSKoans' + Should -Invoke 'Move-Item' -Scope Context @module } It 'should call Set-PSKoanLocation' { - Should -Invoke 'Set-PSKoanLocation' -Scope Context -ModuleName 'PSKoans' + Should -Invoke 'Set-PSKoanLocation' -Scope Context @module } } diff --git a/Tests/Functions/Public/Register-Advice.Tests.ps1 b/Tests/Functions/Public/Register-Advice.Tests.ps1 index 866cd199..900745ac 100644 --- a/Tests/Functions/Public/Register-Advice.Tests.ps1 +++ b/Tests/Functions/Public/Register-Advice.Tests.ps1 @@ -1,13 +1,18 @@ #Requires -Modules PSKoans Describe "Register-Advice" { + BeforeAll { + $module = @{ + ModuleName = 'PSKoans' + } + } Context "Profile Folder/File Missing" { BeforeAll { - Mock New-Item -Verifiable -ModuleName 'PSKoans' - Mock Test-Path { $false } -Verifiable -ModuleName 'PSKoans' - Mock Set-Content -Verifiable -ModuleName 'PSKoans' + Mock New-Item @module -Verifiable + Mock Test-Path { $false } @module -Verifiable + Mock Set-Content @module -Verifiable } It 'should create the $profile if it does not exist' { @@ -19,9 +24,9 @@ Describe "Register-Advice" { Context "Profile Already Exists" { BeforeAll { - Mock 'Test-Path' { $true } -Verifiable -ModuleName 'PSKoans' - Mock 'Select-String' { $false } -Verifiable -ModuleName 'PSKoans' - Mock 'Add-Content' -Verifiable -ModuleName 'PSKoans' + Mock Test-Path { $true } @module -Verifiable + Mock Select-String { $false } @module -Verifiable + Mock Add-Content @module -Verifiable } It "adds content to the profile if it already exists (Get|Set)-Advice" { @@ -33,10 +38,10 @@ Describe "Register-Advice" { Context "Parameter Validation" { BeforeAll { - Mock Test-Path { $false } -ParameterFilter { $Path -eq $ProfileFolder } - Mock New-Item - Mock Test-Path { $false } -ParameterFilter { $Path -eq $ProfilePath } - Mock Set-Content -ParameterFilter { $Value -eq "Show-Advice" } + Mock Test-Path { $false } -ParameterFilter { $Path -eq $ProfileFolder } @module + Mock New-Item @module + Mock Test-Path { $false } -ParameterFilter { $Path -eq $ProfilePath } @module + Mock Set-Content @module } It "throws if an invalid value is supplied for -TargetProfile" { @@ -60,4 +65,4 @@ Describe "Register-Advice" { } } } -} +} \ No newline at end of file diff --git a/Tests/Functions/Public/Show-Advice.Tests.ps1 b/Tests/Functions/Public/Show-Advice.Tests.ps1 index e91fa726..b70993c1 100644 --- a/Tests/Functions/Public/Show-Advice.Tests.ps1 +++ b/Tests/Functions/Public/Show-Advice.Tests.ps1 @@ -3,7 +3,10 @@ Describe "Show-Advice" { BeforeAll { - Mock 'Write-ConsoleLine' -ModuleName 'PSKoans' + $module = @{ + ModuleName = 'PSKoans' + } + Mock 'Write-ConsoleLine' @module } Context "Behaviour of Parameter-less Calls" { @@ -13,11 +16,11 @@ Describe "Show-Advice" { } It "calls Write-ConsoleLine with Parameter -Title" { - Should -Invoke 'Write-ConsoleLine' -ModuleName 'PSKoans' -ParameterFilter { $null -eq $Title } -Scope Context + Should -Invoke 'Write-ConsoleLine' @module -ParameterFilter { $null -eq $Title } -Scope Context } It "calls Write-ConsoleLine with only the display string" { - Should -Invoke 'Write-ConsoleLine' -ModuleName 'PSKoans' -ParameterFilter { $null -ne $Title } -Scope Context + Should -Invoke 'Write-ConsoleLine' @module -ParameterFilter { $null -ne $Title } -Scope Context } It "outputs nothing to the pipeline" { @@ -32,11 +35,11 @@ Describe "Show-Advice" { } It "should call Write-ConsoleLine with normal parameters" { - Should -Invoke 'Write-ConsoleLine' -ParameterFilter { $null -ne $Title } -ModuleName 'PSKoans' -Scope Context + Should -Invoke 'Write-ConsoleLine' -ParameterFilter { $null -ne $Title } @module -Scope Context } It "should call Write-ConsoleLine without parameters" { - Should -Invoke 'Write-ConsoleLine' -ParameterFilter { $null -eq $Title } -ModuleName 'PSKoans' -Scope Context + Should -Invoke 'Write-ConsoleLine' -ParameterFilter { $null -eq $Title } @module -Scope Context } It "should throw an error if the requested file cannot be found" { From cdc448d5d42d346ebff70d74a576da06cf0c7d02 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Thu, 16 Feb 2023 22:35:19 -0800 Subject: [PATCH 54/92] Update tests to Pester v5+ Ensure new lines at EOF Update to use ModuleName where necessary All tests now pass! --- Build/Build-Module.ps1 | 2 +- PSKoans/PSKoans.format.ps1xml | 2 +- PSKoans/Public/Reset-PSKoan.ps1 | 5 +- .../Public/Register-Advice.Tests.ps1 | 2 +- Tests/Functions/Public/Reset-PSKoan.Tests.ps1 | 106 +++++++++------ .../Public/Set-PSKoanLocation.Tests.ps1 | 7 +- Tests/Functions/Public/Show-Advice.Tests.ps1 | 4 +- Tests/Functions/Public/Show-Karma.Tests.ps1 | 124 +++++++++--------- .../Functions/Public/Update-PSKoan.Tests.ps1 | 31 +++-- 9 files changed, 167 insertions(+), 116 deletions(-) diff --git a/Build/Build-Module.ps1 b/Build/Build-Module.ps1 index ff7d91d2..256e26a2 100644 --- a/Build/Build-Module.ps1 +++ b/Build/Build-Module.ps1 @@ -39,4 +39,4 @@ New-ExternalHelp -Path "$env:PROJECTROOT/docs/" -OutputPath "$env:PROJECTROOT/PS $BuiltModulePath = "$env:GITHUB_WORKSPACE/$env:BUILTMODULEPATH" Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $BuiltModulePath -Recurse -PassThru | - Where-Object { -not $_.PSIsContainer } \ No newline at end of file + Where-Object { -not $_.PSIsContainer } diff --git a/PSKoans/PSKoans.format.ps1xml b/PSKoans/PSKoans.format.ps1xml index cb351ae7..646da3fc 100644 --- a/PSKoans/PSKoans.format.ps1xml +++ b/PSKoans/PSKoans.format.ps1xml @@ -1,4 +1,4 @@ - + diff --git a/PSKoans/Public/Reset-PSKoan.ps1 b/PSKoans/Public/Reset-PSKoan.ps1 index d5705215..64c35421 100644 --- a/PSKoans/Public/Reset-PSKoan.ps1 +++ b/PSKoans/Public/Reset-PSKoan.ps1 @@ -97,7 +97,10 @@ function Reset-PSKoan { # Replace the content of the koan with the modules content. $content = $content.Remove( $_.Ast.Extent.StartOffset, - ($_.Ast.Extent.EndOffset - $_.Ast.Extent.StartOffset) + [math]::Min( + ($_.Ast.Extent.EndOffset - $_.Ast.Extent.StartOffset), + ($content.Length - $_.Ast.Extent.StartOffset) + ) ).Insert( $_.Ast.Extent.StartOffset, $ModuleItCommands[$_.ID].Ast.Extent.Text diff --git a/Tests/Functions/Public/Register-Advice.Tests.ps1 b/Tests/Functions/Public/Register-Advice.Tests.ps1 index 900745ac..2255cce7 100644 --- a/Tests/Functions/Public/Register-Advice.Tests.ps1 +++ b/Tests/Functions/Public/Register-Advice.Tests.ps1 @@ -65,4 +65,4 @@ Describe "Register-Advice" { } } } -} \ No newline at end of file +} diff --git a/Tests/Functions/Public/Reset-PSKoan.Tests.ps1 b/Tests/Functions/Public/Reset-PSKoan.Tests.ps1 index 885ab87c..8cdccd07 100644 --- a/Tests/Functions/Public/Reset-PSKoan.Tests.ps1 +++ b/Tests/Functions/Public/Reset-PSKoan.Tests.ps1 @@ -7,6 +7,14 @@ Describe Reset-PSKoan { Confirm = $false } + $module = @{ + ModuleName = 'PSKoans' + } + + Mock 'Get-PSKoanLocation' { + Join-Path -Path $TestDrive -ChildPath 'PSKoans' + } @module + Mock 'Get-PSKoanLocation' { Join-Path -Path $TestDrive -ChildPath 'PSKoans' } @@ -17,82 +25,104 @@ Describe Reset-PSKoan { Path = Join-Path -Path $TestDrive -ChildPath 'Module\Group\AboutSomething.Koans.ps1' RelativePath = 'Group\AboutSomething.Koans.ps1' } - } + } @module - New-Item -Path (Join-Path -Path $TestDrive -ChildPath 'Module\Group') -ItemType Directory - New-Item -Path (Join-Path -Path $TestDrive -ChildPath 'PSKoans\Group') -ItemType Directory + New-Item -Path (Join-Path -Path $TestDrive -ChildPath 'Module\Group') -ItemType Directory -Force + New-Item -Path (Join-Path -Path $TestDrive -ChildPath 'PSKoans\Group') -ItemType Directory -Force $userFilePath = Get-PSKoanLocation | Join-Path -ChildPath 'Group\AboutSomething.Koans.ps1' - Set-Content -Path (Get-PSKoan -Scope Module).Path, $userFilePath -Value @' - using module PSKoans - [Koan(Position = 1)] - param ( ) + Set-Content -Path $userFilePath -Value @' + #using module PSKoans + [Koan(Position = 1)] + param ( ) + + Describe 'AboutSomething' { + It 'reset content' { + __ | Should -Be 2 + } - Describe 'AboutSomething' { - It 'existing content' { - __ | Should -Be 1 + Context 'first' { + It 'nested reset content' { + __ | Should -Be 3 } + } - It 'reset content' { - __ | Should -Be 2 + Context 'second' { + It 'nested reset content' { + __ | Should -Be 4 } + } + } +'@ + Set-Content -Path (Join-Path -Path $TestDrive -ChildPath 'Module\Group\AboutSomething.Koans.ps1') -Value @' + #using module PSKoans + [Koan(Position = 1)] + param ( ) + + Describe 'AboutSomething' { + It 'existing content' { + __ | Should -Be 1 + } - Context 'first' { - It 'nested reset content' { - __ | Should -Be 3 - } + It 'reset content' { + __ | Should -Be 2 + } + + Context 'first' { + It 'nested reset content' { + __ | Should -Be 3 } + } - Context 'second' { - It 'nested reset content' { - __ | Should -Be 4 - } + Context 'second' { + It 'nested reset content' { + __ | Should -Be 4 } } + } '@ } Context 'User file exists, It block exists' { BeforeAll { - Mock 'Set-Content' - Mock 'Copy-Item' + Mock 'Set-Content' @module + Mock 'Copy-Item' @module } It 'updates an existing user file when -Name is supplied' { - Reset-PSKoan -Name 'existing content' @defaultParams + Reset-PSKoan -Name 'reset content' @defaultParams - Should -Invoke 'Set-Content' -Times 1 - Should -Invoke 'Copy-Item' -Times 0 + Should -Invoke 'Set-Content' -Times 1 @module + Should -Invoke 'Copy-Item' -Times 0 @module } It 'updates an existing user file when -Context is supplied' { Reset-PSKoan -Context 'first' @defaultParams - Should -Invoke 'Set-Content' -Times 1 -Exactly - Should -Invoke 'Copy-Item' -Times 0 + Should -Invoke 'Set-Content' -Times 1 -Exactly @module + Should -Invoke 'Copy-Item' -Times 0 @module } It 'updates an existing user file when -Name and -Context are supplied' { Reset-PSKoan -Name 'nested reset content' -Context 'first' @defaultParams - Should -Invoke 'Set-Content' -Times 1 -Exactly - Should -Invoke 'Copy-Item' -Times 0 + Should -Invoke 'Set-Content' -Times 1 -Exactly @module + Should -Invoke 'Copy-Item' -Times 0 @module } It 'copies a koan file from the module when -Name and -Context are not supplied' { Reset-PSKoan @defaultParams - Should -Invoke 'Set-Content' -Times 0 - Should -Invoke 'Copy-Item' -Times 1 -Exactly + Should -Invoke 'Set-Content' -Times 0 @module + Should -Invoke 'Copy-Item' -Times 1 -Exactly @module } } Context 'User file exists, It block does not exist' { It 'writes a non-terminating error when the user file does not include the specified Koan' { - Mock 'Get-KoanIt' -ParameterFilter { $Path -match 'PSKoans' } -Module 'PSKoans' { Reset-PSKoan -Topic AboutSomething -Name 'existing content' -ErrorAction Stop @defaultParams } | Should -Throw -ErrorId 'PSKoans.UserItNotFound,Reset-PSKoan' @@ -104,7 +134,7 @@ Describe Reset-PSKoan { BeforeAll { New-Item "$TestDrive/DoesNotExist.Koans.ps1" -ItemType File > $null - Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'User' } -Verifiable + Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'User' } -Verifiable @module Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'Module' } -Verifiable -MockWith { [PSCustomObject]@{ Topic = $Topic @@ -114,30 +144,30 @@ Describe Reset-PSKoan { RelativePath = 'DoesNotExist.Koans.ps1' PSTypeName = 'PSKoans.KoanInfo' } - } + } @module - Mock 'Update-PSKoan' + Mock 'Update-PSKoan' @module } It 'calls Update-PSKoan when the topic does not exist in the user location' { Reset-PSKoan -Topic DoesNotExist -ErrorAction Stop @defaultParams Should -InvokeVerifiable - Should -Invoke Update-PSKoan -Times 1 -Exactly + Should -Invoke Update-PSKoan -Times 1 -Exactly @module } } Context 'Module file does not exist' { BeforeAll { - Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'Module' } + Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'Module' } @module } It 'throws a terminating error when no topics are found in the module' { { Reset-PSKoan -Topic DoesNotExist @defaultParams } | Should -Throw -ErrorId 'PSKoans.ModuleTopicNotFound,Reset-PSKoan' - Should -Invoke 'Get-PSKoan' -Times 1 -Exactly + Should -Invoke 'Get-PSKoan' -Times 1 -Exactly @module } } diff --git a/Tests/Functions/Public/Set-PSKoanLocation.Tests.ps1 b/Tests/Functions/Public/Set-PSKoanLocation.Tests.ps1 index cac34f90..d64d2221 100644 --- a/Tests/Functions/Public/Set-PSKoanLocation.Tests.ps1 +++ b/Tests/Functions/Public/Set-PSKoanLocation.Tests.ps1 @@ -3,7 +3,10 @@ Describe 'Set-PSKoanLocation' { BeforeAll { - Mock 'Set-PSKoanSetting' -ParameterFilter { $Name -eq 'KoanLocation' } + $module = @{ + ModuleName = 'PSKoans' + } + Mock 'Set-PSKoanSetting' -ParameterFilter { $Name -eq 'KoanLocation' } @module } It 'outputs no data by default' { @@ -11,7 +14,7 @@ Describe 'Set-PSKoanLocation' { } It 'sets the KoanLocation setting' { - Should -Invoke 'Set-PSKoanSetting' -Scope Describe + Should -Invoke 'Set-PSKoanSetting' -Scope Describe @module } It 'returns the input -Path value back to the pipeline with -PassThru' { diff --git a/Tests/Functions/Public/Show-Advice.Tests.ps1 b/Tests/Functions/Public/Show-Advice.Tests.ps1 index b70993c1..78d5bb84 100644 --- a/Tests/Functions/Public/Show-Advice.Tests.ps1 +++ b/Tests/Functions/Public/Show-Advice.Tests.ps1 @@ -53,8 +53,8 @@ Describe "Show-Advice" { BeforeAll { $GetContentResult = [string]::Empty - Mock Get-Content -MockWith { $GetContentResult } -Verifiable - Mock Get-ChildItem -MockWith { [PSCustomObject]@{ PSPath = "DummyPath" } } -Verifiable + Mock Get-Content -MockWith { $GetContentResult } -Verifiable @module + Mock Get-ChildItem -MockWith { [PSCustomObject]@{ PSPath = "DummyPath" } } -Verifiable @module } It "should throw an error if the requested file's format is not correct" -TestCases @( diff --git a/Tests/Functions/Public/Show-Karma.Tests.ps1 b/Tests/Functions/Public/Show-Karma.Tests.ps1 index f0bd6fb8..f24afdfe 100644 --- a/Tests/Functions/Public/Show-Karma.Tests.ps1 +++ b/Tests/Functions/Public/Show-Karma.Tests.ps1 @@ -3,6 +3,12 @@ Describe 'Show-Karma' { BeforeAll { + $module = @{ + ModuleName = 'PSKoans' + } + Mock 'Get-PSKoanLocation' { + "$TestDrive/Koans" + } @module Mock 'Get-PSKoanLocation' { "$TestDrive/Koans" } @@ -19,7 +25,7 @@ Describe 'Show-Karma' { Context 'Default Behaviour' { BeforeAll { - Mock 'Out-Host' + Mock 'Out-Host' @module Mock 'Get-Karma' { [PSCustomObject]@{ PSTypeName = 'PSKoans.Result' @@ -36,7 +42,7 @@ Describe 'Show-Karma' { CurrentLine = 1 } } - } + } @module } It 'should not produce output' { @@ -44,18 +50,18 @@ Describe 'Show-Karma' { } It 'should write the formatted output to host' { - Should -Invoke 'Out-Host' -Scope Context + Should -Invoke 'Out-Host' -Scope Context @module } It 'should call Get-Karma to examine the koans' { - Should -Invoke 'Get-Karma' -Scope Context + Should -Invoke 'Get-Karma' -Scope Context @module } } Context 'With All Koans Completed' { BeforeAll { - Mock 'Out-Host' -Verifiable + Mock 'Out-Host' -Verifiable @module Mock 'Get-Karma' -Verifiable { [PSCustomObject]@{ PSTypeName = 'PSKoans.CompleteResult' @@ -64,7 +70,7 @@ Describe 'Show-Karma' { RequestedTopci = $null Complete = $true } - } + } @module } It 'should not throw errors' { @@ -76,8 +82,8 @@ Describe 'Show-Karma' { Context 'With -ClearScreen Switch' { BeforeAll { - Mock 'Clear-Host' - Mock 'Out-Host' + Mock 'Clear-Host' @module + Mock 'Out-Host' @module Mock 'Get-Karma' { [PSCustomObject]@{ PSTypeName = 'PSKoans.Result' @@ -94,7 +100,7 @@ Describe 'Show-Karma' { CurrentLine = 1 } } - } + } @module } It 'should not produce output' { @@ -102,28 +108,28 @@ Describe 'Show-Karma' { } It 'should clear the screen' { - Should -Invoke 'Clear-Host' -Scope Context -Times 1 -Exactly + Should -Invoke 'Clear-Host' -Scope Context -Times 1 -Exactly @module } It 'should display the rendered output' { - Should -Invoke 'Out-Host' -Scope Context + Should -Invoke 'Out-Host' -Scope Context @module } It 'should use Get-Karma to retrieve koan results' { - Should -Invoke 'Get-Karma' -Scope Context -Times 1 -Exactly + Should -Invoke 'Get-Karma' -Scope Context -Times 1 -Exactly @module } } Context 'With Nonexistent Koans Folder / No Koans Found' { BeforeAll { - Mock 'Write-Host' - Mock 'Get-PSKoan' - Mock 'Update-PSKoan' { throw 'Prevent recursion' } - Mock 'Write-Warning' - Mock 'Test-Path' { $false } - Mock 'Invoke-Item' - Mock 'Measure-Koan' -ModuleName 'PSKoans' + Mock 'Write-Host' @module + Mock 'Get-PSKoan' @module + Mock 'Update-PSKoan' { throw 'Prevent recursion' } @module + Mock 'Write-Warning' @module + Mock 'Test-Path' { $false } @module + Mock 'Invoke-Item' @module + Mock 'Measure-Koan' @module } BeforeEach { @@ -135,7 +141,7 @@ Describe 'Show-Karma' { } It 'should display a warning before initiating a reset' { - Should -Invoke 'Write-Warning' -Scope Context -Times 1 -Exactly + Should -Invoke 'Write-Warning' -Scope Context -Times 1 -Exactly @module } It 'throws an error if a Topic is specified that matches nothing' { @@ -145,34 +151,34 @@ Describe 'Show-Karma' { It 'should create PSKoans directory with -Library' { { Show-Karma -Library } | Should -Throw -ExpectedMessage 'Prevent recursion' - Should -Invoke 'Test-Path' - Should -Invoke 'Update-PSKoan' -Times 1 -Exactly + Should -Invoke 'Test-Path' @module + Should -Invoke 'Update-PSKoan' -Times 1 -Exactly @module } It 'should call Get-PSKoan to retrieve the correct file -Contemplate' { { Show-Karma -Contemplate } | Should -Throw -ExpectedMessage 'Prevent recursion' - Should -Invoke 'Get-PSKoan' -Times 1 -Exactly - Should -Invoke 'Update-PSKoan' -Times 1 -Exactly + Should -Invoke 'Get-PSKoan' -Times 1 -Exactly @module + Should -Invoke 'Update-PSKoan' -Times 1 -Exactly @module } } Context 'With -ListTopics Parameter' { BeforeAll { - Mock 'Get-PSKoan' + Mock 'Get-PSKoan' @module } It 'should list all the koan topics' { Show-Karma -ListTopics - Should -Invoke 'Get-PSKoan' -Times 1 -Exactly + Should -Invoke 'Get-PSKoan' -Times 1 -Exactly @module } } Context 'With -Topic Parameter' { BeforeAll { - Mock 'Out-Host' -Verifiable + Mock 'Out-Host' -Verifiable @module Mock 'Get-Karma' -ParameterFilter { $Topic -eq 'TestTopic' } -Verifiable -MockWith { [PSCustomObject]@{ PSTypeName = 'PSKoans.Result' @@ -190,7 +196,7 @@ Describe 'Show-Karma' { } RequestedTopic = $Topic } - } + } @module } It 'should call Get-Karma on the selected topic' { @@ -202,8 +208,8 @@ Describe 'Show-Karma' { Context 'With All Koans in a Single Topic Completed' { BeforeAll { - Mock 'Format-Custom' -Verifiable { $null } - Mock 'Out-Host' -Verifiable + Mock 'Format-Custom' -Verifiable { $null } @module + Mock 'Out-Host' -Verifiable @module Mock 'Get-Karma' -Verifiable { [PSCustomObject]@{ PSTypeName = 'PSKoans.CompleteResult' @@ -212,7 +218,7 @@ Describe 'Show-Karma' { RequestedTopic = 'TestTopic' Complete = $true } - } + } @module } It 'should not throw errors' { @@ -226,12 +232,12 @@ Describe 'Show-Karma' { BeforeAll { $TestFile = New-TemporaryFile - Mock 'Invoke-Item' { $Path } - Mock 'Get-Command' { $true } -ParameterFilter { $Name -ne "missing_editor" } - Mock 'Get-Command' { $false } -ParameterFilter { $Name -eq "missing_editor" } + Mock 'Invoke-Item' { $Path } @module + Mock 'Get-Command' { $true } -ParameterFilter { $Name -ne "missing_editor" } @module + Mock 'Get-Command' { $false } -ParameterFilter { $Name -eq "missing_editor" } @module Mock 'Start-Process' { @{ Editor = $FilePath; Arguments = $ArgumentList; NoNewWindow = $NoNewWindow } - } + } @module Mock 'Get-Karma' { $currentTopic = @{ @@ -256,11 +262,11 @@ Describe 'Show-Karma' { param($Topic) $script:CurrentTopic = $Topic } - } + } @module Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'User' } { [PSCustomObject]@{ Path = $TestFile.FullName } - } + } @module } AfterAll { @@ -281,8 +287,8 @@ Describe 'Show-Karma' { $Path = ($Result.Arguments[1] -split '(?<="):')[0] -replace '"' $Path | Should -BeExactly (Resolve-Path -Path $Path).Path - Should -Invoke 'Get-Command' -Times 1 -Exactly - Should -Invoke 'Start-Process' -Times 1 -Exactly + Should -Invoke 'Get-Command' -Times 1 -Exactly @module + Should -Invoke 'Start-Process' -Times 1 -Exactly @module InModuleScope 'PSKoans' { $script:CurrentTopic } | Should -BeNullOrEmpty } @@ -306,10 +312,10 @@ Describe 'Show-Karma' { $Path = ($Result.Arguments[1] -split '(?<="):')[0] -replace '"' $Path | Should -BeExactly (Resolve-Path -Path $Path).Path - Should -Invoke 'Get-Command' -Times 1 -Exactly - Should -Invoke 'Start-Process' -Times 1 -Exactly - Should -Invoke 'Get-Karma' -ParameterFilter { $Module -eq $ModuleName } - Should -Invoke 'Get-PSKoan' -ParameterFilter { $IncludeModule -eq $ModuleName } + Should -Invoke 'Get-Command' -Times 1 -Exactly @module + Should -Invoke 'Start-Process' -Times 1 -Exactly @module + Should -Invoke 'Get-Karma' -ParameterFilter { $Module -eq $ModuleName } @module + Should -Invoke 'Get-PSKoan' -ParameterFilter { $IncludeModule -eq $ModuleName } @module InModuleScope 'PSKoans' { $script:CurrentTopic } | Should -BeNullOrEmpty } @@ -320,8 +326,8 @@ Describe 'Show-Karma' { $Result = Show-Karma -Contemplate -Topic TestTopic $Result.Arguments[1] | Should -MatchExactly ([regex]::Escape($TestFile.FullName)) - Should -Invoke 'Get-Command' -Times 1 -Exactly - Should -Invoke 'Start-Process' -Times 1 -Exactly + Should -Invoke 'Get-Command' -Times 1 -Exactly @module + Should -Invoke 'Start-Process' -Times 1 -Exactly @module InModuleScope 'PSKoans' { $script:CurrentTopic } | Should -BeNullOrEmpty } @@ -337,8 +343,8 @@ Describe 'Show-Karma' { $Path = $Result.Arguments -replace '"' $Path | Should -BeExactly (Resolve-Path -Path $Path).Path - Should -Invoke 'Get-Command' -Times 1 -Exactly - Should -Invoke 'Start-Process' -Times 1 -Exactly + Should -Invoke 'Get-Command' -Times 1 -Exactly @module + Should -Invoke 'Start-Process' -Times 1 -Exactly @module InModuleScope 'PSKoans' { $script:CurrentTopic } | Should -BeNullOrEmpty } @@ -348,8 +354,8 @@ Describe 'Show-Karma' { Show-Karma -Contemplate | Should -BeExactly $TestFile.FullName - Should -Invoke 'Get-Command' -Times 1 -Exactly -ParameterFilter { $Name -eq "missing_editor" } - Should -Invoke 'Invoke-Item' -Times 1 -Exactly + Should -Invoke 'Get-Command' -Times 1 -Exactly -ParameterFilter { $Name -eq "missing_editor" } @module + Should -Invoke 'Invoke-Item' -Times 1 -Exactly @module InModuleScope 'PSKoans' { $script:CurrentTopic } | Should -BeNullOrEmpty } @@ -358,12 +364,12 @@ Describe 'Show-Karma' { Context 'With -Library Switch' { BeforeAll { - Mock 'Get-Command' { $true } -ParameterFilter { $Name -ne "missing_editor" } - Mock 'Get-Command' { $false } -ParameterFilter { $Name -eq "missing_editor" } + Mock 'Get-Command' { $true } -ParameterFilter { $Name -ne "missing_editor" } @module + Mock 'Get-Command' { $false } -ParameterFilter { $Name -eq "missing_editor" } @module Mock 'Start-Process' { @{ Editor = $FilePath; Arguments = $ArgumentList } - } - Mock 'Invoke-Item' { $Path } + } @module + Mock 'Invoke-Item' { $Path } @module } It 'invokes VS Code with "code" set as Editor with proper arguments' { @@ -376,8 +382,8 @@ Describe 'Show-Karma' { $Path = $Result.Arguments -replace '"' $Path | Should -BeExactly (Resolve-Path -Path $Path).Path - Should -Invoke 'Get-Command' -Times 1 -Exactly - Should -Invoke 'Start-Process' -Times 1 -Exactly + Should -Invoke 'Get-Command' -Times 1 -Exactly @module + Should -Invoke 'Start-Process' -Times 1 -Exactly @module } It 'invokes the set editor with unknown editor chosen' { @@ -390,8 +396,8 @@ Describe 'Show-Karma' { $Path = $Result.Arguments -replace '"' $Path | Should -BeExactly (Resolve-Path -Path $Path).Path - Should -Invoke 'Get-Command' -Times 1 -Exactly - Should -Invoke 'Start-Process' -Times 1 -Exactly + Should -Invoke 'Get-Command' -Times 1 -Exactly @module + Should -Invoke 'Start-Process' -Times 1 -Exactly @module } It 'opens the file directly when selected editor is unavailable' { @@ -399,8 +405,8 @@ Describe 'Show-Karma' { Show-Karma -Library | Should -BeExactly (Get-PSKoanLocation) - Should -Invoke 'Get-Command' -Times 1 -Exactly -ParameterFilter { $Name -eq "missing_editor" } - Should -Invoke 'Invoke-Item' -Times 1 -Exactly + Should -Invoke 'Get-Command' -Times 1 -Exactly -ParameterFilter { $Name -eq "missing_editor" } @module + Should -Invoke 'Invoke-Item' -Times 1 -Exactly @module } } } diff --git a/Tests/Functions/Public/Update-PSKoan.Tests.ps1 b/Tests/Functions/Public/Update-PSKoan.Tests.ps1 index d86cf7f2..f0fe4955 100644 --- a/Tests/Functions/Public/Update-PSKoan.Tests.ps1 +++ b/Tests/Functions/Public/Update-PSKoan.Tests.ps1 @@ -2,14 +2,20 @@ Describe 'Update-PSKoan' { + BeforeAll { + $module = @{ + ModuleName = 'PSKoans' + } + } + Context 'Mocked Commands' { BeforeAll { - Mock 'Remove-Item' - Mock 'Copy-Item' - Mock 'New-Item' - Mock 'Move-Item' - Mock 'Update-PSKoanFile' -ModuleName 'PSKoans' + Mock 'Remove-Item' @module + Mock 'Copy-Item' @module + Mock 'New-Item' @module + Mock 'Move-Item' @module + Mock 'Update-PSKoanFile' @module Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'Module' } -MockWith { [PSCustomObject]@{ @@ -24,7 +30,7 @@ Describe 'Update-PSKoan' { Topic = 'Existing' Path = 'Module\Group\AboutSomethingExisting.Koans.ps1' } - } + } @module Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'User' } -MockWith { [PSCustomObject]@{ @@ -39,7 +45,7 @@ Describe 'Update-PSKoan' { Topic = 'Existing' Path = 'Module\Group\AboutSomethingExisting.Koans.ps1' } - } + } @module } It 'should not produce output' { @@ -47,19 +53,19 @@ Describe 'Update-PSKoan' { } It 'should copy missing topic files' { - Should -Invoke 'Copy-Item' -Times 1 -Scope Context + Should -Invoke 'Copy-Item' -Times 1 -Scope Context @module } It 'should move incorrectly placed topics' { - Should -Invoke 'Remove-Item' -Times 1 -Scope Context + Should -Invoke 'Remove-Item' -Times 1 -Scope Context @module } It 'should remove discarded topics' { - Should -Invoke 'Remove-Item' -Times 1 -Scope Context + Should -Invoke 'Remove-Item' -Times 1 -Scope Context @module } It 'should update topics which exist in module and koan path' { - Should -Invoke 'Update-PSKoanFile' -ModuleName 'PSKoans' -Times 2 -Scope Context + Should -Invoke 'Update-PSKoanFile' @module -Times 2 -Scope Context } } @@ -69,6 +75,9 @@ Describe 'Update-PSKoan' { Mock 'Get-PSKoanLocation' { Join-Path -Path $TestDrive -ChildPath 'PSKoans' } + Mock 'Get-PSKoanLocation' { + Join-Path -Path $TestDrive -ChildPath 'PSKoans' + } @module New-Item -Path (Get-PSKoanLocation) -ItemType Directory Update-PSKoan -Confirm:$false From 3ff95b488b79de2dfb1bd055f2712d30528221c6 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Thu, 16 Feb 2023 22:46:48 -0800 Subject: [PATCH 55/92] Update Invoke-Pester to v5 syntax --- Build/Invoke-ModuleTests.ps1 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Build/Invoke-ModuleTests.ps1 b/Build/Invoke-ModuleTests.ps1 index 70fe1c36..c272a7c3 100644 --- a/Build/Invoke-ModuleTests.ps1 +++ b/Build/Invoke-ModuleTests.ps1 @@ -12,7 +12,18 @@ Write-Host $Lines try { # Try/Finally required since -CI will exit with exit code on failure. - Invoke-Pester -Path "$env:PROJECTROOT" -CI -Output Normal + $config = New-PesterConfiguration + + $config.Run.Path = "$env:PROJECTROOT" + $config.Run.Exit = $true + + $config.TestResult.Enabled = $true + + $config.Output.Verbosity = "Normal" + + $config.CodeCoverage.Enabled = $true + + Invoke-Pester -Configuration $config } finally { $Timestamp = Get-Date -Format "yyyyMMdd-hhmmss" From 52961af935edaaa15684c525136a2b97be241972 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Thu, 16 Feb 2023 23:41:22 -0800 Subject: [PATCH 56/92] Update Test steps Bump to latest versions Correct environment variable access --- .github/workflows/github.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 4c3ef090..999b50c8 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -194,17 +194,17 @@ jobs: - name: Publish Test Results if: ${{ always() }} - uses: MirageNet/nunit-reporter@v1.0.5 + uses: MirageNet/nunit-reporter@v1.1 with: access-token: ${{ secrets.GITHUB_TOKEN }} - path: '${{ github.workspace }}\$TestResults' + path: '${{ github.workspace }}\$env:TestResults' - name: Generate Code Coverage - uses: danielpalme/ReportGenerator-GitHub-Action@4.8.8 + uses: danielpalme/ReportGenerator-GitHub-Action@5 with: - reports: '$env:GITHUB_WORKSPACE\$CodeCoverageFile' + reports: '$env:GITHUB_WORKSPACE\$env:CodeCoverageFile' targetdir: '$env:GITHUB_WORKSPACE\coveragereports' - sourcedirs: $SourceFolders + sourcedirs: '$env:SourceFolders' title: PSKoans Code Coverage - name: Publish Code Coverage artifacts From 264ed7b945c25c316da9ee8622b6110b2f29e028 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Thu, 16 Feb 2023 23:46:46 -0800 Subject: [PATCH 57/92] Adjust nunit report version --- .github/workflows/github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 999b50c8..fad927b3 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -194,7 +194,7 @@ jobs: - name: Publish Test Results if: ${{ always() }} - uses: MirageNet/nunit-reporter@v1.1 + uses: MirageNet/nunit-reporter@v1 with: access-token: ${{ secrets.GITHUB_TOKEN }} path: '${{ github.workspace }}\$env:TestResults' From 4cc08ea767291216e898344380c12f4c1ceb8616 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Thu, 16 Feb 2023 23:49:10 -0800 Subject: [PATCH 58/92] Specify exact action versions --- .github/workflows/github.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index fad927b3..24ebca09 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -194,13 +194,13 @@ jobs: - name: Publish Test Results if: ${{ always() }} - uses: MirageNet/nunit-reporter@v1 + uses: MirageNet/nunit-reporter@v1.1.0 with: access-token: ${{ secrets.GITHUB_TOKEN }} path: '${{ github.workspace }}\$env:TestResults' - name: Generate Code Coverage - uses: danielpalme/ReportGenerator-GitHub-Action@5 + uses: danielpalme/ReportGenerator-GitHub-Action@5.1.17 with: reports: '$env:GITHUB_WORKSPACE\$env:CodeCoverageFile' targetdir: '$env:GITHUB_WORKSPACE\coveragereports' From 2cd21e9846a459a621d9d9d8264eb05a7dbf61b6 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Fri, 17 Feb 2023 13:20:02 -0800 Subject: [PATCH 59/92] Small change to location variable for test files Also added the generated coverage and test results files to the ignore. --- .github/workflows/github.yml | 2 +- .gitignore | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 24ebca09..e4a1a205 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -197,7 +197,7 @@ jobs: uses: MirageNet/nunit-reporter@v1.1.0 with: access-token: ${{ secrets.GITHUB_TOKEN }} - path: '${{ github.workspace }}\$env:TestResults' + path: '$env:GITHUB_WORKSPACE\$env:TestResults' - name: Generate Code Coverage uses: danielpalme/ReportGenerator-GitHub-Action@5.1.17 diff --git a/.gitignore b/.gitignore index d69e534e..885c5c9c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ PSKoans.psproj PSKoans/*/PSKoans-help.xml +coverage.xml +testResults.xml From 43e69b6d5ebbff0839818bfb9d501cffbb145ca3 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Fri, 17 Feb 2023 13:56:09 -0800 Subject: [PATCH 60/92] Fix environment variable naming --- Build/Invoke-ModuleTests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Build/Invoke-ModuleTests.ps1 b/Build/Invoke-ModuleTests.ps1 index c272a7c3..9f65dda0 100644 --- a/Build/Invoke-ModuleTests.ps1 +++ b/Build/Invoke-ModuleTests.ps1 @@ -51,10 +51,10 @@ finally { } elseif ($GithubActions) { @( - "TestResults=$TestFile" + "TestFile=$ " "CodeCoverageFile=$CodeCoverageFile" - "SourceFolders=$ModuleFolders" - ) | Add-Content -Path $env:GITHUB_ENV + "ModuleFolders=$ModuleFolders" + ) | Out-File -FilePath $env:GITHUB_ENV -Encoding -utf8 -Append Move-Item -Path './testResults.xml' -Destination "$env:GITHUB_WORKSPACE/$TestFile" Move-Item -Path './coverage.xml' -Destination "$env:GITHUB_WORKSPACE/$CodeCoverageFile" From 83e1d7e602e6e2acd305d8bde4a3e0ac75fd8af4 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Fri, 17 Feb 2023 14:20:35 -0800 Subject: [PATCH 61/92] Replace missing var Also revert output change --- Build/Invoke-ModuleTests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Build/Invoke-ModuleTests.ps1 b/Build/Invoke-ModuleTests.ps1 index 9f65dda0..755aa299 100644 --- a/Build/Invoke-ModuleTests.ps1 +++ b/Build/Invoke-ModuleTests.ps1 @@ -51,10 +51,10 @@ finally { } elseif ($GithubActions) { @( - "TestFile=$ " + "TestFile=$TestFile" "CodeCoverageFile=$CodeCoverageFile" "ModuleFolders=$ModuleFolders" - ) | Out-File -FilePath $env:GITHUB_ENV -Encoding -utf8 -Append + ) | Add-Content -Path $env:GITHUB_ENV Move-Item -Path './testResults.xml' -Destination "$env:GITHUB_WORKSPACE/$TestFile" Move-Item -Path './coverage.xml' -Destination "$env:GITHUB_WORKSPACE/$CodeCoverageFile" From 71677234c7ac759da355ce1c13d4f83d75e1e566 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Fri, 17 Feb 2023 16:21:29 -0800 Subject: [PATCH 62/92] Try switching to different test reporter --- .github/workflows/github.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index e4a1a205..3144bcea 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -194,10 +194,11 @@ jobs: - name: Publish Test Results if: ${{ always() }} - uses: MirageNet/nunit-reporter@v1.1.0 + uses: dorny/test-reporter@v1.6.0 with: - access-token: ${{ secrets.GITHUB_TOKEN }} + name: Pester Tests path: '$env:GITHUB_WORKSPACE\$env:TestResults' + reporter: dotnet-trx - name: Generate Code Coverage uses: danielpalme/ReportGenerator-GitHub-Action@5.1.17 From 356c8bc232c524068abaa90f3c8842ea8a56226f Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Fri, 17 Feb 2023 17:03:07 -0800 Subject: [PATCH 63/92] Move publish test results to publish job Based heavily on the information here: https://github.com/marketplace/actions/publish-test-results#use-with-matrix-strategy --- .github/workflows/github.yml | 53 ++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 3144bcea..b31a6510 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -192,31 +192,20 @@ jobs: shell: pwsh run: ./Build/Invoke-ModuleTests.ps1 - - name: Publish Test Results - if: ${{ always() }} - uses: dorny/test-reporter@v1.6.0 - with: - name: Pester Tests - path: '$env:GITHUB_WORKSPACE\$env:TestResults' - reporter: dotnet-trx - - - name: Generate Code Coverage - uses: danielpalme/ReportGenerator-GitHub-Action@5.1.17 - with: - reports: '$env:GITHUB_WORKSPACE\$env:CodeCoverageFile' - targetdir: '$env:GITHUB_WORKSPACE\coveragereports' - sourcedirs: '$env:SourceFolders' - title: PSKoans Code Coverage - - - name: Publish Code Coverage artifacts - uses: actions/upload-artifact@v2.2.3 + - name: Upload Test Results + if: always() + uses: actions/upload-artifact@v2 with: - name: 'Code Coverage Reports' - path: '$env:GITHUB_WORKSPACE\coveragereports' + name: Test Results for ${{ matrix.os }} + path: $env:GITHUB_WORKSPACE\$env:TestResults + + publish: needs: test if: ${{ success() && startsWith( 'refs/tags/', github.ref ) }} + permissions: + checks: write runs-on: ubuntu-latest @@ -229,6 +218,30 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Download Test Artifacts + uses: actions/download-artifact@v2 + with: + path: artifacts + + - name: Publish Test Results + uses: EnricoMi/public-unit-test-result-action@v2.4.1 + with: + files: "artifacts/**/*TestResults.xml" + + - name: Generate Code Coverage + uses: danielpalme/ReportGenerator-GitHub-Action@5.1.17 + with: + reports: '$env:GITHUB_WORKSPACE\$env:CodeCoverageFile' + targetdir: '$env:GITHUB_WORKSPACE\coveragereports' + sourcedirs: '$env:SourceFolders' + title: PSKoans Code Coverage + + - name: Publish Code Coverage artifacts + uses: actions/upload-artifact@v2.2.3 + with: + name: 'Code Coverage Reports' + path: '$env:GITHUB_WORKSPACE\coveragereports' + - name: Download Module Artifact uses: actions/download-artifact@v2.0.9 with: From 4db86ba48203496c35ce58f826ed6a4a4763df81 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Fri, 17 Feb 2023 17:28:32 -0800 Subject: [PATCH 64/92] Fix variables in pipeline Accidentally using powershell syntax instead of github actions --- .github/workflows/github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index b31a6510..c1542fa7 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -197,7 +197,7 @@ jobs: uses: actions/upload-artifact@v2 with: name: Test Results for ${{ matrix.os }} - path: $env:GITHUB_WORKSPACE\$env:TestResults + path: ${{env.GITHUB_WORKSPACE}}\${{env.TestResults}} From d45e00e5d4388c7d519bbfb001568781265ac4e0 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Fri, 17 Feb 2023 18:15:35 -0800 Subject: [PATCH 65/92] Update upload artifact to v3 --- .github/workflows/github.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index c1542fa7..26b486b7 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -194,7 +194,7 @@ jobs: - name: Upload Test Results if: always() - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: Test Results for ${{ matrix.os }} path: ${{env.GITHUB_WORKSPACE}}\${{env.TestResults}} @@ -237,7 +237,7 @@ jobs: title: PSKoans Code Coverage - name: Publish Code Coverage artifacts - uses: actions/upload-artifact@v2.2.3 + uses: actions/upload-artifact@v3 with: name: 'Code Coverage Reports' path: '$env:GITHUB_WORKSPACE\coveragereports' From 913275370c318885c202f34987412bd3d80501df Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Fri, 17 Feb 2023 20:48:32 -0800 Subject: [PATCH 66/92] Fix artifact name Also corrects all remaining variable references --- .github/workflows/github.yml | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 26b486b7..f755c9ec 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -196,7 +196,7 @@ jobs: if: always() uses: actions/upload-artifact@v3 with: - name: Test Results for ${{ matrix.os }} + name: ${{matrix.os}}Test-Results path: ${{env.GITHUB_WORKSPACE}}\${{env.TestResults}} @@ -210,8 +210,8 @@ jobs: runs-on: ubuntu-latest env: - BuiltModulePath: '$env:GITHUB_WORKSPACE/Deploy/PSKoans' - GalleryDeploymentPath: '$env:GITHUB_WORKSPACE/Deploy/PSGallery' + BuiltModulePath: '${{env.GITHUB_WORKSPACE}}/Deploy/PSKoans' + GalleryDeploymentPath: '${{env.GITHUB_WORKSPACE}}/Deploy/PSGallery' # This variable must be set by the script TagName: '' @@ -231,26 +231,27 @@ jobs: - name: Generate Code Coverage uses: danielpalme/ReportGenerator-GitHub-Action@5.1.17 with: - reports: '$env:GITHUB_WORKSPACE\$env:CodeCoverageFile' - targetdir: '$env:GITHUB_WORKSPACE\coveragereports' - sourcedirs: '$env:SourceFolders' + reports: '${{env.GITHUB_WORKSPACE}}\${{env.CodeCoverageFile}}' + targetdir: '${{env.GITHUB_WORKSPACE}}\coveragereports' + sourcedirs: '${{env.SourceFolders}}' title: PSKoans Code Coverage - name: Publish Code Coverage artifacts uses: actions/upload-artifact@v3 with: name: 'Code Coverage Reports' - path: '$env:GITHUB_WORKSPACE\coveragereports' + path: '${{env.GITHUB_WORKSPACE}}\coveragereports' - name: Download Module Artifact - uses: actions/download-artifact@v2.0.9 + uses: actions/download-artifact@v2 with: - name: $ModuleArtifactName - path: $BuiltModulePath + name: ${{env.ModuleArtifactName}} + path: ${{env.BuiltModulePath}} - name: Deploy Module to PSGallery shell: pwsh - run: ./Deploy/Publish.ps1 -ApiKey '${{ secrets.PSGALLERYAPIKEY }}' -Path '${{ env.GalleryDeploymentPath }}' + run: | + ./Deploy/Publish.ps1 -ApiKey '${{ secrets.PSGALLERYAPIKEY }}' -Path '${{ env.GalleryDeploymentPath }}' - name: Set Release Tag Name shell: pwsh @@ -259,13 +260,13 @@ jobs: "TagName=$tagname" | Add-Content -Path '${{ github.env }}' - name: Download Artifacts - uses: actions/download-artifact@v2.0.9 + uses: actions/download-artifact@v2 with: - path: '$env:GITHUB_WORKSPACE/artifacts' + path: '${{env.GITHUB_WORKSPACE}}/artifacts' - name: Update Release with Artifacts & Changelog uses: Roang-zero1/github-create-release-action@v2.1.0 with: - created_tag: $TagName - changelog_file: '$env:GITHUB_WORKSPACE/artifacts/Changelog.md' - release_title: 'PSKoans Release $TagName' + created_tag: ${{env.TagName}} + changelog_file: '${{env.GITHUB_WORKSPACE}}/artifacts/Changelog.md' + release_title: 'PSKoans Release ${{env.TagName}}' From 26365da265c0a621eea1b71b1355db8060584b43 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Fri, 17 Feb 2023 20:52:17 -0800 Subject: [PATCH 67/92] Switch to use github.workspace for any non-powershell workspace ref --- .github/workflows/github.yml | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index f755c9ec..708eb8ef 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -31,7 +31,7 @@ jobs: runs-on: ubuntu-latest env: - FilePath: '$env:GITHUB_WORKSPACE/Changelog.md' + FilePath: '${{github.workspace}}/Changelog.md' steps: - uses: actions/checkout@v3 @@ -86,7 +86,7 @@ jobs: env: PROJECTROOT: ${{ env.PROJECTROOT }} BUILTMODULEPATH: ${{ env.BuiltModulePath }} - GITHUB_WORKSPACE: ${{ env.GITHUB_WORKSPACE }} + GITHUB_WORKSPACE: ${{github.workspace}} - name: Upload Module Artifact uses: actions/upload-artifact@v3 @@ -101,7 +101,7 @@ jobs: ./Build/Register-FileSystemRepository.ps1 -Path $FileSystemDeploymentPath -Name 'FileSystem' ./Deploy/Publish.ps1 -Key 'filesystem' -Path $FileSystemDeploymentPath -OutputDirectory $FileSystemDeploymentPath env: - GITHUB_WORKSPACE: ${{ env.GITHUB_WORKSPACE}} + GITHUB_WORKSPACE: ${{github.workspace}} FileSystemDeploymentPath: ${{ env.FileSystemDeploymentPath }} - name: Upload Nupkg Artifact @@ -158,7 +158,7 @@ jobs: $PackageDownloadPath = "$env:GITHUB_WORKSPACE/$env:PackageDownloadPath" ./Build/Register-FileSystemRepository.ps1 -Path $PackageDownloadPath -Name ${{ env.PSRepositoryName }} env: - GITHUB_WORKSPACE: ${{ env.GITHUB_WORKSPACE }} + GITHUB_WORKSPACE: ${{github.workspace}} PackageDownloadPath: ${{ env.PackageDownloadPath }} - name: Download Module Nupkg @@ -183,7 +183,7 @@ jobs: Save-Package @pesterParams | Select-Object -Property Name, Version, Status, Source Install-Module PSKoans -Repository $env:PSRepositoryName -Force -Scope CurrentUser env: - GITHUB_WORKSPACE: ${{ env.GITHUB_WORKSPACE }} + GITHUB_WORKSPACE: ${{github.workspace}} PackageDownloadPath: ${{ env.PackageDownloadPath }} PSRepositoryName: ${{ env.PSRepositoryName }} pester_min_version: ${{ env.pester_min_version }} @@ -197,10 +197,8 @@ jobs: uses: actions/upload-artifact@v3 with: name: ${{matrix.os}}Test-Results - path: ${{env.GITHUB_WORKSPACE}}\${{env.TestResults}} - - - + path: ${{github.workspace}}\${{env.TestResults}} + publish: needs: test if: ${{ success() && startsWith( 'refs/tags/', github.ref ) }} @@ -210,8 +208,8 @@ jobs: runs-on: ubuntu-latest env: - BuiltModulePath: '${{env.GITHUB_WORKSPACE}}/Deploy/PSKoans' - GalleryDeploymentPath: '${{env.GITHUB_WORKSPACE}}/Deploy/PSGallery' + BuiltModulePath: '${{github.workspace}}/Deploy/PSKoans' + GalleryDeploymentPath: '${{github.workspace}}/Deploy/PSGallery' # This variable must be set by the script TagName: '' @@ -231,8 +229,8 @@ jobs: - name: Generate Code Coverage uses: danielpalme/ReportGenerator-GitHub-Action@5.1.17 with: - reports: '${{env.GITHUB_WORKSPACE}}\${{env.CodeCoverageFile}}' - targetdir: '${{env.GITHUB_WORKSPACE}}\coveragereports' + reports: '${{github.workspace}}\${{env.CodeCoverageFile}}' + targetdir: '${{github.workspace}}\coveragereports' sourcedirs: '${{env.SourceFolders}}' title: PSKoans Code Coverage @@ -240,7 +238,7 @@ jobs: uses: actions/upload-artifact@v3 with: name: 'Code Coverage Reports' - path: '${{env.GITHUB_WORKSPACE}}\coveragereports' + path: '${{github.workspace}}\coveragereports' - name: Download Module Artifact uses: actions/download-artifact@v2 @@ -262,11 +260,11 @@ jobs: - name: Download Artifacts uses: actions/download-artifact@v2 with: - path: '${{env.GITHUB_WORKSPACE}}/artifacts' + path: '${{github.workspace}}/artifacts' - name: Update Release with Artifacts & Changelog uses: Roang-zero1/github-create-release-action@v2.1.0 with: created_tag: ${{env.TagName}} - changelog_file: '${{env.GITHUB_WORKSPACE}}/artifacts/Changelog.md' + changelog_file: '${{github.workspace}}/artifacts/Changelog.md' release_title: 'PSKoans Release ${{env.TagName}}' From 1f9de59ad79f0266262aba886fc7ad78dc938642 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Fri, 17 Feb 2023 21:36:01 -0800 Subject: [PATCH 68/92] Move test reporting to its own job Fix test results path so the entire workspace is not packaged Upload code coverage results revert publish job to as it was --- .github/workflows/github.yml | 47 +++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 708eb8ef..54a219a1 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -196,26 +196,24 @@ jobs: if: always() uses: actions/upload-artifact@v3 with: - name: ${{matrix.os}}Test-Results - path: ${{github.workspace}}\${{env.TestResults}} + name: ${{matrix.os}}-Test-Results + path: ${{github.workspace}}/${{env.TestFile}} + + - name: Upload Coverage Results + if: always() + uses: actions/upload-artifact@v3 + with: + name: ${{matrix.os}}-Test-Results + path: ${{github.workspace}}/${{env.CodeCoverageFile}} - publish: + report-tests: needs: test - if: ${{ success() && startsWith( 'refs/tags/', github.ref ) }} + if: always() + runs-on: ubuntu-latest permissions: checks: write - - runs-on: ubuntu-latest - - env: - BuiltModulePath: '${{github.workspace}}/Deploy/PSKoans' - GalleryDeploymentPath: '${{github.workspace}}/Deploy/PSGallery' - # This variable must be set by the script - TagName: '' - + steps: - - uses: actions/checkout@v3 - - name: Download Test Artifacts uses: actions/download-artifact@v2 with: @@ -229,7 +227,7 @@ jobs: - name: Generate Code Coverage uses: danielpalme/ReportGenerator-GitHub-Action@5.1.17 with: - reports: '${{github.workspace}}\${{env.CodeCoverageFile}}' + reports: 'artifacts/**/*coverage.xml' targetdir: '${{github.workspace}}\coveragereports' sourcedirs: '${{env.SourceFolders}}' title: PSKoans Code Coverage @@ -237,9 +235,24 @@ jobs: - name: Publish Code Coverage artifacts uses: actions/upload-artifact@v3 with: - name: 'Code Coverage Reports' + name: 'CodeCoverageReport' path: '${{github.workspace}}\coveragereports' + + publish: + needs: test + if: ${{ success() && startsWith( 'refs/tags/', github.ref ) }} + runs-on: ubuntu-latest + + env: + BuiltModulePath: '${{github.workspace}}/Deploy/PSKoans' + GalleryDeploymentPath: '${{github.workspace}}/Deploy/PSGallery' + # This variable must be set by the script + TagName: '' + + steps: + - uses: actions/checkout@v3 + - name: Download Module Artifact uses: actions/download-artifact@v2 with: From 202651b67394ccfc2e2a41acd0e68a1c52a862aa Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Fri, 17 Feb 2023 22:18:30 -0800 Subject: [PATCH 69/92] Fix typo in action name --- .github/workflows/github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 54a219a1..1fe7942f 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -220,7 +220,7 @@ jobs: path: artifacts - name: Publish Test Results - uses: EnricoMi/public-unit-test-result-action@v2.4.1 + uses: EnricoMi/publish-unit-test-result-action@v2.4.1 with: files: "artifacts/**/*TestResults.xml" From f0dd08c22c4db4bd512d37a07922467b916bc781 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Fri, 17 Feb 2023 23:15:24 -0800 Subject: [PATCH 70/92] Change CI to better support test results Based on https://github.com/EnricoMi/publish-unit-test-result-action/blob/v2.4.1/README.md#github-action-to-publish-test-results Also add new workflow to support this --- .github/workflows/github.yml | 28 ++++++++++----- .github/workflows/unit-test-results.yml | 45 +++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/unit-test-results.yml diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 1fe7942f..dffffdd5 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -199,6 +199,13 @@ jobs: name: ${{matrix.os}}-Test-Results path: ${{github.workspace}}/${{env.TestFile}} + - name: Upload Test Results + if: always() + uses: actions/upload-artifact@v3 + with: + name: ${{matrix.os}}-Test-Results + path: ${{ github.event_path }} + - name: Upload Coverage Results if: always() uses: actions/upload-artifact@v3 @@ -214,21 +221,18 @@ jobs: checks: write steps: + - uses: actions/checkout@v3 + - name: Download Test Artifacts uses: actions/download-artifact@v2 with: path: artifacts - - name: Publish Test Results - uses: EnricoMi/publish-unit-test-result-action@v2.4.1 - with: - files: "artifacts/**/*TestResults.xml" - - name: Generate Code Coverage uses: danielpalme/ReportGenerator-GitHub-Action@5.1.17 with: reports: 'artifacts/**/*coverage.xml' - targetdir: '${{github.workspace}}\coveragereports' + targetdir: '${{github.workspace}}/coveragereports' sourcedirs: '${{env.SourceFolders}}' title: PSKoans Code Coverage @@ -236,9 +240,17 @@ jobs: uses: actions/upload-artifact@v3 with: name: 'CodeCoverageReport' - path: '${{github.workspace}}\coveragereports' + path: '${{github.workspace}}/coveragereports' - + event_file: + runs-on: ubuntu-latest + steps: + - name: Upload Event File + uses: action/upload-artifact@v3 + with: + name: Event File + path: ${{ github.event_path }} + publish: needs: test if: ${{ success() && startsWith( 'refs/tags/', github.ref ) }} diff --git a/.github/workflows/unit-test-results.yml b/.github/workflows/unit-test-results.yml new file mode 100644 index 00000000..151d16b7 --- /dev/null +++ b/.github/workflows/unit-test-results.yml @@ -0,0 +1,45 @@ +name: Unit Test Results + +on: + workflow_run: + workflows: ["PSKoans CI"] + types: + - completed + +permissions: {} + +jobs: + unit-test-results: + runs-on: ubuntu-latest + if: github.event.workflow_run.conclusion != 'skipped' + + permissions: + checks: write + actions: read + + steps: + # This is done in bash based on https://github.com/EnricoMi/publish-unit-test-result-action/blob/v2.4.1/README.md#support-fork-repositories-and-dependabot-branches + # preferably, this would be in a pwsh shell, but I cannot translate this from bash --> pwsh + - name: Download and Extract Artifacts + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + run: | + mkdir -p artifacts && cd artifacts + + artifacts_url=${{ github.event.workflow_run.artifacts_url }} + + gh api --paginate "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact + do + IFS=$'\t' read name url <<< "$artifact" + gh api $url > "$name.zip" + unzip -d "$name" "$name.zip" + done + + - name: Publish Test Results + uses: EnricoMi/publish-unit-test-result-action@v2.4.1 + with: + comment_mode: off + commit: ${{ github.event.workflow_run.head_sha }} + event_file: artifacts/Event File/event.json + event_name: ${{ github.event.workflow_run.event }} + files: "artifacts/**/*TestResults.xml" \ No newline at end of file From 82fb5ac29afc7cc2ff29b86d48f70a902616f1d8 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Fri, 17 Feb 2023 23:27:18 -0800 Subject: [PATCH 71/92] Fix action typo --- .github/workflows/github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index dffffdd5..61ebe037 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -246,7 +246,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Upload Event File - uses: action/upload-artifact@v3 + uses: actions/upload-artifact@v3 with: name: Event File path: ${{ github.event_path }} From aa33ffe3cd67db195e00b36eb87fd4cdf7ef989e Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sat, 18 Feb 2023 00:14:29 -0800 Subject: [PATCH 72/92] Use correct source folder --- .github/workflows/github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 61ebe037..945d802a 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -233,7 +233,7 @@ jobs: with: reports: 'artifacts/**/*coverage.xml' targetdir: '${{github.workspace}}/coveragereports' - sourcedirs: '${{env.SourceFolders}}' + sourcedirs: '${{env.ModuleFolders}}' title: PSKoans Code Coverage - name: Publish Code Coverage artifacts From ec1ec3c07447654ba66fcfde10c31f59ace72fb4 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sat, 18 Feb 2023 08:13:38 -0800 Subject: [PATCH 73/92] Revert to original test result reporting May still be a good idea to update to a non-deprecated action for publishing test results --- .github/workflows/github.yml | 115 +++++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 47 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 945d802a..12c01cbb 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -192,64 +192,85 @@ jobs: shell: pwsh run: ./Build/Invoke-ModuleTests.ps1 - - name: Upload Test Results + - name: Publish Test Results if: always() - uses: actions/upload-artifact@v3 + uses: MirageNet/nunit-reporter@v1.0.5 with: - name: ${{matrix.os}}-Test-Results - path: ${{github.workspace}}/${{env.TestFile}} - - - name: Upload Test Results - if: always() - uses: actions/upload-artifact@v3 + access-token: ${{ secrets.GITHUB_TOKEN }} + path: '${{github.workspace}}\${{env.TestFile}}' + + - name: Generate Code Coverage + uses: danielpalme/ReportGenerator-GitHub-Action@4.8.8 with: - name: ${{matrix.os}}-Test-Results - path: ${{ github.event_path }} - - - name: Upload Coverage Results - if: always() + reports: '${{github.workspace}}\${{env.CodeCoverageFile}}' + targetdir: '${{github.workspace}}\coveragereports' + sourcedirs: ${{env.ModuleFolders}} + title: PSKoans Code Coverage + + - name: Publish Code Coverage artifacts uses: actions/upload-artifact@v3 with: - name: ${{matrix.os}}-Test-Results - path: ${{github.workspace}}/${{env.CodeCoverageFile}} + name: 'Code Coverage Reports' + path: '${{github.workspace}}\coveragereports' + + # - name: Upload Test Results + # if: always() + # uses: actions/upload-artifact@v3 + # with: + # name: ${{matrix.os}}-Test-Results + # path: ${{github.workspace}}/${{env.TestFile}} + + # - name: Upload Test Results + # if: always() + # uses: actions/upload-artifact@v3 + # with: + # name: ${{matrix.os}}-Test-Results + # path: ${{ github.event_path }} + + # - name: Upload Coverage Results + # if: always() + # uses: actions/upload-artifact@v3 + # with: + # name: ${{matrix.os}}-Test-Results + # path: ${{github.workspace}}/${{env.CodeCoverageFile}} - report-tests: - needs: test - if: always() - runs-on: ubuntu-latest - permissions: - checks: write + # report-tests: + # needs: test + # if: always() + # runs-on: ubuntu-latest + # permissions: + # checks: write - steps: - - uses: actions/checkout@v3 + # steps: + # - uses: actions/checkout@v3 - - name: Download Test Artifacts - uses: actions/download-artifact@v2 - with: - path: artifacts + # - name: Download Test Artifacts + # uses: actions/download-artifact@v2 + # with: + # path: artifacts - - name: Generate Code Coverage - uses: danielpalme/ReportGenerator-GitHub-Action@5.1.17 - with: - reports: 'artifacts/**/*coverage.xml' - targetdir: '${{github.workspace}}/coveragereports' - sourcedirs: '${{env.ModuleFolders}}' - title: PSKoans Code Coverage + # - name: Generate Code Coverage + # uses: danielpalme/ReportGenerator-GitHub-Action@5.1.17 + # with: + # reports: 'artifacts/**/*coverage.xml' + # targetdir: '${{github.workspace}}/coveragereports' + # sourcedirs: '${{env.ModuleFolders}}' + # title: PSKoans Code Coverage - - name: Publish Code Coverage artifacts - uses: actions/upload-artifact@v3 - with: - name: 'CodeCoverageReport' - path: '${{github.workspace}}/coveragereports' + # - name: Publish Code Coverage artifacts + # uses: actions/upload-artifact@v3 + # with: + # name: 'CodeCoverageReport' + # path: '${{github.workspace}}/coveragereports' - event_file: - runs-on: ubuntu-latest - steps: - - name: Upload Event File - uses: actions/upload-artifact@v3 - with: - name: Event File - path: ${{ github.event_path }} + # event_file: + # runs-on: ubuntu-latest + # steps: + # - name: Upload Event File + # uses: actions/upload-artifact@v3 + # with: + # name: Event File + # path: ${{ github.event_path }} publish: needs: test From 405b8fb22ec2457189b65fb682522e2e28911138 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sat, 18 Feb 2023 08:50:33 -0800 Subject: [PATCH 74/92] Update to latest of MirageNet --- .github/workflows/github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 12c01cbb..fbcf67c2 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -194,7 +194,7 @@ jobs: - name: Publish Test Results if: always() - uses: MirageNet/nunit-reporter@v1.0.5 + uses: MirageNet/nunit-reporter@v1.1.0 with: access-token: ${{ secrets.GITHUB_TOKEN }} path: '${{github.workspace}}\${{env.TestFile}}' From 81020ba5429f6a280804c4b27d08e9f46b481dc2 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sat, 18 Feb 2023 11:27:06 -0800 Subject: [PATCH 75/92] Revert "Update to latest of MirageNet" This reverts commit 405b8fb22ec2457189b65fb682522e2e28911138. --- .github/workflows/github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index fbcf67c2..12c01cbb 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -194,7 +194,7 @@ jobs: - name: Publish Test Results if: always() - uses: MirageNet/nunit-reporter@v1.1.0 + uses: MirageNet/nunit-reporter@v1.0.5 with: access-token: ${{ secrets.GITHUB_TOKEN }} path: '${{github.workspace}}\${{env.TestFile}}' From f6c153fc4fb4411a97cf1dc9f0fdc17429839664 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sat, 18 Feb 2023 11:27:10 -0800 Subject: [PATCH 76/92] Revert "Revert to original test result reporting" This reverts commit ec1ec3c07447654ba66fcfde10c31f59ace72fb4. --- .github/workflows/github.yml | 115 ++++++++++++++--------------------- 1 file changed, 47 insertions(+), 68 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 12c01cbb..945d802a 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -192,85 +192,64 @@ jobs: shell: pwsh run: ./Build/Invoke-ModuleTests.ps1 - - name: Publish Test Results + - name: Upload Test Results if: always() - uses: MirageNet/nunit-reporter@v1.0.5 - with: - access-token: ${{ secrets.GITHUB_TOKEN }} - path: '${{github.workspace}}\${{env.TestFile}}' - - - name: Generate Code Coverage - uses: danielpalme/ReportGenerator-GitHub-Action@4.8.8 - with: - reports: '${{github.workspace}}\${{env.CodeCoverageFile}}' - targetdir: '${{github.workspace}}\coveragereports' - sourcedirs: ${{env.ModuleFolders}} - title: PSKoans Code Coverage - - - name: Publish Code Coverage artifacts uses: actions/upload-artifact@v3 with: - name: 'Code Coverage Reports' - path: '${{github.workspace}}\coveragereports' - - # - name: Upload Test Results - # if: always() - # uses: actions/upload-artifact@v3 - # with: - # name: ${{matrix.os}}-Test-Results - # path: ${{github.workspace}}/${{env.TestFile}} + name: ${{matrix.os}}-Test-Results + path: ${{github.workspace}}/${{env.TestFile}} - # - name: Upload Test Results - # if: always() - # uses: actions/upload-artifact@v3 - # with: - # name: ${{matrix.os}}-Test-Results - # path: ${{ github.event_path }} + - name: Upload Test Results + if: always() + uses: actions/upload-artifact@v3 + with: + name: ${{matrix.os}}-Test-Results + path: ${{ github.event_path }} - # - name: Upload Coverage Results - # if: always() - # uses: actions/upload-artifact@v3 - # with: - # name: ${{matrix.os}}-Test-Results - # path: ${{github.workspace}}/${{env.CodeCoverageFile}} + - name: Upload Coverage Results + if: always() + uses: actions/upload-artifact@v3 + with: + name: ${{matrix.os}}-Test-Results + path: ${{github.workspace}}/${{env.CodeCoverageFile}} - # report-tests: - # needs: test - # if: always() - # runs-on: ubuntu-latest - # permissions: - # checks: write + report-tests: + needs: test + if: always() + runs-on: ubuntu-latest + permissions: + checks: write - # steps: - # - uses: actions/checkout@v3 + steps: + - uses: actions/checkout@v3 - # - name: Download Test Artifacts - # uses: actions/download-artifact@v2 - # with: - # path: artifacts + - name: Download Test Artifacts + uses: actions/download-artifact@v2 + with: + path: artifacts - # - name: Generate Code Coverage - # uses: danielpalme/ReportGenerator-GitHub-Action@5.1.17 - # with: - # reports: 'artifacts/**/*coverage.xml' - # targetdir: '${{github.workspace}}/coveragereports' - # sourcedirs: '${{env.ModuleFolders}}' - # title: PSKoans Code Coverage + - name: Generate Code Coverage + uses: danielpalme/ReportGenerator-GitHub-Action@5.1.17 + with: + reports: 'artifacts/**/*coverage.xml' + targetdir: '${{github.workspace}}/coveragereports' + sourcedirs: '${{env.ModuleFolders}}' + title: PSKoans Code Coverage - # - name: Publish Code Coverage artifacts - # uses: actions/upload-artifact@v3 - # with: - # name: 'CodeCoverageReport' - # path: '${{github.workspace}}/coveragereports' + - name: Publish Code Coverage artifacts + uses: actions/upload-artifact@v3 + with: + name: 'CodeCoverageReport' + path: '${{github.workspace}}/coveragereports' - # event_file: - # runs-on: ubuntu-latest - # steps: - # - name: Upload Event File - # uses: actions/upload-artifact@v3 - # with: - # name: Event File - # path: ${{ github.event_path }} + event_file: + runs-on: ubuntu-latest + steps: + - name: Upload Event File + uses: actions/upload-artifact@v3 + with: + name: Event File + path: ${{ github.event_path }} publish: needs: test From 69d700a01e0976b8a828b6a67e86fc934893335c Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sat, 18 Feb 2023 16:02:06 -0800 Subject: [PATCH 77/92] Fix to give Code Coverage access to files --- .github/workflows/github.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 945d802a..c4d107e9 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -192,14 +192,14 @@ jobs: shell: pwsh run: ./Build/Invoke-ModuleTests.ps1 - - name: Upload Test Results + - name: Upload Test Results (package) if: always() uses: actions/upload-artifact@v3 with: name: ${{matrix.os}}-Test-Results path: ${{github.workspace}}/${{env.TestFile}} - - name: Upload Test Results + - name: Upload Test Results (event) if: always() uses: actions/upload-artifact@v3 with: @@ -233,7 +233,7 @@ jobs: with: reports: 'artifacts/**/*coverage.xml' targetdir: '${{github.workspace}}/coveragereports' - sourcedirs: '${{env.ModuleFolders}}' + sourcedirs: 'artifacts/PSKoans' title: PSKoans Code Coverage - name: Publish Code Coverage artifacts From 41efda7e4a0a5e6bf5d2644be44c1397a4c58652 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sat, 18 Feb 2023 18:29:39 -0800 Subject: [PATCH 78/92] Fix naming collision Also try to output code coverage results for extra information (why does code coverage state 0% when it should currently be around 8%?) --- .github/workflows/github.yml | 11 ++--------- Build/Invoke-ModuleTests.ps1 | 5 ++++- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index c4d107e9..3b50f1c2 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -192,25 +192,18 @@ jobs: shell: pwsh run: ./Build/Invoke-ModuleTests.ps1 - - name: Upload Test Results (package) + - name: Upload Test Results if: always() uses: actions/upload-artifact@v3 with: name: ${{matrix.os}}-Test-Results path: ${{github.workspace}}/${{env.TestFile}} - - name: Upload Test Results (event) - if: always() - uses: actions/upload-artifact@v3 - with: - name: ${{matrix.os}}-Test-Results - path: ${{ github.event_path }} - - name: Upload Coverage Results if: always() uses: actions/upload-artifact@v3 with: - name: ${{matrix.os}}-Test-Results + name: ${{matrix.os}}-Coverage-Results path: ${{github.workspace}}/${{env.CodeCoverageFile}} report-tests: diff --git a/Build/Invoke-ModuleTests.ps1 b/Build/Invoke-ModuleTests.ps1 index 755aa299..08298e89 100644 --- a/Build/Invoke-ModuleTests.ps1 +++ b/Build/Invoke-ModuleTests.ps1 @@ -16,6 +16,7 @@ try { $config.Run.Path = "$env:PROJECTROOT" $config.Run.Exit = $true + $config.Run.PassThru = $true $config.TestResult.Enabled = $true @@ -23,7 +24,9 @@ try { $config.CodeCoverage.Enabled = $true - Invoke-Pester -Configuration $config + $pesterResults = Invoke-Pester -Configuration $config + $pesterResults + $pesterResults.CodeCoverage } finally { $Timestamp = Get-Date -Format "yyyyMMdd-hhmmss" From f33e55f008475a0eaaeccabe35caa0977efb8a45 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sat, 18 Feb 2023 21:00:55 -0800 Subject: [PATCH 79/92] Add CodeCoverage Path Also remove passthru and adjust output to detailed --- Build/Invoke-ModuleTests.ps1 | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Build/Invoke-ModuleTests.ps1 b/Build/Invoke-ModuleTests.ps1 index 08298e89..71373d4f 100644 --- a/Build/Invoke-ModuleTests.ps1 +++ b/Build/Invoke-ModuleTests.ps1 @@ -16,17 +16,15 @@ try { $config.Run.Path = "$env:PROJECTROOT" $config.Run.Exit = $true - $config.Run.PassThru = $true $config.TestResult.Enabled = $true - $config.Output.Verbosity = "Normal" + $config.Output.Verbosity = "Detailed" $config.CodeCoverage.Enabled = $true + $config.CodeCoverage.Path = "$env:PROJECTROOT" - $pesterResults = Invoke-Pester -Configuration $config - $pesterResults - $pesterResults.CodeCoverage + Invoke-Pester -Configuration $config } finally { $Timestamp = Get-Date -Format "yyyyMMdd-hhmmss" From 6e233a7912bc79559f6df66c5354d1704c75f566 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sat, 18 Feb 2023 21:41:55 -0800 Subject: [PATCH 80/92] Specify folders for Invoke-Pester Just the Tests folder for where to run from Just the PSKoans folder for where the source files are. --- Build/Invoke-ModuleTests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Build/Invoke-ModuleTests.ps1 b/Build/Invoke-ModuleTests.ps1 index 71373d4f..8bdde8c6 100644 --- a/Build/Invoke-ModuleTests.ps1 +++ b/Build/Invoke-ModuleTests.ps1 @@ -14,7 +14,7 @@ try { # Try/Finally required since -CI will exit with exit code on failure. $config = New-PesterConfiguration - $config.Run.Path = "$env:PROJECTROOT" + $config.Run.Path = "$env:PROJECTROOT\Tests" $config.Run.Exit = $true $config.TestResult.Enabled = $true @@ -22,7 +22,7 @@ try { $config.Output.Verbosity = "Detailed" $config.CodeCoverage.Enabled = $true - $config.CodeCoverage.Path = "$env:PROJECTROOT" + $config.CodeCoverage.Path = "$env:PROJECTROOT\PSKoans" Invoke-Pester -Configuration $config } From 7b684a501d75484248aa8cf60b33f82dec4a5b5c Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sat, 18 Feb 2023 21:50:26 -0800 Subject: [PATCH 81/92] Adjust Folder structure This should allow Code Coverage to more directly link tests to their respective files Also chang the variable in the KoanValidation tests to actually print --- Tests/KoanValidation.Tests.ps1 | 8 +- .../Private/Assert-UnblockedFile.Tests.ps1 | 0 .../Invoke-Koan.Control_Tests.ps1 | 0 .../ConvertFrom-WildcardPattern.Tests.ps1 | 52 +- .../Private/Get-KoanAst.Tests.ps1 | 0 .../Private/Get-KoanAttribute.Tests.ps1 | 0 .../Private/Get-KoanIt.Tests.ps1 | 0 .../Private/Invoke-Koan.Tests.ps1 | 0 .../Private/Measure-Koan.Tests.ps1 | 180 +++---- .../Private/New-KoanRunspace.Tests.ps1 | 0 .../Private/New-PSKoanErrorRecord.Tests.ps1 | 0 .../Private/Update-PSKoanFile.Tests.ps1 | 162 +++--- .../Public/Get-Blank.Tests.ps1 | 0 .../Public/Get-Karma.Tests.ps1 | 0 .../Public/Get-PSKoan.Tests.ps1 | 0 .../Public/Get-PSKoanLocation.Tests.ps1 | 0 .../Public/Get-PSKoanSetting.Tests.ps1 | 0 .../Public/Move-PSKoanLibrary.Tests.ps1 | 0 .../Public/Register-Advice.Tests.ps1 | 0 .../Public/Reset-PSKoan.Tests.ps1 | 482 +++++++++--------- .../Public/Set-PSKoanLocation.Tests.ps1 | 0 .../Public/Set-PSKoanSetting.Tests.ps1 | 0 .../Public/Show-Advice.Tests.ps1 | 0 .../Public/Show-Karma.Tests.ps1 | 0 .../Public/Update-PSKoan.Tests.ps1 | 236 ++++----- 25 files changed, 560 insertions(+), 560 deletions(-) rename Tests/{Functions => }/Private/Assert-UnblockedFile.Tests.ps1 (100%) rename Tests/{Functions => }/Private/ControlTests/Invoke-Koan.Control_Tests.ps1 (100%) rename Tests/{Functions => }/Private/ConvertFrom-WildcardPattern.Tests.ps1 (97%) rename Tests/{Functions => }/Private/Get-KoanAst.Tests.ps1 (100%) rename Tests/{Functions => }/Private/Get-KoanAttribute.Tests.ps1 (100%) rename Tests/{Functions => }/Private/Get-KoanIt.Tests.ps1 (100%) rename Tests/{Functions => }/Private/Invoke-Koan.Tests.ps1 (100%) rename Tests/{Functions => }/Private/Measure-Koan.Tests.ps1 (96%) rename Tests/{Functions => }/Private/New-KoanRunspace.Tests.ps1 (100%) rename Tests/{Functions => }/Private/New-PSKoanErrorRecord.Tests.ps1 (100%) rename Tests/{Functions => }/Private/Update-PSKoanFile.Tests.ps1 (96%) rename Tests/{Functions => }/Public/Get-Blank.Tests.ps1 (100%) rename Tests/{Functions => }/Public/Get-Karma.Tests.ps1 (100%) rename Tests/{Functions => }/Public/Get-PSKoan.Tests.ps1 (100%) rename Tests/{Functions => }/Public/Get-PSKoanLocation.Tests.ps1 (100%) rename Tests/{Functions => }/Public/Get-PSKoanSetting.Tests.ps1 (100%) rename Tests/{Functions => }/Public/Move-PSKoanLibrary.Tests.ps1 (100%) rename Tests/{Functions => }/Public/Register-Advice.Tests.ps1 (100%) rename Tests/{Functions => }/Public/Reset-PSKoan.Tests.ps1 (97%) rename Tests/{Functions => }/Public/Set-PSKoanLocation.Tests.ps1 (100%) rename Tests/{Functions => }/Public/Set-PSKoanSetting.Tests.ps1 (100%) rename Tests/{Functions => }/Public/Show-Advice.Tests.ps1 (100%) rename Tests/{Functions => }/Public/Show-Karma.Tests.ps1 (100%) rename Tests/{Functions => }/Public/Update-PSKoan.Tests.ps1 (97%) diff --git a/Tests/KoanValidation.Tests.ps1 b/Tests/KoanValidation.Tests.ps1 index ac6b8e6c..84cc8ae2 100644 --- a/Tests/KoanValidation.Tests.ps1 +++ b/Tests/KoanValidation.Tests.ps1 @@ -23,7 +23,7 @@ Describe 'Static Analysis: Koan Topics' { } #endregion Discovery - It 'has no syntax errors in ' -TestCases $KoanTopics { + It 'has no syntax errors in ' -TestCases $KoanTopics { $File.FullName | Should -Exist $Errors = $Tokens = $null @@ -31,7 +31,7 @@ Describe 'Static Analysis: Koan Topics' { $Errors.Count | Should -Be 0 } - It 'does not have nested It blocks in ' -TestCases $KoanTopics { + It 'does not have nested It blocks in ' -TestCases $KoanTopics { function Test-ItBlock { [CmdletBinding()] param([Ast] $element) @@ -78,12 +78,12 @@ Describe 'Static Analysis: Koan Topics' { $ParentItBlocks | Should -BeNullOrEmpty -Because 'It blocks cannot be nested' } - It 'has exactly one line feed at end of the file' -TestCases $KoanTopics { + It 'has exactly one line feed at end of the file' -TestCases $KoanTopics { $crlf = [Regex]::Match(($File | Get-Content -Raw), '(\r?(?\n))+\Z') $crlf.Groups['lf'].Captures.Count | Should -Be 1 } - It 'has a position number defined for ' -TestCases $KoanTopics { + It 'has a position number defined for ' -TestCases $KoanTopics { param($File, $Position) $Position | Should -Not -BeNullOrEmpty diff --git a/Tests/Functions/Private/Assert-UnblockedFile.Tests.ps1 b/Tests/Private/Assert-UnblockedFile.Tests.ps1 similarity index 100% rename from Tests/Functions/Private/Assert-UnblockedFile.Tests.ps1 rename to Tests/Private/Assert-UnblockedFile.Tests.ps1 diff --git a/Tests/Functions/Private/ControlTests/Invoke-Koan.Control_Tests.ps1 b/Tests/Private/ControlTests/Invoke-Koan.Control_Tests.ps1 similarity index 100% rename from Tests/Functions/Private/ControlTests/Invoke-Koan.Control_Tests.ps1 rename to Tests/Private/ControlTests/Invoke-Koan.Control_Tests.ps1 diff --git a/Tests/Functions/Private/ConvertFrom-WildcardPattern.Tests.ps1 b/Tests/Private/ConvertFrom-WildcardPattern.Tests.ps1 similarity index 97% rename from Tests/Functions/Private/ConvertFrom-WildcardPattern.Tests.ps1 rename to Tests/Private/ConvertFrom-WildcardPattern.Tests.ps1 index 96ac71f9..6dc6fcf3 100644 --- a/Tests/Functions/Private/ConvertFrom-WildcardPattern.Tests.ps1 +++ b/Tests/Private/ConvertFrom-WildcardPattern.Tests.ps1 @@ -1,26 +1,26 @@ -#Requires -Modules PSKoans - -Describe 'ConvertFrom-WildcardPattern' { - - It 'adds start and end of string anchors to an explicit value' { - InModuleScope 'PSKoans' { ConvertFrom-WildcardPattern 'AboutArrays' } | Should -Be '^AboutArrays$' - } - - It 'joins multiple expressions with |' { - InModuleScope 'PSKoans' { ConvertFrom-WildcardPattern 'AboutArrays', 'AboutComparison' } | - Should -Be '^AboutArrays$|^AboutComparison$' - } - - It 'replaces wildcard characters with regex equivalent' -TestCases @( - @{ Pattern = 'About*son'; Expected = '^About.*son$' } - @{ Pattern = 'AboutArrays*'; Expected = '^AboutArrays' } - @{ Pattern = '*Arrays'; Expected = 'Arrays$' } - @{ Pattern = '*Array*'; Expected = 'Array' } - ) { - InModuleScope 'PSKoans' -Parameters @{ Pattern = $Pattern } { - param($Pattern) - - ConvertFrom-WildcardPattern $Pattern - } | Should -Be $Expected - } -} +#Requires -Modules PSKoans + +Describe 'ConvertFrom-WildcardPattern' { + + It 'adds start and end of string anchors to an explicit value' { + InModuleScope 'PSKoans' { ConvertFrom-WildcardPattern 'AboutArrays' } | Should -Be '^AboutArrays$' + } + + It 'joins multiple expressions with |' { + InModuleScope 'PSKoans' { ConvertFrom-WildcardPattern 'AboutArrays', 'AboutComparison' } | + Should -Be '^AboutArrays$|^AboutComparison$' + } + + It 'replaces wildcard characters with regex equivalent' -TestCases @( + @{ Pattern = 'About*son'; Expected = '^About.*son$' } + @{ Pattern = 'AboutArrays*'; Expected = '^AboutArrays' } + @{ Pattern = '*Arrays'; Expected = 'Arrays$' } + @{ Pattern = '*Array*'; Expected = 'Array' } + ) { + InModuleScope 'PSKoans' -Parameters @{ Pattern = $Pattern } { + param($Pattern) + + ConvertFrom-WildcardPattern $Pattern + } | Should -Be $Expected + } +} diff --git a/Tests/Functions/Private/Get-KoanAst.Tests.ps1 b/Tests/Private/Get-KoanAst.Tests.ps1 similarity index 100% rename from Tests/Functions/Private/Get-KoanAst.Tests.ps1 rename to Tests/Private/Get-KoanAst.Tests.ps1 diff --git a/Tests/Functions/Private/Get-KoanAttribute.Tests.ps1 b/Tests/Private/Get-KoanAttribute.Tests.ps1 similarity index 100% rename from Tests/Functions/Private/Get-KoanAttribute.Tests.ps1 rename to Tests/Private/Get-KoanAttribute.Tests.ps1 diff --git a/Tests/Functions/Private/Get-KoanIt.Tests.ps1 b/Tests/Private/Get-KoanIt.Tests.ps1 similarity index 100% rename from Tests/Functions/Private/Get-KoanIt.Tests.ps1 rename to Tests/Private/Get-KoanIt.Tests.ps1 diff --git a/Tests/Functions/Private/Invoke-Koan.Tests.ps1 b/Tests/Private/Invoke-Koan.Tests.ps1 similarity index 100% rename from Tests/Functions/Private/Invoke-Koan.Tests.ps1 rename to Tests/Private/Invoke-Koan.Tests.ps1 diff --git a/Tests/Functions/Private/Measure-Koan.Tests.ps1 b/Tests/Private/Measure-Koan.Tests.ps1 similarity index 96% rename from Tests/Functions/Private/Measure-Koan.Tests.ps1 rename to Tests/Private/Measure-Koan.Tests.ps1 index 577a82d6..c7c43012 100644 --- a/Tests/Functions/Private/Measure-Koan.Tests.ps1 +++ b/Tests/Private/Measure-Koan.Tests.ps1 @@ -1,90 +1,90 @@ -#Requires -Modules PSKoans - -Describe 'Measure-Koan' -Skip { - - BeforeAll { - Set-Content -Path 'TestDrive:\TestCases.Koans.ps1' -Value @' - Describe 'Test cases param' { - It 'first ' -TestCases @( - @{ TestCase = 1 } - @{ TestCase = 2 } - @{ TestCase = 3 } - ) { - param($TestCase) - - $TestCase | Should -BeOfType int - } - } -'@ - - Set-Content -Path 'TestDrive:\JustIt.Koans.ps1' -Value @' - Describe 'Just it' { - It 'first' { - $true | Should -BeTrue - } - - It 'second' { - $true | Should -BeTrue - } - } -'@ - - Set-Content -Path TestDrive:\Mixed.Koans.ps1 -Value @' - Describe 'Mixed' { - It 'first' { - $true | Should -BeTrue - } - - It 'second ' -TestCases @( - @{ TestCase = 1 } - @{ TestCase = 2 } - ) { - param($TestCase) - - $TestCase | Should -BeOfType int - } - } -'@ - - Set-Content -Path TestDrive:\MutlipleTestCases.Koans.ps1 -Value @' - Describe 'Test cases param' { - It 'first ' -TestCases @( - @{ TestCase = 1 } - @{ TestCase = 2 } - @{ TestCase = 3 } - ) { - param($TestCase) - - $TestCase | Should -BeOfType int - } - - It 'second ' -TestCases @( - @{ TestCase = 1 } - @{ TestCase = 2 } - @{ TestCase = 3 } - ) { - param($TestCase) - - $TestCase | Should -BeOfType int - } - } -'@ - } - - It 'correctly counts the number of tests in , including -TestCases' -TestCases @( - @{ Path = 'TestDrive:\TestCases.Koans.ps1'; ExpectedValue = 3 } - @{ Path = 'TestDrive:\JustIt.Koans.ps1'; ExpectedValue = 2 } - @{ Path = 'TestDrive:\Mixed.Koans.ps1'; ExpectedValue = 3 } - @{ Path = 'TestDrive:\MutlipleTestCases.Koans.ps1'; ExpectedValue = 6 } - ) { - $koanInfo = [PSCustomObject]@{ - Path = $Path - PSTypeName = 'PSKoans.KoanInfo' - } - - InModuleScope 'PSKoans' -Parameters @{ Koan = $koanInfo } { - param($Koan) - Measure-Koan $Koan - } | Should -Be $ExpectedValue - } -} +#Requires -Modules PSKoans + +Describe 'Measure-Koan' -Skip { + + BeforeAll { + Set-Content -Path 'TestDrive:\TestCases.Koans.ps1' -Value @' + Describe 'Test cases param' { + It 'first ' -TestCases @( + @{ TestCase = 1 } + @{ TestCase = 2 } + @{ TestCase = 3 } + ) { + param($TestCase) + + $TestCase | Should -BeOfType int + } + } +'@ + + Set-Content -Path 'TestDrive:\JustIt.Koans.ps1' -Value @' + Describe 'Just it' { + It 'first' { + $true | Should -BeTrue + } + + It 'second' { + $true | Should -BeTrue + } + } +'@ + + Set-Content -Path TestDrive:\Mixed.Koans.ps1 -Value @' + Describe 'Mixed' { + It 'first' { + $true | Should -BeTrue + } + + It 'second ' -TestCases @( + @{ TestCase = 1 } + @{ TestCase = 2 } + ) { + param($TestCase) + + $TestCase | Should -BeOfType int + } + } +'@ + + Set-Content -Path TestDrive:\MutlipleTestCases.Koans.ps1 -Value @' + Describe 'Test cases param' { + It 'first ' -TestCases @( + @{ TestCase = 1 } + @{ TestCase = 2 } + @{ TestCase = 3 } + ) { + param($TestCase) + + $TestCase | Should -BeOfType int + } + + It 'second ' -TestCases @( + @{ TestCase = 1 } + @{ TestCase = 2 } + @{ TestCase = 3 } + ) { + param($TestCase) + + $TestCase | Should -BeOfType int + } + } +'@ + } + + It 'correctly counts the number of tests in , including -TestCases' -TestCases @( + @{ Path = 'TestDrive:\TestCases.Koans.ps1'; ExpectedValue = 3 } + @{ Path = 'TestDrive:\JustIt.Koans.ps1'; ExpectedValue = 2 } + @{ Path = 'TestDrive:\Mixed.Koans.ps1'; ExpectedValue = 3 } + @{ Path = 'TestDrive:\MutlipleTestCases.Koans.ps1'; ExpectedValue = 6 } + ) { + $koanInfo = [PSCustomObject]@{ + Path = $Path + PSTypeName = 'PSKoans.KoanInfo' + } + + InModuleScope 'PSKoans' -Parameters @{ Koan = $koanInfo } { + param($Koan) + Measure-Koan $Koan + } | Should -Be $ExpectedValue + } +} diff --git a/Tests/Functions/Private/New-KoanRunspace.Tests.ps1 b/Tests/Private/New-KoanRunspace.Tests.ps1 similarity index 100% rename from Tests/Functions/Private/New-KoanRunspace.Tests.ps1 rename to Tests/Private/New-KoanRunspace.Tests.ps1 diff --git a/Tests/Functions/Private/New-PSKoanErrorRecord.Tests.ps1 b/Tests/Private/New-PSKoanErrorRecord.Tests.ps1 similarity index 100% rename from Tests/Functions/Private/New-PSKoanErrorRecord.Tests.ps1 rename to Tests/Private/New-PSKoanErrorRecord.Tests.ps1 diff --git a/Tests/Functions/Private/Update-PSKoanFile.Tests.ps1 b/Tests/Private/Update-PSKoanFile.Tests.ps1 similarity index 96% rename from Tests/Functions/Private/Update-PSKoanFile.Tests.ps1 rename to Tests/Private/Update-PSKoanFile.Tests.ps1 index e3a86e11..6d863556 100644 --- a/Tests/Functions/Private/Update-PSKoanFile.Tests.ps1 +++ b/Tests/Private/Update-PSKoanFile.Tests.ps1 @@ -1,81 +1,81 @@ -#Requires -Modules PSKoans - -Describe 'Update-PSKoanFile' { - - BeforeAll { - Mock 'Get-PSKoanLocation' { - Join-Path -Path $TestDrive -ChildPath 'Koans' - } - - Mock 'Get-PSKoan' { - [PSCustomObject]@{ - Topic = 'AboutSomething' - Path = Join-Path -Path $TestDrive -ChildPath 'Module/Group/AboutSomething.ps1' - RelativePath = 'Group/AboutSomething.ps1' - } - } - - New-Item -Path (Join-Path -Path $TestDrive -ChildPath 'Koans/Group') -ItemType Directory - New-Item -Path (Join-Path -Path $TestDrive -ChildPath 'Module/Group') -ItemType Directory - - Set-Content -Path (Get-PSKoan).Path -Value @' - Describe 'AboutSomething' { - It 'koan 1' { - __ | Should -Be 1 - } - - It 'koan 2' { - __ | Should -Be 2 - } - - Context 'second' { - It 'koan 4' { - __ | Should -Be 4 - } - } - } -'@ - - $userFilePath = Join-Path -Path (Get-PSKoanLocation) -ChildPath (Get-PSKoan).RelativePath - } - - BeforeEach { - Set-Content -Path $userFilePath -Value @' - Describe 'AboutSomething' { - It 'koan 1' { - 1 | Should -Be 1 - } - - It 'koan 2' { - __ | Should -Be 2 - } - - Context 'first' { - It 'koan 3' { - __ | Should -Be 3 - } - } - - Context 'second' { - It 'koan 4' { - 4 | Should -Be 4 - } - } - } -'@ - } - - It 'should replay completed koans' { - InModuleScope 'PSKoans' { Update-PSKoanFile -Topic AboutSomething -Confirm:$false } - - $userFilePath | Should -FileContentMatch '1 | Should -Be 1' - $userFilePath | Should -FileContentMatch '__ | Should -Be 2' - $userFilePath | Should -FileContentMatch '4 | Should -Be 4' - } - - It 'should should allow new koans to be inserted' { - InModuleScope 'PSKoans' { Update-PSKoanFile -Topic AboutSomething -Confirm:$false } - - $userFilePath | Should -FileContentMatch 'koan 3' - } -} +#Requires -Modules PSKoans + +Describe 'Update-PSKoanFile' { + + BeforeAll { + Mock 'Get-PSKoanLocation' { + Join-Path -Path $TestDrive -ChildPath 'Koans' + } + + Mock 'Get-PSKoan' { + [PSCustomObject]@{ + Topic = 'AboutSomething' + Path = Join-Path -Path $TestDrive -ChildPath 'Module/Group/AboutSomething.ps1' + RelativePath = 'Group/AboutSomething.ps1' + } + } + + New-Item -Path (Join-Path -Path $TestDrive -ChildPath 'Koans/Group') -ItemType Directory + New-Item -Path (Join-Path -Path $TestDrive -ChildPath 'Module/Group') -ItemType Directory + + Set-Content -Path (Get-PSKoan).Path -Value @' + Describe 'AboutSomething' { + It 'koan 1' { + __ | Should -Be 1 + } + + It 'koan 2' { + __ | Should -Be 2 + } + + Context 'second' { + It 'koan 4' { + __ | Should -Be 4 + } + } + } +'@ + + $userFilePath = Join-Path -Path (Get-PSKoanLocation) -ChildPath (Get-PSKoan).RelativePath + } + + BeforeEach { + Set-Content -Path $userFilePath -Value @' + Describe 'AboutSomething' { + It 'koan 1' { + 1 | Should -Be 1 + } + + It 'koan 2' { + __ | Should -Be 2 + } + + Context 'first' { + It 'koan 3' { + __ | Should -Be 3 + } + } + + Context 'second' { + It 'koan 4' { + 4 | Should -Be 4 + } + } + } +'@ + } + + It 'should replay completed koans' { + InModuleScope 'PSKoans' { Update-PSKoanFile -Topic AboutSomething -Confirm:$false } + + $userFilePath | Should -FileContentMatch '1 | Should -Be 1' + $userFilePath | Should -FileContentMatch '__ | Should -Be 2' + $userFilePath | Should -FileContentMatch '4 | Should -Be 4' + } + + It 'should should allow new koans to be inserted' { + InModuleScope 'PSKoans' { Update-PSKoanFile -Topic AboutSomething -Confirm:$false } + + $userFilePath | Should -FileContentMatch 'koan 3' + } +} diff --git a/Tests/Functions/Public/Get-Blank.Tests.ps1 b/Tests/Public/Get-Blank.Tests.ps1 similarity index 100% rename from Tests/Functions/Public/Get-Blank.Tests.ps1 rename to Tests/Public/Get-Blank.Tests.ps1 diff --git a/Tests/Functions/Public/Get-Karma.Tests.ps1 b/Tests/Public/Get-Karma.Tests.ps1 similarity index 100% rename from Tests/Functions/Public/Get-Karma.Tests.ps1 rename to Tests/Public/Get-Karma.Tests.ps1 diff --git a/Tests/Functions/Public/Get-PSKoan.Tests.ps1 b/Tests/Public/Get-PSKoan.Tests.ps1 similarity index 100% rename from Tests/Functions/Public/Get-PSKoan.Tests.ps1 rename to Tests/Public/Get-PSKoan.Tests.ps1 diff --git a/Tests/Functions/Public/Get-PSKoanLocation.Tests.ps1 b/Tests/Public/Get-PSKoanLocation.Tests.ps1 similarity index 100% rename from Tests/Functions/Public/Get-PSKoanLocation.Tests.ps1 rename to Tests/Public/Get-PSKoanLocation.Tests.ps1 diff --git a/Tests/Functions/Public/Get-PSKoanSetting.Tests.ps1 b/Tests/Public/Get-PSKoanSetting.Tests.ps1 similarity index 100% rename from Tests/Functions/Public/Get-PSKoanSetting.Tests.ps1 rename to Tests/Public/Get-PSKoanSetting.Tests.ps1 diff --git a/Tests/Functions/Public/Move-PSKoanLibrary.Tests.ps1 b/Tests/Public/Move-PSKoanLibrary.Tests.ps1 similarity index 100% rename from Tests/Functions/Public/Move-PSKoanLibrary.Tests.ps1 rename to Tests/Public/Move-PSKoanLibrary.Tests.ps1 diff --git a/Tests/Functions/Public/Register-Advice.Tests.ps1 b/Tests/Public/Register-Advice.Tests.ps1 similarity index 100% rename from Tests/Functions/Public/Register-Advice.Tests.ps1 rename to Tests/Public/Register-Advice.Tests.ps1 diff --git a/Tests/Functions/Public/Reset-PSKoan.Tests.ps1 b/Tests/Public/Reset-PSKoan.Tests.ps1 similarity index 97% rename from Tests/Functions/Public/Reset-PSKoan.Tests.ps1 rename to Tests/Public/Reset-PSKoan.Tests.ps1 index 8cdccd07..94bc8f7d 100644 --- a/Tests/Functions/Public/Reset-PSKoan.Tests.ps1 +++ b/Tests/Public/Reset-PSKoan.Tests.ps1 @@ -1,241 +1,241 @@ -#Requires -Modules PSKoans - -Describe Reset-PSKoan { - - BeforeAll { - $defaultParams = @{ - Confirm = $false - } - - $module = @{ - ModuleName = 'PSKoans' - } - - Mock 'Get-PSKoanLocation' { - Join-Path -Path $TestDrive -ChildPath 'PSKoans' - } @module - - Mock 'Get-PSKoanLocation' { - Join-Path -Path $TestDrive -ChildPath 'PSKoans' - } - - Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'Module' } -MockWith { - [PSCustomObject]@{ - Topic = 'AboutSomething' - Path = Join-Path -Path $TestDrive -ChildPath 'Module\Group\AboutSomething.Koans.ps1' - RelativePath = 'Group\AboutSomething.Koans.ps1' - } - } @module - - New-Item -Path (Join-Path -Path $TestDrive -ChildPath 'Module\Group') -ItemType Directory -Force - New-Item -Path (Join-Path -Path $TestDrive -ChildPath 'PSKoans\Group') -ItemType Directory -Force - - $userFilePath = Get-PSKoanLocation | Join-Path -ChildPath 'Group\AboutSomething.Koans.ps1' - - Set-Content -Path $userFilePath -Value @' - #using module PSKoans - [Koan(Position = 1)] - param ( ) - - Describe 'AboutSomething' { - It 'reset content' { - __ | Should -Be 2 - } - - Context 'first' { - It 'nested reset content' { - __ | Should -Be 3 - } - } - - Context 'second' { - It 'nested reset content' { - __ | Should -Be 4 - } - } - } -'@ - Set-Content -Path (Join-Path -Path $TestDrive -ChildPath 'Module\Group\AboutSomething.Koans.ps1') -Value @' - #using module PSKoans - [Koan(Position = 1)] - param ( ) - - Describe 'AboutSomething' { - It 'existing content' { - __ | Should -Be 1 - } - - It 'reset content' { - __ | Should -Be 2 - } - - Context 'first' { - It 'nested reset content' { - __ | Should -Be 3 - } - } - - Context 'second' { - It 'nested reset content' { - __ | Should -Be 4 - } - } - } -'@ - } - - Context 'User file exists, It block exists' { - - BeforeAll { - Mock 'Set-Content' @module - Mock 'Copy-Item' @module - } - - It 'updates an existing user file when -Name is supplied' { - Reset-PSKoan -Name 'reset content' @defaultParams - - Should -Invoke 'Set-Content' -Times 1 @module - Should -Invoke 'Copy-Item' -Times 0 @module - } - - It 'updates an existing user file when -Context is supplied' { - Reset-PSKoan -Context 'first' @defaultParams - - Should -Invoke 'Set-Content' -Times 1 -Exactly @module - Should -Invoke 'Copy-Item' -Times 0 @module - } - - It 'updates an existing user file when -Name and -Context are supplied' { - Reset-PSKoan -Name 'nested reset content' -Context 'first' @defaultParams - - Should -Invoke 'Set-Content' -Times 1 -Exactly @module - Should -Invoke 'Copy-Item' -Times 0 @module - } - - It 'copies a koan file from the module when -Name and -Context are not supplied' { - Reset-PSKoan @defaultParams - - Should -Invoke 'Set-Content' -Times 0 @module - Should -Invoke 'Copy-Item' -Times 1 -Exactly @module - } - } - - Context 'User file exists, It block does not exist' { - - It 'writes a non-terminating error when the user file does not include the specified Koan' { - - { Reset-PSKoan -Topic AboutSomething -Name 'existing content' -ErrorAction Stop @defaultParams } | - Should -Throw -ErrorId 'PSKoans.UserItNotFound,Reset-PSKoan' - } - } - - Context 'User file does not exist' { - - BeforeAll { - New-Item "$TestDrive/DoesNotExist.Koans.ps1" -ItemType File > $null - - Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'User' } -Verifiable @module - Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'Module' } -Verifiable -MockWith { - [PSCustomObject]@{ - Topic = $Topic - Module = '_powershell' - Position = 101 - Path = "$TestDrive/DoesNotExist.Koans.ps1" - RelativePath = 'DoesNotExist.Koans.ps1' - PSTypeName = 'PSKoans.KoanInfo' - } - } @module - - Mock 'Update-PSKoan' @module - } - - It 'calls Update-PSKoan when the topic does not exist in the user location' { - Reset-PSKoan -Topic DoesNotExist -ErrorAction Stop @defaultParams - - Should -InvokeVerifiable - Should -Invoke Update-PSKoan -Times 1 -Exactly @module - } - } - - Context 'Module file does not exist' { - - BeforeAll { - Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'Module' } @module - } - - It 'throws a terminating error when no topics are found in the module' { - { Reset-PSKoan -Topic DoesNotExist @defaultParams } | - Should -Throw -ErrorId 'PSKoans.ModuleTopicNotFound,Reset-PSKoan' - - Should -Invoke 'Get-PSKoan' -Times 1 -Exactly @module - } - } - - Context 'Practical tests' { - - BeforeEach { - Set-Content -Path $userFilePath -Value @' - using module PSKoans - [Koan(Position = 1)] - param ( ) - - Describe 'AboutSomething' { - It 'existing content' { - 1 | Should -Be 1 - } - - It 'reset content' { - 1 | Should -Be 2 - } - - Context 'first' { - It 'nested reset content' { - 3 | Should -Be 3 - } - } - - Context 'second' { - It 'nested reset content' { - 4 | Should -Be 4 - } - } - } -'@ - } - - It 'should reset all koans in a file when Name is not specified' { - $userFilePath | Should -FileContentMatch '__ | Should -Be 1' - $userFilePath | Should -FileContentMatch '__ | Should -Be 2' - $userFilePath | Should -FileContentMatch '__ | Should -Be 3' - $userFilePath | Should -FileContentMatch '__ | Should -Be 4' - } - - It 'should reset the state of a single koan without affecting others when Name is specified' { - Reset-PSKoan -Topic AboutSomething -Name 'reset content' @defaultParams - - $userFilePath | Should -FileContentMatch '1 | Should -Be 1' - $userFilePath | Should -FileContentMatch '__ | Should -Be 2' - } - - It 'supports context based searching' { - Reset-PSKoan -Topic AboutSomething -Name "nested reset content" -Context 'first' @defaultParams - - $userFilePath | Should -FileContentMatch '__ | Should -Be 3' - $userFilePath | Should -FileContentMatch '4 | Should -Be 4' - } - - It 'allows koans of a given name to be reset across all contexts' { - Reset-PSKoan -Topic AboutSomething -Name "nested reset content" @defaultParams - - $userFilePath | Should -FileContentMatch '__ | Should -Be 3' - $userFilePath | Should -FileContentMatch '__ | Should -Be 4' - } - - It 'supports wildcard patterns when matching name' { - Reset-PSKoan -Topic AboutSomething -Name "*content" @defaultParams - - $userFilePath | Should -FileContentMatch '__ | Should -Be 1' - $userFilePath | Should -FileContentMatch '__ | Should -Be 2' - } - } -} +#Requires -Modules PSKoans + +Describe Reset-PSKoan { + + BeforeAll { + $defaultParams = @{ + Confirm = $false + } + + $module = @{ + ModuleName = 'PSKoans' + } + + Mock 'Get-PSKoanLocation' { + Join-Path -Path $TestDrive -ChildPath 'PSKoans' + } @module + + Mock 'Get-PSKoanLocation' { + Join-Path -Path $TestDrive -ChildPath 'PSKoans' + } + + Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'Module' } -MockWith { + [PSCustomObject]@{ + Topic = 'AboutSomething' + Path = Join-Path -Path $TestDrive -ChildPath 'Module\Group\AboutSomething.Koans.ps1' + RelativePath = 'Group\AboutSomething.Koans.ps1' + } + } @module + + New-Item -Path (Join-Path -Path $TestDrive -ChildPath 'Module\Group') -ItemType Directory -Force + New-Item -Path (Join-Path -Path $TestDrive -ChildPath 'PSKoans\Group') -ItemType Directory -Force + + $userFilePath = Get-PSKoanLocation | Join-Path -ChildPath 'Group\AboutSomething.Koans.ps1' + + Set-Content -Path $userFilePath -Value @' + #using module PSKoans + [Koan(Position = 1)] + param ( ) + + Describe 'AboutSomething' { + It 'reset content' { + __ | Should -Be 2 + } + + Context 'first' { + It 'nested reset content' { + __ | Should -Be 3 + } + } + + Context 'second' { + It 'nested reset content' { + __ | Should -Be 4 + } + } + } +'@ + Set-Content -Path (Join-Path -Path $TestDrive -ChildPath 'Module\Group\AboutSomething.Koans.ps1') -Value @' + #using module PSKoans + [Koan(Position = 1)] + param ( ) + + Describe 'AboutSomething' { + It 'existing content' { + __ | Should -Be 1 + } + + It 'reset content' { + __ | Should -Be 2 + } + + Context 'first' { + It 'nested reset content' { + __ | Should -Be 3 + } + } + + Context 'second' { + It 'nested reset content' { + __ | Should -Be 4 + } + } + } +'@ + } + + Context 'User file exists, It block exists' { + + BeforeAll { + Mock 'Set-Content' @module + Mock 'Copy-Item' @module + } + + It 'updates an existing user file when -Name is supplied' { + Reset-PSKoan -Name 'reset content' @defaultParams + + Should -Invoke 'Set-Content' -Times 1 @module + Should -Invoke 'Copy-Item' -Times 0 @module + } + + It 'updates an existing user file when -Context is supplied' { + Reset-PSKoan -Context 'first' @defaultParams + + Should -Invoke 'Set-Content' -Times 1 -Exactly @module + Should -Invoke 'Copy-Item' -Times 0 @module + } + + It 'updates an existing user file when -Name and -Context are supplied' { + Reset-PSKoan -Name 'nested reset content' -Context 'first' @defaultParams + + Should -Invoke 'Set-Content' -Times 1 -Exactly @module + Should -Invoke 'Copy-Item' -Times 0 @module + } + + It 'copies a koan file from the module when -Name and -Context are not supplied' { + Reset-PSKoan @defaultParams + + Should -Invoke 'Set-Content' -Times 0 @module + Should -Invoke 'Copy-Item' -Times 1 -Exactly @module + } + } + + Context 'User file exists, It block does not exist' { + + It 'writes a non-terminating error when the user file does not include the specified Koan' { + + { Reset-PSKoan -Topic AboutSomething -Name 'existing content' -ErrorAction Stop @defaultParams } | + Should -Throw -ErrorId 'PSKoans.UserItNotFound,Reset-PSKoan' + } + } + + Context 'User file does not exist' { + + BeforeAll { + New-Item "$TestDrive/DoesNotExist.Koans.ps1" -ItemType File > $null + + Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'User' } -Verifiable @module + Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'Module' } -Verifiable -MockWith { + [PSCustomObject]@{ + Topic = $Topic + Module = '_powershell' + Position = 101 + Path = "$TestDrive/DoesNotExist.Koans.ps1" + RelativePath = 'DoesNotExist.Koans.ps1' + PSTypeName = 'PSKoans.KoanInfo' + } + } @module + + Mock 'Update-PSKoan' @module + } + + It 'calls Update-PSKoan when the topic does not exist in the user location' { + Reset-PSKoan -Topic DoesNotExist -ErrorAction Stop @defaultParams + + Should -InvokeVerifiable + Should -Invoke Update-PSKoan -Times 1 -Exactly @module + } + } + + Context 'Module file does not exist' { + + BeforeAll { + Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'Module' } @module + } + + It 'throws a terminating error when no topics are found in the module' { + { Reset-PSKoan -Topic DoesNotExist @defaultParams } | + Should -Throw -ErrorId 'PSKoans.ModuleTopicNotFound,Reset-PSKoan' + + Should -Invoke 'Get-PSKoan' -Times 1 -Exactly @module + } + } + + Context 'Practical tests' { + + BeforeEach { + Set-Content -Path $userFilePath -Value @' + using module PSKoans + [Koan(Position = 1)] + param ( ) + + Describe 'AboutSomething' { + It 'existing content' { + 1 | Should -Be 1 + } + + It 'reset content' { + 1 | Should -Be 2 + } + + Context 'first' { + It 'nested reset content' { + 3 | Should -Be 3 + } + } + + Context 'second' { + It 'nested reset content' { + 4 | Should -Be 4 + } + } + } +'@ + } + + It 'should reset all koans in a file when Name is not specified' { + $userFilePath | Should -FileContentMatch '__ | Should -Be 1' + $userFilePath | Should -FileContentMatch '__ | Should -Be 2' + $userFilePath | Should -FileContentMatch '__ | Should -Be 3' + $userFilePath | Should -FileContentMatch '__ | Should -Be 4' + } + + It 'should reset the state of a single koan without affecting others when Name is specified' { + Reset-PSKoan -Topic AboutSomething -Name 'reset content' @defaultParams + + $userFilePath | Should -FileContentMatch '1 | Should -Be 1' + $userFilePath | Should -FileContentMatch '__ | Should -Be 2' + } + + It 'supports context based searching' { + Reset-PSKoan -Topic AboutSomething -Name "nested reset content" -Context 'first' @defaultParams + + $userFilePath | Should -FileContentMatch '__ | Should -Be 3' + $userFilePath | Should -FileContentMatch '4 | Should -Be 4' + } + + It 'allows koans of a given name to be reset across all contexts' { + Reset-PSKoan -Topic AboutSomething -Name "nested reset content" @defaultParams + + $userFilePath | Should -FileContentMatch '__ | Should -Be 3' + $userFilePath | Should -FileContentMatch '__ | Should -Be 4' + } + + It 'supports wildcard patterns when matching name' { + Reset-PSKoan -Topic AboutSomething -Name "*content" @defaultParams + + $userFilePath | Should -FileContentMatch '__ | Should -Be 1' + $userFilePath | Should -FileContentMatch '__ | Should -Be 2' + } + } +} diff --git a/Tests/Functions/Public/Set-PSKoanLocation.Tests.ps1 b/Tests/Public/Set-PSKoanLocation.Tests.ps1 similarity index 100% rename from Tests/Functions/Public/Set-PSKoanLocation.Tests.ps1 rename to Tests/Public/Set-PSKoanLocation.Tests.ps1 diff --git a/Tests/Functions/Public/Set-PSKoanSetting.Tests.ps1 b/Tests/Public/Set-PSKoanSetting.Tests.ps1 similarity index 100% rename from Tests/Functions/Public/Set-PSKoanSetting.Tests.ps1 rename to Tests/Public/Set-PSKoanSetting.Tests.ps1 diff --git a/Tests/Functions/Public/Show-Advice.Tests.ps1 b/Tests/Public/Show-Advice.Tests.ps1 similarity index 100% rename from Tests/Functions/Public/Show-Advice.Tests.ps1 rename to Tests/Public/Show-Advice.Tests.ps1 diff --git a/Tests/Functions/Public/Show-Karma.Tests.ps1 b/Tests/Public/Show-Karma.Tests.ps1 similarity index 100% rename from Tests/Functions/Public/Show-Karma.Tests.ps1 rename to Tests/Public/Show-Karma.Tests.ps1 diff --git a/Tests/Functions/Public/Update-PSKoan.Tests.ps1 b/Tests/Public/Update-PSKoan.Tests.ps1 similarity index 97% rename from Tests/Functions/Public/Update-PSKoan.Tests.ps1 rename to Tests/Public/Update-PSKoan.Tests.ps1 index f0fe4955..38677ed8 100644 --- a/Tests/Functions/Public/Update-PSKoan.Tests.ps1 +++ b/Tests/Public/Update-PSKoan.Tests.ps1 @@ -1,118 +1,118 @@ -#Requires -Modules PSKoans - -Describe 'Update-PSKoan' { - - BeforeAll { - $module = @{ - ModuleName = 'PSKoans' - } - } - - Context 'Mocked Commands' { - - BeforeAll { - Mock 'Remove-Item' @module - Mock 'Copy-Item' @module - Mock 'New-Item' @module - Mock 'Move-Item' @module - Mock 'Update-PSKoanFile' @module - - Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'Module' } -MockWith { - [PSCustomObject]@{ - Topic = 'Missing' - Path = 'Module\Group\AboutSomethingMissing.Koans.ps1' - } - [PSCustomObject]@{ - Topic = 'IncorrectPath' - Path = 'Module\Group\AboutSomethingIncorrectPath.Koans.ps1' - } - [PSCustomObject]@{ - Topic = 'Existing' - Path = 'Module\Group\AboutSomethingExisting.Koans.ps1' - } - } @module - - Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'User' } -MockWith { - [PSCustomObject]@{ - Topic = 'IncorrectPath' - Path = 'Module\RetiredGroup\AboutSomethingIncorrectPath.Koans.ps1' - } - [PSCustomObject]@{ - Topic = 'RetiredTopic' - Path = 'Module\RetiredGroup\AboutSomethingRetiredTopic.Koans.ps1' - } - [PSCustomObject]@{ - Topic = 'Existing' - Path = 'Module\Group\AboutSomethingExisting.Koans.ps1' - } - } @module - } - - It 'should not produce output' { - Update-PSKoan -Confirm:$false | Should -BeNullOrEmpty - } - - It 'should copy missing topic files' { - Should -Invoke 'Copy-Item' -Times 1 -Scope Context @module - } - - It 'should move incorrectly placed topics' { - Should -Invoke 'Remove-Item' -Times 1 -Scope Context @module - } - - It 'should remove discarded topics' { - Should -Invoke 'Remove-Item' -Times 1 -Scope Context @module - } - - It 'should update topics which exist in module and koan path' { - Should -Invoke 'Update-PSKoanFile' @module -Times 2 -Scope Context - } - } - - Context 'Practical Tests with TestDrive' { - - BeforeAll { - Mock 'Get-PSKoanLocation' { - Join-Path -Path $TestDrive -ChildPath 'PSKoans' - } - Mock 'Get-PSKoanLocation' { - Join-Path -Path $TestDrive -ChildPath 'PSKoans' - } @module - - New-Item -Path (Get-PSKoanLocation) -ItemType Directory - Update-PSKoan -Confirm:$false - - $file = Get-ChildItem -Path (Get-PSKoanLocation) -Filter *.koans.ps1 -File -Recurse | - Select-Object -First 1 - } - - It 'should copy missing topic files' { - $file | Remove-Item - $file.FullName | Should -Not -Exist - - Update-PSKoan -Confirm:$false - - $file.FullName | Should -Exist - } - - It 'should move incorrectly placed topics' { - $directory = New-Item -Path (Join-Path -Path $TestDrive -ChildPath 'PSKoans\Wrong') -ItemType Directory - $file | Move-Item -Destination $directory.FullName - $file.FullName | Should -Not -Exist - - Update-PSKoan -Confirm:$false - - $file.FullName | Should -Exist - } - - It 'should remove discarded topics' { - $oldTopicPath = Join-Path $TestDrive 'PSKoans\Foundations\OldTopic.koans.ps1' - $file | Copy-Item -Destination $oldTopicPath - $oldTopicPath | Should -Exist - - Update-PSKoan -Confirm:$false - - $oldTopicPath | Should -Not -Exist - } - } -} +#Requires -Modules PSKoans + +Describe 'Update-PSKoan' { + + BeforeAll { + $module = @{ + ModuleName = 'PSKoans' + } + } + + Context 'Mocked Commands' { + + BeforeAll { + Mock 'Remove-Item' @module + Mock 'Copy-Item' @module + Mock 'New-Item' @module + Mock 'Move-Item' @module + Mock 'Update-PSKoanFile' @module + + Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'Module' } -MockWith { + [PSCustomObject]@{ + Topic = 'Missing' + Path = 'Module\Group\AboutSomethingMissing.Koans.ps1' + } + [PSCustomObject]@{ + Topic = 'IncorrectPath' + Path = 'Module\Group\AboutSomethingIncorrectPath.Koans.ps1' + } + [PSCustomObject]@{ + Topic = 'Existing' + Path = 'Module\Group\AboutSomethingExisting.Koans.ps1' + } + } @module + + Mock 'Get-PSKoan' -ParameterFilter { $Scope -eq 'User' } -MockWith { + [PSCustomObject]@{ + Topic = 'IncorrectPath' + Path = 'Module\RetiredGroup\AboutSomethingIncorrectPath.Koans.ps1' + } + [PSCustomObject]@{ + Topic = 'RetiredTopic' + Path = 'Module\RetiredGroup\AboutSomethingRetiredTopic.Koans.ps1' + } + [PSCustomObject]@{ + Topic = 'Existing' + Path = 'Module\Group\AboutSomethingExisting.Koans.ps1' + } + } @module + } + + It 'should not produce output' { + Update-PSKoan -Confirm:$false | Should -BeNullOrEmpty + } + + It 'should copy missing topic files' { + Should -Invoke 'Copy-Item' -Times 1 -Scope Context @module + } + + It 'should move incorrectly placed topics' { + Should -Invoke 'Remove-Item' -Times 1 -Scope Context @module + } + + It 'should remove discarded topics' { + Should -Invoke 'Remove-Item' -Times 1 -Scope Context @module + } + + It 'should update topics which exist in module and koan path' { + Should -Invoke 'Update-PSKoanFile' @module -Times 2 -Scope Context + } + } + + Context 'Practical Tests with TestDrive' { + + BeforeAll { + Mock 'Get-PSKoanLocation' { + Join-Path -Path $TestDrive -ChildPath 'PSKoans' + } + Mock 'Get-PSKoanLocation' { + Join-Path -Path $TestDrive -ChildPath 'PSKoans' + } @module + + New-Item -Path (Get-PSKoanLocation) -ItemType Directory + Update-PSKoan -Confirm:$false + + $file = Get-ChildItem -Path (Get-PSKoanLocation) -Filter *.koans.ps1 -File -Recurse | + Select-Object -First 1 + } + + It 'should copy missing topic files' { + $file | Remove-Item + $file.FullName | Should -Not -Exist + + Update-PSKoan -Confirm:$false + + $file.FullName | Should -Exist + } + + It 'should move incorrectly placed topics' { + $directory = New-Item -Path (Join-Path -Path $TestDrive -ChildPath 'PSKoans\Wrong') -ItemType Directory + $file | Move-Item -Destination $directory.FullName + $file.FullName | Should -Not -Exist + + Update-PSKoan -Confirm:$false + + $file.FullName | Should -Exist + } + + It 'should remove discarded topics' { + $oldTopicPath = Join-Path $TestDrive 'PSKoans\Foundations\OldTopic.koans.ps1' + $file | Copy-Item -Destination $oldTopicPath + $oldTopicPath | Should -Exist + + Update-PSKoan -Confirm:$false + + $oldTopicPath | Should -Not -Exist + } + } +} From 93a946032e6f67a67cc89cd6c2884e6824e19e3e Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sat, 18 Feb 2023 22:16:12 -0800 Subject: [PATCH 82/92] Specify only PSKoans files for coverage, not Koans --- Build/Invoke-ModuleTests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Build/Invoke-ModuleTests.ps1 b/Build/Invoke-ModuleTests.ps1 index 8bdde8c6..e221a282 100644 --- a/Build/Invoke-ModuleTests.ps1 +++ b/Build/Invoke-ModuleTests.ps1 @@ -22,7 +22,7 @@ try { $config.Output.Verbosity = "Detailed" $config.CodeCoverage.Enabled = $true - $config.CodeCoverage.Path = "$env:PROJECTROOT\PSKoans" + $config.CodeCoverage.Path = @("$env:PROJECTROOT\PSKoans\Private", "$env:PROJECTROOT\PSKoans\Public") Invoke-Pester -Configuration $config } From 542493002bccc0fbafe1c29207c6b8686ae0b609 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sat, 18 Feb 2023 22:47:27 -0800 Subject: [PATCH 83/92] Comment out install of PSKoans Also demote output back to Normal from Detailed --- .github/workflows/github.yml | 2 +- Build/Invoke-ModuleTests.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 3b50f1c2..59f3292c 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -181,7 +181,7 @@ jobs: } Register-PackageSource -Name PSGallery -ProviderName NuGet -Location https://www.powershellgallery.com/api/v2 -Force Save-Package @pesterParams | Select-Object -Property Name, Version, Status, Source - Install-Module PSKoans -Repository $env:PSRepositoryName -Force -Scope CurrentUser + #Install-Module PSKoans -Repository $env:PSRepositoryName -Force -Scope CurrentUser env: GITHUB_WORKSPACE: ${{github.workspace}} PackageDownloadPath: ${{ env.PackageDownloadPath }} diff --git a/Build/Invoke-ModuleTests.ps1 b/Build/Invoke-ModuleTests.ps1 index e221a282..5c994aee 100644 --- a/Build/Invoke-ModuleTests.ps1 +++ b/Build/Invoke-ModuleTests.ps1 @@ -19,7 +19,7 @@ try { $config.TestResult.Enabled = $true - $config.Output.Verbosity = "Detailed" + $config.Output.Verbosity = "Normal" $config.CodeCoverage.Enabled = $true $config.CodeCoverage.Path = @("$env:PROJECTROOT\PSKoans\Private", "$env:PROJECTROOT\PSKoans\Public") From 146a50750f3c13374c322b4776e88022e41c306d Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sat, 18 Feb 2023 23:08:48 -0800 Subject: [PATCH 84/92] Add ability to import PSKoans from local --- Build/Invoke-ModuleTests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Build/Invoke-ModuleTests.ps1 b/Build/Invoke-ModuleTests.ps1 index 5c994aee..2179d0d7 100644 --- a/Build/Invoke-ModuleTests.ps1 +++ b/Build/Invoke-ModuleTests.ps1 @@ -1,6 +1,6 @@ $Lines = '-' * 70 - -Import-Module 'PSKoans' +$env:PSModulePath = "$env:PROJECTROOT$([IO.Path]::PathSeparator)$env:PSModulePath" +Import-Module "$env:PROJECTROOT\PSKoans" $PesterVersion = (Get-Module -Name Pester).Version $PSVersion = $PSVersionTable.PSVersion From 7665ec2085ebb8925eb1b1597884057d50437a35 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sat, 18 Feb 2023 23:20:39 -0800 Subject: [PATCH 85/92] Remove unneeded environment variable set Also commented out suspected unneccesary step in the Test job --- .github/workflows/github.yml | 40 ++++++++++++++++++------------------ Build/Invoke-ModuleTests.ps1 | 4 ++-- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 59f3292c..195df378 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -167,26 +167,26 @@ jobs: name: ${{ env.NupkgArtifactName }} path: "${{ github.workspace }}/${{ env.PackageDownloadPath }}" - - name: Install Module from Nupkg - shell: pwsh - run: | - $PackageDownloadPath = "$env:GITHUB_WORKSPACE/$env:PackageDownloadPath" - $pesterParams = @{ - Name = 'Pester' - MinimumVersion = $env:pester_min_version - ProviderName = 'NuGet' - Path = $PackageDownloadPath - Force = $true - Source = 'PSGallery' - } - Register-PackageSource -Name PSGallery -ProviderName NuGet -Location https://www.powershellgallery.com/api/v2 -Force - Save-Package @pesterParams | Select-Object -Property Name, Version, Status, Source - #Install-Module PSKoans -Repository $env:PSRepositoryName -Force -Scope CurrentUser - env: - GITHUB_WORKSPACE: ${{github.workspace}} - PackageDownloadPath: ${{ env.PackageDownloadPath }} - PSRepositoryName: ${{ env.PSRepositoryName }} - pester_min_version: ${{ env.pester_min_version }} + # - name: Install Module from Nupkg + # shell: pwsh + # run: | + # $PackageDownloadPath = "$env:GITHUB_WORKSPACE/$env:PackageDownloadPath" + # $pesterParams = @{ + # Name = 'Pester' + # MinimumVersion = $env:pester_min_version + # ProviderName = 'NuGet' + # Path = $PackageDownloadPath + # Force = $true + # Source = 'PSGallery' + # } + # Register-PackageSource -Name PSGallery -ProviderName NuGet -Location https://www.powershellgallery.com/api/v2 -Force + # Save-Package @pesterParams | Select-Object -Property Name, Version, Status, Source + # Install-Module PSKoans -Repository $env:PSRepositoryName -Force -Scope CurrentUser + # env: + # GITHUB_WORKSPACE: ${{github.workspace}} + # PackageDownloadPath: ${{ env.PackageDownloadPath }} + # PSRepositoryName: ${{ env.PSRepositoryName }} + # pester_min_version: ${{ env.pester_min_version }} - name: Run Pester Tests shell: pwsh diff --git a/Build/Invoke-ModuleTests.ps1 b/Build/Invoke-ModuleTests.ps1 index 2179d0d7..92c7f5a5 100644 --- a/Build/Invoke-ModuleTests.ps1 +++ b/Build/Invoke-ModuleTests.ps1 @@ -1,5 +1,5 @@ $Lines = '-' * 70 -$env:PSModulePath = "$env:PROJECTROOT$([IO.Path]::PathSeparator)$env:PSModulePath" + Import-Module "$env:PROJECTROOT\PSKoans" $PesterVersion = (Get-Module -Name Pester).Version @@ -19,7 +19,7 @@ try { $config.TestResult.Enabled = $true - $config.Output.Verbosity = "Normal" + $config.Output.Verbosity = "Detailed" $config.CodeCoverage.Enabled = $true $config.CodeCoverage.Path = @("$env:PROJECTROOT\PSKoans\Private", "$env:PROJECTROOT\PSKoans\Public") From 8261cff467122df663b479a050ec8c6fe504c11b Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sat, 18 Feb 2023 23:30:51 -0800 Subject: [PATCH 86/92] Comment out more potentially unused steps --- .github/workflows/github.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 195df378..7e26b636 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -152,20 +152,20 @@ jobs: shell: pwsh run: ./Build/Initialize-Environment.ps1 - - name: Register FileSystem Repository - shell: pwsh - run: | - $PackageDownloadPath = "$env:GITHUB_WORKSPACE/$env:PackageDownloadPath" - ./Build/Register-FileSystemRepository.ps1 -Path $PackageDownloadPath -Name ${{ env.PSRepositoryName }} - env: - GITHUB_WORKSPACE: ${{github.workspace}} - PackageDownloadPath: ${{ env.PackageDownloadPath }} + # - name: Register FileSystem Repository + # shell: pwsh + # run: | + # $PackageDownloadPath = "$env:GITHUB_WORKSPACE/$env:PackageDownloadPath" + # ./Build/Register-FileSystemRepository.ps1 -Path $PackageDownloadPath -Name ${{ env.PSRepositoryName }} + # env: + # GITHUB_WORKSPACE: ${{github.workspace}} + # PackageDownloadPath: ${{ env.PackageDownloadPath }} - - name: Download Module Nupkg - uses: actions/download-artifact@v2.0.9 - with: - name: ${{ env.NupkgArtifactName }} - path: "${{ github.workspace }}/${{ env.PackageDownloadPath }}" + # - name: Download Module Nupkg + # uses: actions/download-artifact@v2.0.9 + # with: + # name: ${{ env.NupkgArtifactName }} + # path: "${{ github.workspace }}/${{ env.PackageDownloadPath }}" # - name: Install Module from Nupkg # shell: pwsh From 160008f62d12750e3d8d1b40545c2d064e51aa8e Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sat, 18 Feb 2023 23:31:03 -0800 Subject: [PATCH 87/92] Bump Pester to version 5.4.0 --- PSKoans/PSKoans.psd1 | 2 +- README.md | 4 ++-- templates/environment-setup.yml | 2 +- templates/install-built-module.yml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/PSKoans/PSKoans.psd1 b/PSKoans/PSKoans.psd1 index df3e9e77..aaf1adee 100644 --- a/PSKoans/PSKoans.psd1 +++ b/PSKoans/PSKoans.psd1 @@ -54,7 +54,7 @@ RequiredModules = @( @{ ModuleName = 'Pester' - ModuleVersion = '5.0.2' + ModuleVersion = '5.4.0' } ) diff --git a/README.md b/README.md index 9b10b660..bb1a8d4f 100644 --- a/README.md +++ b/README.md @@ -41,10 +41,10 @@ To install the latest version of Pester, use the appropriate command for your ve ```PowerShell # PS 5.1 (upgrade to latest Pester) -Install-Module Pester -Force -SkipPublisherCheck -Scope CurrentUser -MinimumVersion 5.0.2 +Install-Module Pester -Force -SkipPublisherCheck -Scope CurrentUser -MinimumVersion 5.4.0 # PS 6.0+ (Install Pester under current user) -Install-Module Pester -Scope CurrentUser -MinimumVersion 5.0.2 +Install-Module Pester -Scope CurrentUser -MinimumVersion 5.4.0 ``` ## Getting Started diff --git a/templates/environment-setup.yml b/templates/environment-setup.yml index 634a3f60..682b7e35 100644 --- a/templates/environment-setup.yml +++ b/templates/environment-setup.yml @@ -17,7 +17,7 @@ steps: $Params.Name = 'Pester' $Params.SkipPublisherCheck = $true - $Params.MinimumVersion = '5.0.2' + $Params.MinimumVersion = '5.4.0' $Params | Out-String | Write-Host Install-Module @Params $Params.Remove('SkipPublisherCheck') diff --git a/templates/install-built-module.yml b/templates/install-built-module.yml index 268f4c65..c777aca3 100644 --- a/templates/install-built-module.yml +++ b/templates/install-built-module.yml @@ -28,7 +28,7 @@ steps: script: | $pesterParams = @{ Name = 'Pester' - MinimumVersion = '5.0.2' + MinimumVersion = '5.4.0' ProviderName = 'NuGet' Path = '${{ parameters.repositoryPath }}' Force = $true From 279eb796dbe198a2817f2520b7837b5352fc0ca5 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sat, 18 Feb 2023 23:31:14 -0800 Subject: [PATCH 88/92] Add in sanity debug for file location and contents --- Build/Invoke-ModuleTests.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/Build/Invoke-ModuleTests.ps1 b/Build/Invoke-ModuleTests.ps1 index 92c7f5a5..6faaddfa 100644 --- a/Build/Invoke-ModuleTests.ps1 +++ b/Build/Invoke-ModuleTests.ps1 @@ -1,5 +1,6 @@ $Lines = '-' * 70 +Get-ChildItem -Path $env:PROJECTROOT Import-Module "$env:PROJECTROOT\PSKoans" $PesterVersion = (Get-Module -Name Pester).Version From d937df8669181e338440912beb442ad5a1d6250b Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sat, 18 Feb 2023 23:46:33 -0800 Subject: [PATCH 89/92] Add in proper PSModulePath setting Also remove sanity debug output --- Build/Invoke-ModuleTests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Build/Invoke-ModuleTests.ps1 b/Build/Invoke-ModuleTests.ps1 index 6faaddfa..ac683497 100644 --- a/Build/Invoke-ModuleTests.ps1 +++ b/Build/Invoke-ModuleTests.ps1 @@ -1,7 +1,7 @@ $Lines = '-' * 70 -Get-ChildItem -Path $env:PROJECTROOT -Import-Module "$env:PROJECTROOT\PSKoans" +$env:PSModulePath = "$env:PROJECTROOT" + [IO.Path]::PathSeparator + "$env:PSModulePath" +Import-Module "PSKoans" $PesterVersion = (Get-Module -Name Pester).Version $PSVersion = $PSVersionTable.PSVersion From e13ca21bad2b11f90ff3171a8ff118e984682096 Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sun, 19 Feb 2023 00:10:45 -0800 Subject: [PATCH 90/92] Add docs to test run path --- Build/Invoke-ModuleTests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Build/Invoke-ModuleTests.ps1 b/Build/Invoke-ModuleTests.ps1 index ac683497..a43c0208 100644 --- a/Build/Invoke-ModuleTests.ps1 +++ b/Build/Invoke-ModuleTests.ps1 @@ -15,7 +15,7 @@ try { # Try/Finally required since -CI will exit with exit code on failure. $config = New-PesterConfiguration - $config.Run.Path = "$env:PROJECTROOT\Tests" + $config.Run.Path = @("$env:PROJECTROOT\Tests", "$env:PROJECTROOT\docs") $config.Run.Exit = $true $config.TestResult.Enabled = $true From 6564d356479049853c914f456c731fdc1378110b Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sun, 19 Feb 2023 00:36:25 -0800 Subject: [PATCH 91/92] Generate Help as required by tests Remove unneccesary docs inclusion in tests --- .github/workflows/github.yml | 4 ++++ Build/Invoke-ModuleTests.ps1 | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 7e26b636..158c28e9 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -152,6 +152,10 @@ jobs: shell: pwsh run: ./Build/Initialize-Environment.ps1 + - name: Generate help.xml + shell: pwsh + run: New-ExternalHelp -Path "${{env.PROJECTROOT}}/docs/" -OutputPath "${{env.PROJECTROOT}}/PSKoans/en" + # - name: Register FileSystem Repository # shell: pwsh # run: | diff --git a/Build/Invoke-ModuleTests.ps1 b/Build/Invoke-ModuleTests.ps1 index a43c0208..237c3537 100644 --- a/Build/Invoke-ModuleTests.ps1 +++ b/Build/Invoke-ModuleTests.ps1 @@ -15,7 +15,7 @@ try { # Try/Finally required since -CI will exit with exit code on failure. $config = New-PesterConfiguration - $config.Run.Path = @("$env:PROJECTROOT\Tests", "$env:PROJECTROOT\docs") + $config.Run.Path = @("$env:PROJECTROOT\Tests") $config.Run.Exit = $true $config.TestResult.Enabled = $true From becd594ff2c56416d5b73b97574e78fe1a9f7c0b Mon Sep 17 00:00:00 2001 From: Beau Witter Date: Sun, 19 Feb 2023 00:42:42 -0800 Subject: [PATCH 92/92] Lower output back down to normal Bump download-artifact to v3 to dismiss warning --- .github/workflows/github.yml | 8 ++++---- Build/Invoke-ModuleTests.ps1 | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 158c28e9..3832c379 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -155,7 +155,7 @@ jobs: - name: Generate help.xml shell: pwsh run: New-ExternalHelp -Path "${{env.PROJECTROOT}}/docs/" -OutputPath "${{env.PROJECTROOT}}/PSKoans/en" - + # - name: Register FileSystem Repository # shell: pwsh # run: | @@ -221,7 +221,7 @@ jobs: - uses: actions/checkout@v3 - name: Download Test Artifacts - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: path: artifacts @@ -263,7 +263,7 @@ jobs: - uses: actions/checkout@v3 - name: Download Module Artifact - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: ${{env.ModuleArtifactName}} path: ${{env.BuiltModulePath}} @@ -280,7 +280,7 @@ jobs: "TagName=$tagname" | Add-Content -Path '${{ github.env }}' - name: Download Artifacts - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: path: '${{github.workspace}}/artifacts' diff --git a/Build/Invoke-ModuleTests.ps1 b/Build/Invoke-ModuleTests.ps1 index 237c3537..f585ce0d 100644 --- a/Build/Invoke-ModuleTests.ps1 +++ b/Build/Invoke-ModuleTests.ps1 @@ -20,7 +20,7 @@ try { $config.TestResult.Enabled = $true - $config.Output.Verbosity = "Detailed" + $config.Output.Verbosity = "Normal" $config.CodeCoverage.Enabled = $true $config.CodeCoverage.Path = @("$env:PROJECTROOT\PSKoans\Private", "$env:PROJECTROOT\PSKoans\Public")