-
Notifications
You must be signed in to change notification settings - Fork 10
/
PoshNotify.build.ps1
63 lines (49 loc) · 1.67 KB
/
PoshNotify.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
<#
.Synopsis
Build script (https://github.com/nightroman/Invoke-Build)
#>
# Thanks to Stephan Stranger
# https://stefanstranger.github.io/2018/12/30/UseAzurePipelinesToPublishPowerShellModule/
param ($Configuration = 'Development')
#region use the most strict mode
Set-StrictMode -Version Latest
#endregion
#region Task to Copy PowerShell Module files to output folder for release as Module
task CopyModuleFiles {
# Copy Module Files to Output Folder
if (-not (Test-Path .\output\PoshNotify)) {
$null = New-Item -Path .\output\PoshNotify -ItemType Directory
}
Copy-Item -Path '.\src\*' -Filter *.* -Recurse -Destination .\output\PoshNotify -Force
# Copy Module README file
Copy-Item -Path '.\README.md' -Destination .\output\PoshNotify -Force
}
#endregion
#region Task to Publish Module to PowerShell Gallery
task PublishModule -If ($Configuration -eq 'Production') {
Try {
# Build a splat containing the required details and make sure to Stop for errors which will trigger the catch
$params = @{
Path = ('{0}\Output\PoshNotify' -f $PSScriptRoot )
NuGetApiKey = $env:psgallery
ErrorAction = 'Stop'
}
Publish-Module @params
Write-Output -InputObject ('PoshNotify PowerShell Module version published to the PowerShell Gallery')
}
Catch {
throw $_
}
}
#endregion
#region Task clean up Output folder
task Clean {
# Clean output folder
if ((Test-Path .\output)) {
Remove-Item -Path .\Output -Recurse -Force
}
}
#endregion
#region Default Task. Runs Clean, Test, CopyModuleFiles Tasks
task . Clean, Test, CopyModuleFiles, PublishModule
#endregion