Last active
March 24, 2017 06:08
-
-
Save lordmilko/e50c9d15b587ac19a5ff0dfba335ce10 to your computer and use it in GitHub Desktop.
PrtgAPI.CustomSensors Appveyor Config
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
version: 'Build #{build}' | |
install: | |
- ps: cinst pester | |
build_script: | |
- ps: | | |
try | |
{ | |
$version = (Import-PowerShellDataFile .\PrtgAPI.CustomSensors\PrtgAPI.CustomSensors.psd1).ModuleVersion | |
Write-Host "Attempting to set Appveyor build to version '$version'" | |
Update-AppveyorBuild -Version $version | |
} | |
catch { $host.SetShouldExit(1) } | |
test_script: | |
- ps: Invoke-Pester -Path . -EnableExit | |
after_test: | |
- ps: Invoke-WebRequest https://gist.github.com/lordmilko/e50c9d15b587ac19a5ff0dfba335ce10/raw/build_nuget.ps1 -OutFile .\build_nuget.ps1 | |
- ps: | | |
try { .\build_nuget.ps1 } | |
catch { $host.SetShouldExit(1) } | |
artifacts: | |
- path: PrtgAPI.CustomSensors | |
- path: '*.nupkg' | |
skip_commits: | |
files: | |
- README.md |
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
$ProgressPreference = "SilentlyContinue" | |
function Main | |
{ | |
Write-Host -ForegroundColor Cyan "Building Nuget Package" | |
$repoLocation = "$env:TEMP\TempRepository" | |
$projectRoot = "$env:APPVEYOR_BUILD_FOLDER" | |
$outputDir = "$env:APPVEYOR_BUILD_FOLDER\PrtgAPI.CustomSensors" | |
InstallProvider | |
CreateRepo $repoLocation $outputDir | |
CreatePowerShell $outputDir | |
TestPackage | |
if($env:APPVEYOR) | |
{ | |
$pkg = Get-ChildItem $env:temp\TempRepository\*.nupkg | |
if(!$pkg) | |
{ | |
throw "Could not find a nupkg" | |
} | |
Write-Host "Moving package $($pkg.Name) to $env:APPVEYOR_BUILD_FOLDER\$($pkg.Name)" | |
Move-Item $pkg.Fullname "$env:APPVEYOR_BUILD_FOLDER\$($pkg.BaseName)_PowerShell.nupkg" | |
} | |
Write-Host "Unregistering temp repository" | |
Unregister-PSRepository TempRepository | |
Write-Host "Removing temp repository folder" | |
remove-item -Recurse $repoLocation -Force | |
} | |
#region Setup | |
function InstallProvider | |
{ | |
if(!(get-packageprovider|where name -eq nuget)) | |
{ | |
Write-Host "Installing NuGet package provider" | |
install-packageprovider nuget -force | |
} | |
} | |
function CreateRepo($repoPath, $outputDir) | |
{ | |
Write-Host "CreateRepo" | |
if(Test-Path $repoPath) | |
{ | |
Write-Host -ForegroundColor Red "`tRemoving repository folder left over from previous run..." | |
remove-item -Recurse $repoPath -Force | |
} | |
Write-Host "`tCreating repo folder" | |
New-Item -ItemType Directory $repoPath|Out-Null | |
if(get-psrepository|where name -eq TempRepository) | |
{ | |
Write-Host -ForegroundColor Red "`tRemoving repository left over from previous run..." | |
Unregister-PSRepository TempRepository | |
} | |
Write-Host "`tRegistering repo" | |
Register-PSRepository -Name TempRepository -SourceLocation $repoPath -PublishLocation $repoPath -InstallationPolicy Trusted | |
} | |
#endregion | |
function CreatePowerShell($outputDir) | |
{ | |
BackupOutputDir $outputDir | |
gci $outputDir -Filter *.cmd | Remove-Item -Force | |
Write-Host "Publishing module to TempRepository" | |
Publish-Module -Path $outputDir -Repository TempRepository | |
RestoreOutputDir $outputDir | |
} | |
function BackupOutputDir($outputDir) | |
{ | |
Write-Host "Backing up build output" | |
if($outputDir.EndsWith("\")) | |
{ | |
$outputDir = $outputDir.Substring(0, $outputDir.Length - 1) | |
} | |
Copy-Item -Recurse $outputDir "$($outputDir)_bak" | |
} | |
function RestoreOutputDir($outputDir) | |
{ | |
if($outputDir.EndsWith("\")) | |
{ | |
$outputDir = $outputDir.Substring(0, $outputDir.Length - 1) | |
} | |
Write-Host "Restoring build output" | |
gci "$($outputDir)_bak" | foreach { mv $_.FullName "$outputDir\$($_.Name)" -Force } | |
Remove-Item -Recurse -Force "$($outputDir)_bak" | |
} | |
function TestPackage | |
{ | |
Write-Host "Testing package" | |
Write-Host "`tInstalling Package" | |
if(!(Install-Package PrtgAPI.CustomSensors -Source TempRepository)) | |
{ | |
throw "PrtgAPI.CustomSensors did not install properly" | |
} | |
Write-Host "`tValidating function output" | |
$result = try { Prtg { } } catch [exception] { $_.exception.message } | |
$expected = "Prtg block requires an inner element." | |
if($result -ne $expected) | |
{ | |
throw "Expected '$expected' but got '$result'" | |
} | |
} | |
Main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment