forked from MSAdministrator/CaptureIT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
executable file
·92 lines (85 loc) · 4.39 KB
/
build.ps1
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
# Line break for readability in AppVeyor console
Write-Host -Object ''
# 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
Try {
# This is where the module manifest lives
$manifestPath = '.\CaptureIT\CaptureIT.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]$newVersion = New-Object -TypeName System.Version -ArgumentList ($version.Major, $version.Minor, $version.Build, $env:APPVEYOR_BUILD_NUMBER)
Write-Output "New Version: $newVersion"
# Update the manifest with the new version value and fix the weird string replace bug
$functionList = ((Get-ChildItem -Path .\CaptureIT\Public).BaseName)
$splat = @{
'Path' = $manifestPath
'ModuleVersion' = $newVersion
'FunctionsToExport' = $functionList
'Copyright' = "(c) 2015-$( (Get-Date).Year ) CaptureIT. All rights reserved."
}
Update-ModuleManifest @splat
(Get-Content -Path $manifestPath) -replace 'PSGet_CaptureIT', 'CaptureIT' | Set-Content -Path $manifestPath
(Get-Content -Path $manifestPath) -replace 'NewManifest', 'CaptureIT' | 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
}
catch {
throw $_
}
# Create new markdown and XML help files
Write-Host "Building new function documentation" -ForegroundColor Yellow
Import-Module -Name "$PSScriptRoot\CaptureIT" -Force
New-MarkdownHelp -Module CaptureIT -OutputFolder '.\docs\' -Force
New-ExternalHelp -Path '.\docs\' -OutputPath '.\CaptureIT\en-US\' -Force
. .\docs.ps1
Write-Host -Object ''
# Publish the new version to the PowerShell Gallery
Try {
# Build a splat containing the required details and make sure to Stop for errors which will trigger the catch
$PM = @{
Path = '.\CaptureIT'
NuGetApiKey = $env:NuGetApiKey
ErrorAction = 'Stop'
Tags = 'GIF', 'Screenshot', 'Record'
LicenseUri = 'https://github.com/MSAdministrator/CaptureIT/blob/master/LICENSE.md'
ProjectUri = 'https://github.com/MSAdministrator/CaptureIT'
ReleaseNotes = 'Initial release to the PowerShell Gallery'
}
Publish-Module @PM
Write-Host "CaptureIT PowerShell Module version $newVersion published to the PowerShell Gallery." -ForegroundColor Cyan
}
Catch {
# Sad panda; it broke
Write-Warning "Publishing update $newVersion to the PowerShell Gallery failed."
throw $_
}
# Publish the new version back to Master on GitHub
Try {
# 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 checkout master
git add --all
git status
git commit -s -m "Update version to $newVersion"
git push origin master
Write-Host "CaptureIT PowerShell Module version $newVersion published to GitHub." -ForegroundColor Cyan
}
Catch {
# Sad panda; it broke
Write-Warning "Publishing update $newVersion to GitHub failed."
throw $_
}
}