-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPosh-YNAB.Build.ps1
64 lines (56 loc) · 2.48 KB
/
Posh-YNAB.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
[cmdletBinding()]
param(
[String]$Phase,
[Switch]$WhatIf
)
Switch ($Phase) {
'Install' {
# https://github.com/rubrikinc/PowerShell-Module/blob/master/tests/install.ps1
[string[]]$PowerShellModules = @("Pester", "posh-git", "platyPS", "InvokeBuild")
[string[]]$PackageProviders = @('NuGet', 'PowerShellGet')
#[string[]]$ChocolateyPackages = @('nodejs', 'calibre')
#[string[]]$NodeModules = @('gitbook-cli', 'gitbook-summary')
# Line break for readability in AppVeyor console
Write-Host -Object ''
# Install package providers for PowerShell Modules
ForEach ($Provider in $PackageProviders) {
If (!(Get-PackageProvider $Provider -ErrorAction SilentlyContinue)) {
$null = Install-PackageProvider $Provider -Force -ForceBootstrap -Scope CurrentUser
}
}
# Install the PowerShell Modules
ForEach ($Module in $PowerShellModules) {
If (!(Get-Module -ListAvailable $Module -ErrorAction SilentlyContinue)) {
Install-Module $Module -Scope CurrentUser -Force -Repository PSGallery
}
Import-Module $Module
}
# Install Chocolatey
#Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
# Install Chocolatey packages
#ForEach ($Package in $ChocolateyPackages) {choco install $Package -y --no-progress}
# Install Node packages
#ForEach ($Module in $NodeModules) {npm install -g $Module}
}
'Test' {
# Update the build version to match the module version, append the commit ID
$commit = $env:APPVEYOR_REPO_COMMIT.Substring(0,8)
$moduleInfo = Import-PowerShellDataFile -Path .\Posh-YNAB\Posh-YNAB.psd1
Update-AppveyorBuild -Version "$($moduleInfo.ModuleVersion)-$commit"
# Run the pester tests
$res = Invoke-Pester -Path ".\Tests" -OutputFormat NUnitXml -OutputFile TestsResults.xml -PassThru
(New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\TestsResults.xml))
if ($res.FailedCount -gt 0) {
throw "$($res.FailedCount) tests failed."
}
}
'Deploy' {
# Deploy the module
try {
Publish-Module -Path .\Posh-YNAB\ -NugetApiKey $ENV:PSGalleryAPIKey -WhatIf:$WhatIf
}
catch {
throw $error[0]
}
}
}