-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Task -
Package_Wiki_Content
(#144)
- Loading branch information
1 parent
bb39323
commit 589ccbd
Showing
11 changed files
with
217 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<# | ||
.SYNOPSIS | ||
This is the alias to the build task Package_Wiki_Content's script file. | ||
.DESCRIPTION | ||
This makes available the alias 'Task.Package_Wiki_Content' that is | ||
exported in the module manifest so that the build task can be correctly | ||
imported using for example Invoke-Build. | ||
.NOTES | ||
This is using the pattern lined out in the Invoke-Build repository | ||
https://github.com/nightroman/Invoke-Build/tree/master/Tasks/Import. | ||
#> | ||
|
||
Set-Alias -Name 'Task.Package_Wiki_Content' -Value "$PSScriptRoot/tasks/Package_Wiki_Content.build.ps1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<# | ||
.SYNOPSIS | ||
This is a build task that generates conceptual help. | ||
.PARAMETER OutputDirectory | ||
The base directory of all output. Defaults to folder 'output' relative to | ||
the $BuildRoot. | ||
.PARAMETER ProjectName | ||
The project name. Defaults to the Project Name. | ||
.PARAMETER BuildInfo | ||
The build info object from ModuleBuilder. Defaults to an empty hashtable. | ||
.NOTES | ||
This is a build task that is primarily meant to be run by Invoke-Build but | ||
wrapped by the Sampler project's build.ps1 (https://github.com/gaelcolas/Sampler). | ||
#> | ||
|
||
param | ||
( | ||
[Parameter()] | ||
[System.String] | ||
$OutputDirectory = (property OutputDirectory (Join-Path $BuildRoot 'output')), | ||
|
||
[Parameter()] | ||
[System.String] | ||
$ProjectName = (property ProjectName $(Get-SamplerProjectName -BuildRoot $BuildRoot)), | ||
|
||
[Parameter()] | ||
[System.Collections.Hashtable] | ||
$BuildInfo = (property BuildInfo @{ }) | ||
) | ||
|
||
# Synopsis: Package wiki documentation for the DSC resources. | ||
task Package_Wiki_Content { | ||
# Get the values for task variables, see https://github.com/gaelcolas/Sampler#task-variables. | ||
. Set-SamplerTaskVariable | ||
|
||
"`tProject Name = {0}" -f $ProjectName | ||
"`tOutput Directory = {0}" -f $OutputDirectory | ||
|
||
$wikiOutputPath = Join-Path -Path $OutputDirectory -ChildPath 'WikiContent' | ||
$wikiArchiveSourcePath = Join-Path -Path $wikiOutputPath -ChildPath '*' | ||
$wikiPackagePath = Join-Path -Path $OutputDirectory -ChildPath 'WikiContent.zip' | ||
|
||
"`tWiki Output Path = $wikiOutputPath" | ||
"`tWiki Archive Source Path = $wikiArchiveSourcePath" | ||
"`tWiki Package Path = $wikiPackagePath" | ||
|
||
if (-not (Test-Path -Path $wikiOutputPath)) | ||
{ | ||
throw 'The Wiki Output Path does not exist. Please run the task Generate_Wiki_Content prior to running this task.' | ||
} | ||
|
||
Write-Build Magenta 'Packaging Wiki content.' | ||
|
||
# Overwrites any existing archive. | ||
Compress-Archive -Path $wikiArchiveSourcePath -DestinationPath $wikiPackagePath -CompressionLevel 'Optimal' -Force -ErrorAction 'Stop' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#region HEADER | ||
$script:projectPath = "$PSScriptRoot\..\..\.." | Convert-Path | ||
$script:projectName = (Get-ChildItem -Path "$script:projectPath\*\*.psd1" | Where-Object -FilterScript { | ||
($_.Directory.Name -match 'source|src' -or $_.Directory.Name -eq $_.BaseName) -and | ||
$(try | ||
{ | ||
Test-ModuleManifest -Path $_.FullName -ErrorAction Stop | ||
} | ||
catch | ||
{ | ||
$false | ||
}) | ||
}).BaseName | ||
|
||
$script:moduleName = Get-Module -Name $script:projectName -ListAvailable | Select-Object -First 1 | ||
Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue' | ||
|
||
Import-Module $script:moduleName -Force -ErrorAction 'Stop' | ||
#endregion HEADER | ||
|
||
Describe 'Package_Wiki_Content' { | ||
BeforeAll { | ||
Mock -CommandName Compress-Archive | ||
} | ||
|
||
It 'Should export the build script alias' { | ||
$buildTaskName = 'Package_Wiki_Content' | ||
$buildScriptAliasName = 'Task.{0}' -f $buildTaskName | ||
|
||
$script:buildScript = Get-Command -Name $buildScriptAliasName -Module $script:projectName | ||
|
||
$script:buildScript.Name | Should -Be $buildScriptAliasName | ||
$script:buildScript.ReferencedCommand | Should -Be ('{0}.build.ps1' -f $buildTaskName) | ||
} | ||
|
||
It 'Should reference an existing build script' { | ||
Test-Path -Path $script:buildScript.Definition | Should -BeTrue | ||
} | ||
|
||
Context 'When path is valid' { | ||
BeforeAll { | ||
Mock -CommandName Test-Path -MockWith { | ||
return $true | ||
} | ||
} | ||
|
||
It 'Should run the build task without throwing' { | ||
{ | ||
$taskParameters = @{ | ||
ProjectName = 'DscResource.DocGenerator' | ||
OutputDirectory = $TestDrive.FullName | ||
} | ||
|
||
Invoke-Build -Task $buildTaskName -File $script:buildScript.Definition @taskParameters | ||
} | Should -Not -Throw | ||
|
||
Assert-MockCalled -CommandName Test-Path -Exactly -Times 2 -Scope It | ||
Assert-MockCalled -CommandName Compress-Archive -Exactly -Times 1 -Scope It | ||
} | ||
} | ||
|
||
Context 'When path is invalid' { | ||
BeforeAll { | ||
Mock -CommandName Test-Path -MockWith { | ||
return $false | ||
} | ||
} | ||
|
||
It 'Should run the build task and throw' { | ||
{ | ||
$taskParameters = @{ | ||
ProjectName = 'DscResource.DocGenerator' | ||
OutputDirectory = $TestDrive.FullName | ||
} | ||
|
||
Invoke-Build -Task $buildTaskName -File $script:buildScript.Definition @taskParameters | ||
} | Should -Throw | ||
|
||
Assert-MockCalled -CommandName Test-Path -Exactly -Times 2 -Scope It | ||
} | ||
} | ||
} |