forked from pcgeek86/PSGitHub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appveyor.yml
109 lines (90 loc) · 4.66 KB
/
appveyor.yml
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
108
#---------------------------------#
# environment configuration #
#---------------------------------#
# Don't edit this build version - only manifest version number matters.
version: 1.0.0.{build}
environment:
PowerShellGalleryApiKey:
secure: SlvbZKurugx1nGHlyk6VB1dXh3IJOWsY/Ds2bGBpknpze8R3os5pHGmPeyJXHv9K
install:
- ps: |
# Update AppVeyor Build Version by pulling from Manifest
$ManifestPath = Join-Path -Path $ENV:APPVEYOR_BUILD_FOLDER -ChildPath 'PSGitHub.psd1'
$ManifestContent = Get-Content -Path $ManifestPath -Raw
$Regex = '(?<=ModuleVersion\s+=\s+'')(?<ModuleVersion>.*)(?='')'
$Matches = @([regex]::matches($ManifestContent, $Regex, 'IgnoreCase'))
$version = $null
if ($Matches)
{
$version = $Matches[0].Value
}
# new version
$version = "$version.$env:APPVEYOR_BUILD_NUMBER"
# update AppVeyor build
Update-AppveyorBuild -Version $version
# Set version number
$ManifestContent = $ManifestContent -replace '(?<=ModuleVersion\s+=\s+'')(?<ModuleVersion>.*)(?='')', ('${{ModuleVersion}}.{0}' -f $env:APPVEYOR_BUILD_NUMBER)
Set-Content -Path $ManifestPath -Value $ManifestContent
Get-PackageProvider -Name nuget -ForceBootStrap -Force
Install-Module PSScriptAnalyzer -RequiredVersion 1.18.0 -Force
Install-Module Pester -RequiredVersion 4.8.1 -Force -SkipPublisherCheck
#---------------------------------#
# build configuration #
#---------------------------------#
build: false
#---------------------------------#
# test configuration #
#---------------------------------#
test_script:
- ps: |
$testResultsFile = ".\TestsResults.xml"
$res = Invoke-Pester -OutputFormat NUnitXml -OutputFile $testResultsFile -PassThru -ExcludeTag Incomplete
(New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $testResultsFile))
Get-ChildItem "$ENV:APPVEYOR_BUILD_FOLDER\Artifacts\*.*" | Foreach-Object { Push-AppveyorArtifact $_ }
if ($res.FailedCount -gt 0) {
throw "$($res.FailedCount) tests failed."
}
#---------------------------------#
# deployment configuration #
#---------------------------------#
# scripts to run before deployment
deploy_script:
- ps: |
# Creating project artifact
$buildFolder = $ENV:APPVEYOR_BUILD_FOLDER
$StagingFolder = Join-Path -Path $ENV:Temp -ChildPath 'Staging'
$null = New-Item -Path $StagingFolder -Type directory
$ModuleFolder = Join-Path -Path $StagingFolder -ChildPath 'PSGitHub'
$null = New-Item -Path $ModuleFolder -Type directory
$VersionFolder = Join-Path -Path $ModuleFolder -ChildPath $ENV:APPVEYOR_BUILD_VERSION
$null = New-Item -Path $VersionFolder -Type directory
# Populate Version Folder
$null = Copy-Item -Path "$buildFolder\*" -Destination $VersionFolder -Recurse -Exclude '.*','AppVeyor.yml', Screenshots, Assets
# Create and Push zip Artifact
$zipFilePath = Join-Path -Path $buildFolder -ChildPath "${env:APPVEYOR_PROJECT_NAME}_${env:APPVEYOR_BUILD_VERSION}.zip"
$null = Add-Type -assemblyname System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::CreateFromDirectory($StagingFolder, $zipFilePath)
# Create and Push Script Artifact (to help manual publish of project to PSGallery)
$PublishScriptName = $env:APPVEYOR_PROJECT_NAME + "." + $env:APPVEYOR_BUILD_VERSION + "_publish.ps1"
$PublishScriptPath = Join-Path -Path $buildFolder -ChildPath $PublishScriptName
Set-Content -Path $PublishScriptPath -Value "Publish-Module -Name 'PSGitHub' -RequiredVersion ${env:APPVEYOR_BUILD_VERSION} -NuGetApiKey (Read-Host -Prompt 'NuGetApiKey')"
@(
# You can add other artifacts here
$zipFilePath,
$PublishScriptPath
) | % {
Write-Host "Pushing package $_ as Appveyor artifact"
Push-AppveyorArtifact $_
}
# If this is a build of the Master branch and not a PR push
# then publish the Module to the PowerShell Gallery.
if ((! $ENV:APPVEYOR_PULL_REQUEST_NUMBER) `
-and ($ENV:APPVEYOR_REPO_BRANCH -eq 'master'))
{
Write-Host -Object "Publishing Module to PowerShell Gallery"
Copy-Item -Path $ModuleFolder -Destination ($ENV:PSModulePath -split ';')[0] -Recurse
Get-PackageProvider -Name NuGet -ForceBootstrap
Publish-Module -Name 'PSGitHub' -RequiredVersion ${ENV:APPVEYOR_BUILD_VERSION} -NuGetApiKey $ENV:PowerShellGalleryApiKey -Confirm:$false
}
# Remove Staging Folder
$null = Remove-Item -Path $StagingFolder -Recurse -Force