2017-09-21 13:32:15 +02:00
|
|
|
<#
|
|
|
|
Define the callsign of you PowerShell Module.
|
|
|
|
Callsign is used to identity:
|
|
|
|
- Module Manifest file name
|
|
|
|
- Artifact File
|
|
|
|
- Git repository name
|
|
|
|
- Module name
|
|
|
|
#>
|
|
|
|
$CALLSIGN = 'PSCredentialStore'
|
2019-01-16 12:55:29 +01:00
|
|
|
Write-Host ("Callsign is: {0}" -f $CALLSIGN) -ForegroundColor Black -BackgroundColor Yellow
|
2017-09-21 13:32:15 +02:00
|
|
|
|
2017-10-23 10:53:52 +02:00
|
|
|
|
|
|
|
Function Invoke-InstallDependencies() {
|
|
|
|
[CmdletBinding()]
|
|
|
|
Param()
|
|
|
|
|
|
|
|
Process {
|
|
|
|
Try {
|
2019-01-16 12:55:29 +01:00
|
|
|
Get-PackageProvider -ListAvailable
|
2017-10-23 10:53:52 +02:00
|
|
|
Install-PackageProvider -Name NuGet -RequiredVersion '2.8.5.208' -Force -Verbose
|
|
|
|
Import-PackageProvider -Name NuGet -RequiredVersion '2.8.5.208' -Force
|
2019-01-16 12:55:29 +01:00
|
|
|
Install-Module -Name 'Pester' -Scope CurrentUser -RequiredVersion '4.4.2' -Force -SkipPublisherCheck -AllowClobber
|
|
|
|
Install-Module -Name 'posh-git' -Scope CurrentUser -RequiredVersion '1.0.0-beta2' -Force -SkipPublisherCheck -AllowClobber -AllowPrerelease
|
2019-02-05 08:37:21 +01:00
|
|
|
Install-Module -Name 'PSCoverage' -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber -RequiredVersion '1.0.78'
|
|
|
|
Import-Module -Name 'Pester', 'posh-git' , 'PSCoverage'
|
2017-10-23 10:53:52 +02:00
|
|
|
}
|
|
|
|
Catch {
|
|
|
|
$MsgParams = @{
|
2019-01-16 12:55:29 +01:00
|
|
|
Message = 'Could not install the required dependencies!'
|
2017-10-23 10:53:52 +02:00
|
|
|
Category = 'Error'
|
2019-01-16 12:55:29 +01:00
|
|
|
Details = $_.Exception.Message
|
2017-10-23 10:53:52 +02:00
|
|
|
}
|
|
|
|
Add-AppveyorMessage @MsgParams
|
|
|
|
Throw $MsgParams.Message
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2017-09-21 13:32:15 +02:00
|
|
|
Function Invoke-AppVeyorBumpVersion() {
|
|
|
|
[CmdletBinding()]
|
|
|
|
Param()
|
|
|
|
|
2019-01-16 12:55:29 +01:00
|
|
|
Write-Host "Listing Env Vars for debugging:" -ForegroundColor Black -BackgroundColor Yellow
|
2017-09-21 13:32:15 +02:00
|
|
|
# Filter Results to prevent exposing secure vars.
|
|
|
|
Get-ChildItem -Path "Env:*" | Where-Object { $_.name -notmatch "(NuGetToken|CoverallsToken)"} | Sort-Object -Property Name | Format-Table
|
|
|
|
|
|
|
|
Try {
|
|
|
|
$ModManifest = Get-Content -Path (".\src\{0}.psd1" -f $CALLSIGN)
|
2019-01-16 12:55:29 +01:00
|
|
|
$BumpedManifest = $ModManifest -replace '0.0.9999', $Env:APPVEYOR_BUILD_VERSION
|
2017-09-21 13:32:15 +02:00
|
|
|
Remove-Item -Path (".\src\{0}.psd1" -f $CALLSIGN)
|
|
|
|
Out-File -FilePath (".\src\{0}.psd1" -f $CALLSIGN) -InputObject $BumpedManifest -NoClobber -Encoding utf8 -Force
|
|
|
|
}
|
|
|
|
Catch {
|
|
|
|
$MsgParams = @{
|
2019-01-16 12:55:29 +01:00
|
|
|
Message = 'Could not bump current version into module manifest.'
|
2017-09-21 13:32:15 +02:00
|
|
|
Category = 'Error'
|
2019-01-16 12:55:29 +01:00
|
|
|
Details = $_.Exception.Message
|
2017-09-21 13:32:15 +02:00
|
|
|
}
|
|
|
|
Add-AppveyorMessage @MsgParams
|
|
|
|
Throw $MsgParams.Message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Function Invoke-AppVeyorBuild() {
|
|
|
|
[CmdletBinding()]
|
2019-01-16 12:55:29 +01:00
|
|
|
[OutputType([PsCustomObject])]
|
2017-09-21 13:32:15 +02:00
|
|
|
Param()
|
|
|
|
$MsgParams = @{
|
2019-01-16 12:55:29 +01:00
|
|
|
Message = 'Creating build artifacts'
|
2017-09-21 13:32:15 +02:00
|
|
|
Category = 'Information'
|
2019-01-16 12:55:29 +01:00
|
|
|
Details = 'Extracting source files and compressing them into zip file.'
|
2017-09-21 13:32:15 +02:00
|
|
|
}
|
|
|
|
Add-AppveyorMessage @MsgParams
|
|
|
|
$CompParams = @{
|
2019-01-16 12:55:29 +01:00
|
|
|
Path = "{0}\src\*" -f $env:APPVEYOR_BUILD_FOLDER
|
2017-09-21 13:32:15 +02:00
|
|
|
DestinationPath = "{0}\bin\{1}.zip" -f $env:APPVEYOR_BUILD_FOLDER, $CALLSIGN
|
2019-01-16 12:55:29 +01:00
|
|
|
Update = $True
|
|
|
|
Verbose = $True
|
2017-09-21 13:32:15 +02:00
|
|
|
}
|
|
|
|
Compress-Archive @CompParams
|
|
|
|
$MsgParams = @{
|
2019-01-16 12:55:29 +01:00
|
|
|
Message = 'Pushing artifacts'
|
2017-09-21 13:32:15 +02:00
|
|
|
Category = 'Information'
|
2019-01-16 12:55:29 +01:00
|
|
|
Details = 'Pushing artifacts to AppVeyor store.'
|
2017-09-21 13:32:15 +02:00
|
|
|
}
|
|
|
|
Add-AppveyorMessage @MsgParams
|
2019-01-16 12:55:29 +01:00
|
|
|
$ArtifactPath = Join-Path -Path '.' -ChildPath ('bin/{0}.zip' -f $CALLSIGN)
|
|
|
|
Push-AppveyorArtifact $ArtifactPath
|
2017-09-21 13:32:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Function Invoke-AppVeyorTests() {
|
|
|
|
[CmdletBinding()]
|
|
|
|
Param()
|
|
|
|
|
|
|
|
$MsgParams = @{
|
2019-01-16 12:55:29 +01:00
|
|
|
Message = 'Starting Pester tests'
|
2017-09-21 13:32:15 +02:00
|
|
|
Category = 'Information'
|
2019-01-16 12:55:29 +01:00
|
|
|
Details = 'Now running all test found in .\tests\ dir.'
|
2017-09-21 13:32:15 +02:00
|
|
|
}
|
|
|
|
Add-AppveyorMessage @MsgParams
|
2019-01-16 12:55:29 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
Write-Host '===== Preload internal private functions =====' -ForegroundColor Black -BackgroundColor Yellow
|
|
|
|
|
|
|
|
$Privates = Get-ChildItem -Path (Join-Path -Path $Env:APPVEYOR_BUILD_FOLDER -ChildPath '/src/Private/*') -Include "*.ps1" -Recurse
|
|
|
|
foreach ($File in $Privates) {
|
|
|
|
if (Test-Path -Path $File.FullName) {
|
|
|
|
. $File.FullName
|
|
|
|
Write-Verbose -Message ('Private function dot-sourced: {0}' -f $File.FullName) -Verbose
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Write-Warning -Message ('Could not find file: {0} !' -f $File.FullName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
$_.Exception.Message | Write-Error
|
|
|
|
throw 'Could not load required private functions!'
|
|
|
|
}
|
|
|
|
|
|
|
|
#$testresults = Invoke-Pester -Path ( Get-ChildItem -Path ".\tests\*.Tests.ps1" -Recurse | Sort-Object -Property Name ) -ExcludeTag 'Disabled' -PassThru
|
|
|
|
$srcFiles = Get-ChildItem -Path ".\src\*.ps1" -Recurse | Sort-Object -Property 'Name' | Select-Object -ExpandProperty 'FullName'
|
|
|
|
$testFiles = Get-ChildItem -Path ".\tests\*.Tests.ps1" -Recurse | Sort-Object -Property 'Name' | Select-Object -ExpandProperty 'FullName'
|
|
|
|
$TestResults = Invoke-Pester -Path $testFiles -CodeCoverage $srcFiles -PassThru
|
|
|
|
ForEach ($Item in $TestResults.TestResult) {
|
2017-09-21 13:32:15 +02:00
|
|
|
Switch ($Item.Result) {
|
|
|
|
"Passed" {
|
|
|
|
$TestParams = @{
|
2019-01-16 12:55:29 +01:00
|
|
|
Name = "{0}: {1}" -f $Item.Context, $Item.Name
|
2017-09-21 13:32:15 +02:00
|
|
|
Framework = "NUnit"
|
2019-01-16 12:55:29 +01:00
|
|
|
Filename = $Item.Describe
|
|
|
|
Outcome = "Passed"
|
|
|
|
Duration = $Item.Time.Milliseconds
|
2017-09-21 13:32:15 +02:00
|
|
|
}
|
|
|
|
Add-AppveyorTest @TestParams
|
|
|
|
}
|
|
|
|
"Failed" {
|
|
|
|
$TestParams = @{
|
2019-01-16 12:55:29 +01:00
|
|
|
Name = "{0}: {1}" -f $Item.Context, $Item.Name
|
|
|
|
Framework = "NUnit"
|
|
|
|
Filename = $Item.Describe
|
|
|
|
Outcome = "Failed"
|
|
|
|
Duration = $Item.Time.Milliseconds
|
|
|
|
ErrorMessage = $Item.FailureMessage
|
2017-09-21 13:32:15 +02:00
|
|
|
ErrorStackTrace = $Item.StackTrace
|
|
|
|
}
|
|
|
|
Add-AppveyorTest @TestParams
|
|
|
|
}
|
|
|
|
Default {
|
|
|
|
$TestParams = @{
|
2019-01-16 12:55:29 +01:00
|
|
|
Name = "{0}: {1}" -f $Item.Context, $Item.Name
|
|
|
|
Framework = "NUnit"
|
|
|
|
Filename = $Item.Describe
|
|
|
|
Outcome = "None"
|
|
|
|
Duration = $Item.Time.Milliseconds
|
|
|
|
ErrorMessage = $Item.FailureMessage
|
2017-09-21 13:32:15 +02:00
|
|
|
ErrorStackTrace = $Item.StackTrace
|
|
|
|
}
|
|
|
|
Add-AppveyorTest @TestParams
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-16 12:55:29 +01:00
|
|
|
If ($TestResults.FailedCount -gt 0) {
|
2017-09-21 13:32:15 +02:00
|
|
|
$MsgParams = @{
|
2019-01-16 12:55:29 +01:00
|
|
|
Message = 'Pester Tests failed.'
|
2017-09-21 13:32:15 +02:00
|
|
|
Category = 'Error'
|
2019-01-16 12:55:29 +01:00
|
|
|
Details = "$($TestResults.FailedCount) tests failed."
|
2017-09-21 13:32:15 +02:00
|
|
|
}
|
|
|
|
Add-AppveyorMessage @MsgParams
|
|
|
|
Throw $MsgParams.Message
|
|
|
|
}
|
|
|
|
|
2019-01-16 12:55:29 +01:00
|
|
|
return $TestResults.CodeCoverage
|
|
|
|
|
2017-09-21 13:32:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Function Invoke-CoverageReport() {
|
|
|
|
[CmdletBinding()]
|
|
|
|
Param(
|
|
|
|
[Parameter(Mandatory = $False)]
|
|
|
|
[ValidateNotNullOrEmpty()]
|
2019-01-16 12:55:29 +01:00
|
|
|
[String]$RepoToken = $Env:CoverallsToken,
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $True)]
|
|
|
|
[ValidateNotNullOrEmpty()]
|
|
|
|
[PSCustomObject]$PesterCoverageReport
|
2017-09-21 13:32:15 +02:00
|
|
|
)
|
|
|
|
|
2019-01-16 12:55:29 +01:00
|
|
|
#$CoverageReport | Format-Custom -Depth 5 | Out-String | Write-Verbose
|
|
|
|
$CoverageReport = New-CoverageReport -CodeCoverage $PesterCoverageReport -RepoToken $RepoToken
|
2017-09-21 13:32:15 +02:00
|
|
|
Write-Host "CoverageReport JSON:" -ForegroundColor Yellow
|
2019-01-16 12:55:29 +01:00
|
|
|
#$CoverageReport | ConvertTo-Json -Depth 5 | Out-String | Write-Verbose
|
2017-09-21 13:32:15 +02:00
|
|
|
Publish-CoverageReport -CoverageReport $CoverageReport
|
|
|
|
}
|
|
|
|
|
|
|
|
Function Invoke-AppVeyorPSGallery() {
|
|
|
|
[CmdletBinding()]
|
2017-10-23 10:53:52 +02:00
|
|
|
Param(
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
[ValidateNotNullOrEmpty()]
|
|
|
|
[String]$OnBranch
|
|
|
|
)
|
2017-09-21 13:32:15 +02:00
|
|
|
Expand-Archive -Path (".\bin\{0}.zip" -f $CALLSIGN) -DestinationPath ("C:\Users\appveyor\Documents\WindowsPowerShell\Modules\{0}\" -f $CALLSIGN) -Verbose
|
|
|
|
Import-Module -Name $CALLSIGN -Verbose -Force
|
2019-01-16 12:55:29 +01:00
|
|
|
Write-Host "Available Package Provider:" -ForegroundColor Black -BackgroundColor Yellow
|
2017-09-21 13:32:15 +02:00
|
|
|
Get-PackageProvider -ListAvailable
|
2019-01-16 12:55:29 +01:00
|
|
|
Write-Host "Available Package Sources:" -ForegroundColor Black -BackgroundColor Yellow
|
2017-09-21 13:32:15 +02:00
|
|
|
Get-PackageSource
|
|
|
|
Try {
|
2019-01-16 12:55:29 +01:00
|
|
|
Write-Host "Try to get NuGet Provider:" -ForegroundColor Black -BackgroundColor Yellow
|
2017-09-21 13:32:15 +02:00
|
|
|
Get-PackageProvider -Name NuGet -ErrorAction Stop
|
|
|
|
}
|
|
|
|
Catch {
|
2019-01-16 12:55:29 +01:00
|
|
|
Write-Host "Installing NuGet..." -ForegroundColor Black -BackgroundColor Yellow
|
2017-09-21 13:32:15 +02:00
|
|
|
Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force -Verbose
|
|
|
|
Import-PackageProvider NuGet -MinimumVersion '2.8.5.201' -Force
|
|
|
|
}
|
|
|
|
Try {
|
|
|
|
If ($env:APPVEYOR_REPO_BRANCH -eq 'master') {
|
2019-01-16 12:55:29 +01:00
|
|
|
Write-Host "try to publish module" -ForegroundColor Black -BackgroundColor Yellow
|
|
|
|
Write-Host ("Callsign is: {0}" -f $CALLSIGN) -ForegroundColor Black -BackgroundColor Yellow
|
|
|
|
Publish-Module -Name $CALLSIGN -NuGetApiKey $env:NuGetToken -Verbose -Force -AllowPrerelease
|
2017-09-21 13:32:15 +02:00
|
|
|
}
|
|
|
|
Else {
|
2019-01-16 12:55:29 +01:00
|
|
|
Write-Host "Skip publishing to PS Gallery because we are on $($env:APPVEYOR_REPO_BRANCH) branch." -ForegroundColor Black -BackgroundColor Yellow
|
2017-09-21 13:32:15 +02:00
|
|
|
# had to remove the publish-Module statement because it would publish although the -WhatIf is given.
|
|
|
|
# Publish-Module -Name $CALLSIGN -NuGetApiKey $env:NuGetToken -Verbose -WhatIf
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Catch {
|
|
|
|
$MsgParams = @{
|
2019-01-16 12:55:29 +01:00
|
|
|
Message = 'Could not deploy module to PSGallery.'
|
2017-09-21 13:32:15 +02:00
|
|
|
Category = 'Error'
|
2019-01-16 12:55:29 +01:00
|
|
|
Details = $_.Exception.Message
|
2017-09-21 13:32:15 +02:00
|
|
|
}
|
2019-01-16 13:02:51 +01:00
|
|
|
$_.Exception.Message | Write-Error
|
2017-09-21 13:32:15 +02:00
|
|
|
Add-AppveyorMessage @MsgParams
|
|
|
|
Throw $MsgParams.Message
|
|
|
|
}
|
|
|
|
}
|