-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInvoke-Release.ps1
129 lines (124 loc) · 4.93 KB
/
Invoke-Release.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
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
[CmdletBinding(DefaultParameterSetName='Path')]
param(
[Parameter(Mandatory=$false)]
[ValidateScript({Test-Path -Path $_ -PathType Container})]
[string]$ProjectDirectory
,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$Namespace
,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$Repository
,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$ApiKey
,
[Parameter(Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$TagName
,
[Parameter(Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$Name
,
[Parameter(ParameterSetName='Path', Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[ValidateScript({Test-Path -Path $_ -PathType Leaf})]
[string]$ReleaseNotesPath
,
[Parameter(ParameterSetName='Content', Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$ReleaseNotesContent
,
[Parameter(Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[bool]$Draft
,
[Parameter(Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[bool]$Prerelease
,
[Parameter(Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$Asset
)
$ErrorActionPreference = 'Stop'
$ErrorView = 'NormalView'
$VerbosePreference = 'Continue'
Set-StrictMode -Version Latest
try {
Push-Location $PSScriptRoot
Import-Module "$(git rev-parse --show-toplevel)\lib\PSGitHubRestApi\src\PSGitHubRestApi\PSGitHubRestApi.psm1" -Force -Verbose
Import-Module "$(git rev-parse --show-toplevel)\src\PSRepositoryReleaseManager\PSRepositoryReleaseManager.psm1" -Force -Verbose
# Create GitHub release
if ($private:ProjectDirectory) {
$private:ProjectDir = $private:ProjectDirectory
}else {
$private:superProjectDir = git rev-parse --show-superproject-working-tree
if ($private:superProjectDir) {
$private:ProjectDir = $private:superProjectDir
"Using superproject path '$private:ProjectDir'" | Write-Verbose
}else {
$private:ProjectDir = git rev-parse --show-toplevel
"Superproject does not exist. Using project path '$private:ProjectDir'" | Write-Verbose
}
}
$private:createReleaseArgs = @{
Namespace = $Namespace
Repository = $Repository
ApiKey = $ApiKey
TagName = $TagName
TargetCommitish = git --git-dir "$($private:ProjectDir)/.git" rev-parse $TagName
Name = if ($Name) { $Name } else { $TagName }
}
if ($ReleaseNotesPath) {
"Sourcing from specified release notes path '$ReleaseNotesPath'" | Write-Verbose
$private:createReleaseArgs['ReleaseNotesPath'] = if ([System.IO.Path]::IsPathRooted($ReleaseNotesPath)) { $ReleaseNotesPath }
else { "$private:ProjectDir/$ReleaseNotesPath" }
}elseif ($ReleaseNotesContent) {
"Using specified release notes content" | Write-Verbose
$private:createReleaseArgs['ReleaseNotesContent'] = $ReleaseNotesContent
}else {
$private:defaultReleaseNotesPath = "$(git rev-parse --show-toplevel)/.release-notes.md"
if (Test-Path -Path $private:defaultReleaseNotesPath -PathType Leaf) {
"Sourcing from the default release notes path '$private:defaultReleaseNotesPath'" | Write-Verbose
$private:createReleaseArgs['ReleaseNotesPath'] = $private:defaultReleaseNotesPath
}else {
"Default release notes not found at the path '$private:defaultReleaseNotesPath'. No release notes will be included with the release." | Write-Verbose
}
}
if ($Draft) { $private:createReleaseArgs['Draft'] = $Draft } else { $false }
if ($Prerelease) { $private:createReleaseArgs['Prerelease'] = $Prerelease } else { $false }
$response = Create-GitHubRelease @private:createReleaseArgs
$responseContent = $response.Content | ConvertFrom-Json
# Upload release assets
if ($Asset) {
try {
$private:releaseAssetsArr = $Asset -Split "`n" | % { $_.Trim() } | ? { $_ }
"Release assets (Specified):" | Write-Verbose
$private:releaseAssetsArr | Out-String -Stream | % { $_.Trim() } | ? { $_ } | Write-Verbose
Push-Location $private:ProjectDir
$private:assets = $private:releaseAssetsArr | % { Resolve-Path -Path $_ }
if (!$private:assets) { throw "No assets of the specified release assets file pattern could be found." }
}catch {
throw
}finally {
Pop-Location
}
"Release assets (Full):" | Write-Verbose
$private:assets | Out-String -Stream | % { $_.Trim() } | ? { $_ } | Write-Verbose
$private:uploadReleaseAssetsArgs = @{
UploadUrl = $responseContent.upload_url
Asset = $private:assets
ApiKey = $ApiKey
}
Upload-GitHubReleaseAsset @private:uploadReleaseAssetsArgs
}
}catch {
throw
}finally {
Pop-Location
}