-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappveyor.yml
More file actions
189 lines (164 loc) · 8.84 KB
/
appveyor.yml
File metadata and controls
189 lines (164 loc) · 8.84 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#---------------------------------#
# environment configuration #
#---------------------------------#
version: 1.0.0.{build}
environment:
PowerShellGalleryApiKey:
secure: 3fXfDuds8yhTa7WTOLIEhytrpsej9kcP+4rPrgLaFVmIhimmc+FgUVxkR4u468LH
GitHubPushFromPlagueHO:
secure: b/CtRX2iDdREmV5mOgoqK9g6HObrPhjNkjeTxrYMgJbiYYmzvivV1Xp52M79NxDN
install:
- ps: |
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module -Name Pester -Repository PSGallery -Force
Install-Module -Name PSScriptAnalyzer -Repository PSGallery -Force
# Update AppVeyor Build Version by pulling from Manifest
$ManifestPath = Join-Path -Path $ENV:APPVEYOR_BUILD_FOLDER -ChildPath 'DSCTools.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
}
# Determine the new version number
$versionArray = $version -split '\.'
$newVersion = ''
Foreach ($ver in (0..2)) {
$sem = $versionArray[$ver]
if ([String]::IsNullOrEmpty($sem)) {
$sem = '0'
}
$newVersion += "$sem."
}
$newVersion += $env:APPVEYOR_BUILD_NUMBER
# update AppVeyor build
Update-AppveyorBuild -Version $newVersion
# Set the new version number in the Module Manifest
$manifestContent = $ManifestContent -replace '(?<=ModuleVersion\s+=\s+'')(?<ModuleVersion>.*)(?='')', $newVersion
Set-Content -Path $ManifestPath -Value $ManifestContent -NoNewLine
# Set the new version number in the CHANGELOG.md
$changeLogPath = Join-Path -Path $ENV:APPVEYOR_BUILD_FOLDER -ChildPath 'CHANGELOG.md'
$changeLogContent = Get-Content -Path $changeLogPath -Raw
$changeLogContent = $changeLogContent -replace '# Unreleased', "# $newVersion"
Set-Content -Path $changeLogPath -Value $changeLogContent -NoNewLine
Install-WindowsFeature -Name hyper-v-powershell
#---------------------------------#
# build configuration #
#---------------------------------#
build: false
#---------------------------------#
# test configuration #
#---------------------------------#
test_script:
- ps: |
$testResultsFile = ".\TestsResults.xml"
$results = Invoke-Pester `
-OutputFormat NUnitXml `
-OutputFile $testResultsFile `
-PassThru `
-ExcludeTag Incomplete `
-CodeCoverage @( Join-Path -Path $env:APPVEYOR_BUILD_FOLDER -ChildPath 'DSCTools.psm1' )
if ($results.CodeCoverage)
{
Write-Host -Message 'Uploading CodeCoverage to CodeCov.io...'
Import-Module -Name (Join-Path -Path $env:APPVEYOR_BUILD_FOLDER -ChildPath '.codecovio\CodeCovio.psm1')
$jsonPath = Export-CodeCovIoJson -CodeCoverage $results.CodeCoverage -repoRoot $env:APPVEYOR_BUILD_FOLDER
Invoke-UploadCoveCoveIoReport -Path $jsonPath
}
else
{
Write-Warning -Message 'Could not create CodeCov.io report because pester results object did not contain a CodeCoverage object'
}
(New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $testResultsFile))
if ($results.FailedCount -gt 0) {
throw "$($results.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 $buildFolder -ChildPath 'Staging'
$null = New-Item -Path $StagingFolder -Type directory
$ModuleFolder = Join-Path -Path $StagingFolder -ChildPath 'DSCTools'
$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 (Join-Path -Path $buildFolder -ChildPath 'DSCTools.psd1') -Destination $VersionFolder
$null = Copy-Item -Path (Join-Path -Path $buildFolder -ChildPath 'DSCTools.psm1') -Destination $VersionFolder
$null = Copy-Item -Path (Join-Path -Path $buildFolder -ChildPath 'LICENSE') -Destination $VersionFolder
$null = Copy-Item -Path (Join-Path -Path $buildFolder -ChildPath 'README.md') -Destination $VersionFolder
$null = Copy-Item -Path (Join-Path -Path $buildFolder -ChildPath 'CHANGELOG.md') -Destination $VersionFolder
$null = Copy-Item -Path (Join-Path -Path $buildFolder -ChildPath 'Examples') -Destination $VersionFolder -Recurse
$null = Copy-Item -Path (Join-Path -Path $buildFolder -ChildPath 'Configuration') -Destination $VersionFolder -Recurse
# Copy the module to the PSModulePath
$PSModulePath = ($ENV:PSModulePath -split ';')[0]
Write-Host "Copying Module to $PSModulePath"
Copy-Item -Path $ModuleFolder -Destination $PSModulePath -Recurse -Verbose
# Create 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)
# Remove the Staging folder
$null = Remove-Item -Path $StagingFolder -Recurse -Force
# Create Publish Script Artifact
$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 'DSCTools' -RequiredVersion ${env:APPVEYOR_BUILD_VERSION} -NuGetApiKey (Read-Host -Prompt 'NuGetApiKey')"
@(
# You can add other artifacts here
$zipFilePath,
$PublishScriptPath,
$testResultsFile
) | % {
Write-Host "Pushing package $_ as Appveyor artifact"
Push-AppveyorArtifact $_
Remove-Item -Path $_ -Force
}
# If this is a build of the Master branch and not a PR push
# then publish the Module to the PowerShell Gallery.
# Deployment management
if ($ENV:APPVEYOR_REPO_BRANCH -eq 'master') {
if ($ENV:APPVEYOR_PULL_REQUEST_NUMBER) {
# This is a PR so do nothing
} elseif ($ENV:APPVEYOR_REPO_COMMIT_MESSAGE -like '* Deploy!') {
# This was a deploy commit so no need to do anything
} else {
# This is not a PR so deploy
Write-Host "Beginning deploy process"
# Pull the master branch, update the readme.md and manifest
Set-Location -Path $ENV:APPVEYOR_BUILD_FOLDER
& git @('config','--global','credential.helper','store')
Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:GitHubPushFromPlagueHO):x-oauth-basic@github.com`n"
& git @('config','--global','user.email','plagueho@gmail.com')
& git @('config','--global','user.name','Daniel Scott-Raynsford')
& git @('checkout','-f','master')
Set-Content -Path $ManifestPath -Value $ManifestContent
Set-Content -Path $changeLogPath -Value $changeLogContent
# Update the master branch
Write-Host "Pushing deployment changes to Master"
& git @('add','.')
& git @('commit','-m',"$NewVersion Deploy!")
& git @('status')
& git @('push','origin','master')
# Create the version tag and push it
Write-Host "Pushing $newVersion tag to Master"
& git @('tag','-a',$newVersion,'-m',$newVersion)
& git @('push','origin',$newVersion)
# Merge the changes to the Dev branch as well
Write-Host "Pushing deployment changes to Dev"
& git @('checkout','-f','dev')
& git @('merge','master')
& git @('push','origin','dev')
# This is a commit to Master
Write-Host "Publishing Module to PowerShell Gallery"
Get-PackageProvider -Name NuGet -ForceBootstrap
Publish-Module -Name 'DSCTools' -RequiredVersion $newVersion -NuGetApiKey $ENV:PowerShellGalleryApiKey -Confirm:$false
}
}