-
Notifications
You must be signed in to change notification settings - Fork 0
/
PSKubeCtx.build.ps1
71 lines (60 loc) · 2.06 KB
/
PSKubeCtx.build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
param(
$RepositoryName = 'PSGallery',
$NuGetApiKey,
$Editor
)
$moduleName = 'PSKubeCtx'
$buildDest = Join-Path $BuildRoot "build\$moduleName"
# Synopsis: Clean the build destination folder
task Clean {
Remove-Item -Force -Recurse $buildDest -ErrorAction SilentlyContinue
}
# Synopsis: Create the build destination folder
task CreateOutputFolder {
New-Item -ItemType Directory $buildDest -Force | Out-Null
}
# Synopsis: Copy module files to the build destination folder
task CopyToOutput @{
Partial = $true
Inputs = {
# From this scriptblock, return the files to to copy to the destination folder.
Get-ChildItem -Path "$BuildRoot\src" -Recurse -File
Get-Item -Path "$BuildRoot\$moduleName.psd1"
Get-Item -Path "$BuildRoot\$moduleName.psm1"
Get-Item -Path "$BuildRoot\Configuration.psd1"
}
Outputs = {
process { $_.Replace($BuildRoot, $buildDest) }
}
Jobs = {
begin {
# Create empty directories
$Outputs | Split-Path -Parent | Select-Object -Unique | ForEach-Object { mkdir -Force $_ } | Out-Null
}
process { Copy-Item $_ $2 }
}
}
# Synopsis: Build the module
task Build CreateOutputFolder, CopyToOutput
# Synopsis: Run Pester tests
task Test Build, {
Remove-Module -Name $moduleName -Force -ErrorAction SilentlyContinue
Import-Module $buildDest
$pesterOption = if ($Editor -eq 'VSCode') {
@{ IncludeVSCodeMarker = $true }
}
else {
@{}
}
Invoke-Pester -PesterOption $pesterOption
}
# Synopsis: Publish the module to the PowerShell Gallery
task Publish Clean, Build, Test, {
$manifestPath = Join-Path $buildDest "$moduleName.psd1"
$manifest = Test-ModuleManifest $manifestPath
# Ensure the version number has been updated
Test-ModulePublished -Name $moduleName -Version $manifest.Version -Repository $RepositoryName -AssertUnpublished | Out-Null
Publish-Module -Verbose -Path $buildDest -NuGetApiKey (property NuGetApiKey) -Repository $RepositoryName
}
# Synopsis: Default task
Task . Test