Skip to content

Commit

Permalink
tweak appveyor abstractions, [releaseme]
Browse files Browse the repository at this point in the history
  • Loading branch information
RamblingCookieMonster committed Sep 12, 2015
1 parent 8ac7a40 commit bf72cdc
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 122 deletions.
6 changes: 6 additions & 0 deletions Tests/Helpers/Initialize-PesterPath.ps1
@@ -0,0 +1,6 @@
# When performing both PS2 and PS5 tests, use this from PS5 to save the path to the Pester module
# We then use that path in PS2
# cinst seems to fail, presumably pester is found, in a path PS2 doesn't like

$PesterPath = @( (Get-Module Pester -ListAvailable).Path )[0]
[Environment]::SetEnvironmentVariable("PesterPath", $PesterPath, "Machine")
36 changes: 36 additions & 0 deletions Tests/Helpers/Invoke-PSGalleryDeployment.ps1
@@ -0,0 +1,36 @@
$Verbose = @{}
if($env:APPVEYOR_REPO_BRANCH -and $env:APPVEYOR_REPO_BRANCH -notlike "master")
{
$Verbose.add("Verbose",$True)
}

# Deploy!

if($ENV:APPVEYOR_REPO_COMMIT_MESSAGE -notmatch '\[ReleaseMe\]')
{
Write-Verbose 'Skipping deployment, include [ReleaseMe] in your commit message to deploy.'
}
elseif($env:APPVEYOR_REPO_BRANCH -notlike 'master')
{
Write-Verbose 'Skipping deployment, not master!'
}
else
{

$PublishParams = @{
Path = Join-Path $ENV:APPVEYOR_BUILD_FOLDER $ENV:ModuleName
NuGetApiKey = $ENV:NugetApiKey
}
if($ENV:ReleaseNotes) { $PublishParams.ReleaseNotes = $ENV:ReleaseNotes }
if($ENV:LicenseUri) { $PublishParams.LicenseUri = $ENV:LicenseUri }
if($ENV:ProjectUri) { $PublishParams.ProjectUri = $ENV:ProjectUri }
if($ENV:Tags)
{
# split it up, remove whitespace
$PublishParams.Tags = $ENV:Tags -split ',' | where { $_ } | foreach {$_.trim()}
}

#Publish!
Publish-Module @PublishParams
}

53 changes: 53 additions & 0 deletions Tests/Helpers/Invoke-PesterFromAppveyor.ps1
@@ -0,0 +1,53 @@
#Initialize some variables, move to the project root
$ProjectRoot = $ENV:APPVEYOR_BUILD_FOLDER
$Timestamp = Get-date -uformat "%Y%m%d-%H%M%S"
$PSVersion = $PSVersionTable.PSVersion.Major
$TestFile = "TestResults_PS$PSVersion`_$TimeStamp.xml"

$Address = "https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)"
Set-Location $ProjectRoot

$Verbose = @{}
if($env:APPVEYOR_REPO_BRANCH -and $env:APPVEYOR_REPO_BRANCH -notlike "master")
{
$Verbose.add("Verbose",$True)
}

# Load up Pester
# PS less than 4? Load from the path we found
if($PSVersionTable.PSVersion.Major -lt 4)
{
$PesterPath = [Environment]::GetEnvironmentVariable("PesterPath","Machine")
if(Test-Path $PesterPath)
{
Import-Module $PesterPath
}
else
{
Throw "Where is pester! '$PesterPath' not found"
}
}
# cinst didn't seem to work, install a new flavor and import it.
elseif(-not (Get-Module Pester -ListAvailable))
{
$null = Install-Module Pester -Force -Confirm:$False
Import-Module Pester -force
}
# Module is there, import it
else
{
Import-Module Pester -force
}

#Run a test with the current version of PowerShell, upload results
"`n`tSTATUS: Testing with PowerShell $PSVersion"

Invoke-Pester @Verbose -Path "$ProjectRoot\Tests" -OutputFormat NUnitXml -OutputFile "$ProjectRoot\$TestFile" -PassThru |
Export-Clixml -Path "$ProjectRoot\PesterResults_PS$PSVersion`_$Timestamp.xml"

If($env:APPVEYOR_JOB_ID)
{
(New-Object 'System.Net.WebClient').UploadFile( $Address, "$ProjectRoot\$TestFile" )
}


37 changes: 37 additions & 0 deletions Tests/Helpers/Read-PesterOutput.ps1
@@ -0,0 +1,37 @@
#If finalize is specified, display errors and fail build if we ran into any

#Show status...
$ProjectRoot = $ENV:APPVEYOR_BUILD_FOLDER
$AllFiles = Get-ChildItem -Path $ProjectRoot\PesterResults*.xml | Select -ExpandProperty FullName
"`n`tSTATUS: Finalizing results"
"COLLATING FILES:`n$($AllFiles | Out-String)"

#What failed?
$Results = @( Get-ChildItem -Path "$ProjectRoot\PesterResults_PS*.xml" | Import-Clixml )

$FailedCount = $Results |
Select -ExpandProperty FailedCount |
Measure-Object -Sum |
Select -ExpandProperty Sum

if ($FailedCount -gt 0) {

$FailedItems = $Results |
Select -ExpandProperty TestResult |
Where {$_.Passed -notlike $True}

"FAILED TESTS SUMMARY:"
$FailedItems | ForEach-Object {
$Item = $_
[pscustomobject]@{
Describe = $Item.Describe
Context = $Item.Context
Name = "It $($Item.Name)"
Result = $Item.Result
}
} |
Sort Describe, Context, Name, Result |
Format-List

throw "$FailedCount tests failed."
}
118 changes: 0 additions & 118 deletions Tests/appveyor.pester.ps1

This file was deleted.

13 changes: 9 additions & 4 deletions appveyor.yml
Expand Up @@ -30,9 +30,14 @@ build_script:

# Test with native PS and PS version 2. Upload test results
test_script:
# Comment out this line to avoid testing in PSv2
- ps: powershell.exe -version 2.0 -executionpolicy bypass -noprofile -file .\Tests\appveyor.pester.ps1 -Test
- ps: . .\Tests\appveyor.pester.ps1 -Test -Finalize
# Set up pester path for PSv2
- ps: . .\Tests\Helpers\Initialize-PesterPath.ps1
# Test in PSv2
- ps: powershell.exe -version 2.0 -executionpolicy bypass -noprofile -file .\Tests\Helpers\Invoke-PesterFromAppveyor.ps1
# Test in native PS
- ps: . .\Tests\Helpers\Invoke-PesterFromAppveyor.ps1
# Collect all test results, fail if any failures
- ps: . .\Tests\Helpers\Read-PesterOutput.ps1

# zipped package for delivery
artifacts:
Expand All @@ -41,4 +46,4 @@ artifacts:
# Duct tape, until this is implemented:
# https://github.com/appveyor/ci/issues/128
deploy_script:
- ps: . .\Tests\appveyor.pester.ps1 -Deploy
- ps: . .\Tests\Helpers\Invoke-PSGalleryDeployment.ps1

0 comments on commit bf72cdc

Please sign in to comment.