forked from majkinetor/au
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.ps1
99 lines (75 loc) · 2.74 KB
/
publish.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
93
94
95
96
97
98
99
#requires -version 5
param(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$Version,
[switch]$Tag,
[switch]$PSGallery,
[switch]$Github,
[switch]$Chocolatey
)
$ErrorActionPreference = 'STOP'
$p = {
$build_dir = "$PSScriptRoot/_build/$Version"
$module_name = "AU"
$module_path = "$build_dir/$module_name"
$release_notes = get_release_notes
if (!(Test-Path $build_dir)) { throw "Build for that version doesn't exist" }
if (!(Get-Command git)) {throw "Git is not installed. Use Chocolatey to install it: cinst git" }
if (Test-Path $PSScriptRoot/vars.ps1) { . $PSScriptRoot/vars.ps1 }
git_tag
Publish-Github
Publish-PSGallery
Publish-Chocolatey
}
function git_tag() {
if (!$Tag) { Write-Host "Creating git tag disabled"; return }
Write-Host "Creating git tag for version $version"
Push-Location $PSScriptRoot
git status
git tag $version
git push --tags
Pop-Location
}
function get_release_notes() {
$changelog_path = Resolve-Path $PSScriptRoot\CHANGELOG.md
$clog = Get-Content $changelog_path -Raw
$res = $clog -match "(?<=## $version)(.|\n)+?(?=\n## )"
if (!$res) { throw "Version $version header can't be found in the CHANGELOG.md" }
$Matches[0]
}
function Publish-Github() {
#[System.Net.ServicePointManager]::SecurityProtocol = 3072 -bor 768 -bor [System.Net.SecurityProtocolType]::Tls -bor [System.Net.SecurityProtocolType]::Ssl3
if (!$Github) { Write-Host "Github publish disabled."; return }
Write-Host 'Publishing to Github'
'Github_UserRepo', 'Github_ApiKey' | test-var
$params = @{
Github_UserRepo = $Env:Github_UserRepo
Github_ApiKey = $Env:Github_ApiKey
TagName = $version
ReleaseNotes = $release_notes
Artifacts = "$build_dir/*.nupkg", "$build_dir/*.7z"
}
. $PSScriptRoot/scripts/Github-CreateRelease.ps1 @params
}
function Publish-PSGallery() {
if (!$PSGallery) { Write-Host "Powershell Gallery publish disabled."; return }
Write-Host 'Publishing to Powershell Gallery'
'NuGet_ApiKey' | test-var
$params = @{
Path = $module_path
NuGetApiKey = $Env:NuGet_ApiKey
}
Publish-Module @params -Verbose
}
function Publish-Chocolatey() {
if (!$Chocolatey) { Write-Host "Chocolatey publish disabled."; return }
Write-Verbose 'Publishing to Chocolatey'
'Chocolatey_ApiKey' | test-var
choco push (Resolve-Path $build_dir/*.$version.nupkg) --api-key $Env:Chocolatey_ApiKey
if ($LastExitCode) {throw "Chocolatey push failed with exit code: $LastExitCode"}
}
function test-var() {
$input | ForEach-Object { if (!(Test-Path Env:$_)) {throw "Environment Variable $_ must be set"} }
}
& $p