forked from MSAdministrator/PSDigitalOcean
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappveyor.yml
131 lines (119 loc) · 6.45 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# YAML Reference Guide: https://www.appveyor.com/docs/appveyor-yml/
# Environmental Variables Guide: https://www.appveyor.com/docs/environment-variables/
# YAML Validator: https://ci.appveyor.com/tools/validate-yaml
# Disable automatic builds
# Without this, the following error shows up:
# "Specify a project or solution file. The directory does not contain a project or solution file."
build: off
# Version number
version: 1.0.0.{build}
# branches to build
branches:
# whitelist
only:
- master
skip_branch_with_pr: true
init:
- git config --global core.autocrlf input
# Ignore testing a commit if only the README.md file changed
# Or if various strings are found in the commit message: updated readme, update readme, update docs, update version, update appveyor
skip_commits:
files:
- README.md
message: /updated readme.*|update readme.*s|update docs.*|update version.*|update appveyor.*/
# There's no need to alter the build number for a Pull Request (PR) since they don't modify anything
pull_requests:
do_not_increment_build_number: true
#Publish to PowerShell Gallery with this key
environment:
project_name: PSDigitalOcean
creator_name: MSAdministrator
NuGetApiKey:
secure: WDLA88mpIaa4q4If+kY8AeJKZr12zjRZmePooBAaT8AxOk9HG+qaA2KFWq+G2vpI
GitHubKey:
secure: Efl6xdTToJDEnOwufIMKcV9pC4Qabo6FFEMGQofWLPPvwfea71v90bawmwGlr2t
# Install NuGet to interact with the PowerShell Gallery
install:
- ps: . .\install.ps1
# Invoke Pester to run all of the unit tests, then save the results into XML in order to populate the AppVeyor tests section
# If any of the tests fail, consider the pipeline failed
test_script:
- ps: |
$res = Invoke-Pester -Path ".\Tests" -OutputFormat NUnitXml -OutputFile TestsResults.xml -PassThru
(New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\TestsResults.xml))
if ($res.FailedCount -gt 0) { throw "$($res.FailedCount) tests failed."}
before_deploy:
- ps: |
# Make sure we're using the Master branch and that it's not a pull request
# Environmental Variables Guide: https://www.appveyor.com/docs/environment-variables/
if ($env:APPVEYOR_REPO_BRANCH -ne 'master') {
Write-Warning -Message "Skipping version increment and publish for branch $env:APPVEYOR_REPO_BRANCH"
}
elseif ($env:APPVEYOR_PULL_REQUEST_NUMBER -gt 0) {
Write-Warning -Message "Skipping version increment and publish for pull request #$env:APPVEYOR_PULL_REQUEST_NUMBER"
}
else {
# We're going to add 1 to the revision value since a new commit has been merged to Master
# This means that the major / minor / build values will be consistent across GitHub and the Gallery
# This is where the module manifest lives
$manifestPath = ".\$env:project_name\$env:project_name.psd1"
# Start by importing the manifest to determine the version, then add 1 to the revision
$manifest = Test-ModuleManifest -Path $manifestPath
[System.Version]$version = $manifest.Version
Write-Output "Old Version: $version"
[String]$env:newVersion = New-Object -TypeName System.Version -ArgumentList ($version.Major, $version.Minor, $version.Build, $env:APPVEYOR_BUILD_NUMBER)
Write-Output "New Version: $env:newVersion"
# Update the manifest with the new version value and fix the weird string replace bug
$functionList = ((Get-ChildItem -Path .\$env:project_name\Public).BaseName)
$splat = @{
'Path' = $manifestPath
'ModuleVersion' = $env:newVersion
'FunctionsToExport' = $functionList
'Copyright' = "(c) 2015-$( (Get-Date).Year ) $env:creator_name. All rights reserved."
}
Update-ModuleManifest @splat
(Get-Content -Path $manifestPath) -replace "PSGet_$env:project_name", "$env:project_name" | Set-Content -Path $manifestPath
(Get-Content -Path $manifestPath) -replace 'NewManifest', $env:project_name | Set-Content -Path $manifestPath
(Get-Content -Path $manifestPath) -replace 'FunctionsToExport = ', 'FunctionsToExport = @(' | Set-Content -Path $manifestPath -Force
(Get-Content -Path $manifestPath) -replace "$($functionList[-1])'", "$($functionList[-1])')" | Set-Content -Path $manifestPath -Force}
- ps: |
# Create new markdown and XML help files
Write-Host "Building new module documentation" -ForegroundColor Yellow
Import-Module ".\$env:project_name\$env:project_name.psm1" -Force
New-MarkdownHelp -Module "$env:project_name" -OutputFolder '.\docs\' -Force
New-ExternalHelp -Path '.\docs\' -OutputPath ".\$env:project_name\en-US\" -Force
. .\docs.ps1
Write-Host -Object ''
artifacts:
- path: docs
- path: en-US
- path: TestsResults.xml
deploy_script:
- ps: |
# Build a splat containing the required details and make sure to Stop for errors which will trigger the catch
$PM = @{
Path = ".\PSDigitalOcean"
NuGetApiKey = $env:NuGetApiKey
ErrorAction = 'Stop'
Tags = @('DigitalOcean', 'Digital Ocean', 'API', 'PowerShell', 'PowerShell Core')
LicenseUri = "https://github.com/MSAdministrator/PSDigitalOcean/blob/master/LICENSE.md"
ProjectUri = "https://github.com/MSAdministrator/PSDigitalOcean"
ReleaseNotes = 'Initial release to the PowerShell Gallery'
}
Publish-Module @PM
Write-Host "PSDigitalOcean PowerShell Module version $env:newVersion published to the PowerShell Gallery." -ForegroundColor Cyan
on_success:
- ps: |
# Set up a path to the git.exe cmd, import posh-git to give us control over git, and then push changes to GitHub
# Note that "update version" is included in the appveyor.yml file's "skip a build" regex to avoid a loop
$env:Path += ";$env:ProgramFiles\Git\cmd"
Import-Module posh-git -ErrorAction Stop
- git config --global credential.helper store
- ps: Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:GitHubKey):[email protected]`n" -Force
- git config --global user.email "[email protected]"
- git config --global user.name "MSAdministrator"
- git add --all
- git status
- git commit -s -m "Update version to $env:newVersion"
- git push origin master
- ps: Write-Host "$env:project_name PowerShell Module version $env:newVersion published to GitHub." -ForegroundColor Cyan