forked from mkellerman/PSTwitterAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PSTwitterAPI.build.ps1
107 lines (85 loc) · 3.43 KB
/
PSTwitterAPI.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<#
.Synopsis
Build script (https://github.com/nightroman/Invoke-Build)
#>
param ($Configuration = 'Development')
#region Set-BuildEnvironment
Try { Set-BuildEnvironment -ErrorAction SilentlyContinue -Force } Catch { }
#endregion
#region use the most strict mode
Set-StrictMode -Version Latest
#endregion
#region Task to run all Pester tests in folder .\tests
task Test {
$OutputPath = New-Item -Path '.\TestResults' -ItemType Directory -Force -Verbose
$PesterParams = @{
Script = '.\Tests'
OutputFile = "${OutputPath}\TestResults-PSTwitterAPI.xml"
CodeCoverage = 'PSTwitterAPI\*\*.ps1'
CodeCoverageOutputFile = "${OutputPath}\CodeCoverage-PSTwitterAPI.xml"
CodeCoverageOutputFileFormat = 'JaCoCo'
}
$Result = Invoke-Pester @PesterParams -PassThru
if ($Result.FailedCount -gt 0) {
throw 'Pester tests failed'
}
}
#endregion
#region Task to update the Module Manifest file with info from the Changelog in Readme.
task UpdateManifest {
# Import PlatyPS. Needed for parsing README for Change Log versions
#Import-Module -Name PlatyPS
$ModuleManifest = Test-ModuleManifest -Path $env:BHPSModuleManifest
[System.Version]$ManifestVersion = $ModuleManifest.Version
Write-Output -InputObject ('Manifest Version : {0}' -f $ManifestVersion)
Try {
$PSGalleryModule = Find-Module -Name $env:BHProjectName -Repository PSGallery
[System.Version]$PSGalleryVersion = $PSGalleryModule.Version
} Catch {
[System.Version]$PSGalleryVersion = '0.0.0'
}
Write-Output -InputObject ('PSGallery Version : {0}' -f $PSGalleryVersion)
If ($PSGalleryVersion -ge $ManifestVersion) {
[System.Version]$Version = New-Object -TypeName System.Version -ArgumentList ($PSGalleryVersion.Major, $PSGalleryVersion.Minor, ($PSGalleryVersion.Build + 1))
Write-Output -InputObject ('Updated Version : {0}' -f $Version)
Update-ModuleManifest -ModuleVersion $Version -Path .\PSTwitterAPI\PSTwitterAPI.psd1 # -ReleaseNotes $ReleaseNotes
}
}
#endregion
#region Task to Publish Module to PowerShell Gallery
task PublishModule -If ($Configuration -eq 'Production') {
Try {
# Publish to gallery with a few restrictions
if(
$env:BHModulePath -and
$env:BHBuildSystem -ne 'Unknown' -and
$env:BHBranchName -eq "master" -and
$env:BHCommitMessage -match '!publish'
)
{
# Build a splat containing the required details and make sure to Stop for errors which will trigger the catch
$params = @{
Path = $env:BHModulePath
NuGetApiKey = $env:NuGetApiKey
ErrorAction = 'Stop'
}
Publish-Module @params
Write-Output -InputObject ('PSTwitterAPI PowerShell Module version published to the PowerShell Gallery')
}
else
{
"Skipping deployment: To deploy, ensure that...`n" +
"`t* You are in a known build system (Current: $ENV:BHBuildSystem)`n" +
"`t* You are committing to the master branch (Current: $ENV:BHBranchName) `n" +
"`t* Your commit message includes !publish (Current: $ENV:BHCommitMessage)" |
Write-Host
}
}
Catch {
throw $_
}
}
#endregion
#region Default Task. Runs Test, UpdateManifest, PublishModule Tasks
task . Test, UpdateManifest, PublishModule
#endregion