-
Notifications
You must be signed in to change notification settings - Fork 1
/
Invoke-Release.ps1
94 lines (88 loc) · 4.42 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
[CmdletBinding()]
param()
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
try {
$private:ProjectDir = git rev-parse --show-toplevel
Push-Location $PSScriptRoot
Import-Module "$(git rev-parse --show-toplevel)\lib\PSGitHubRestApi\src\PSGitHubRestApi\PSGitHubRestApi.psm1" -Force
Import-Module "$(git rev-parse --show-toplevel)\src\PSRepositoryReleaseManager\PSRepositoryReleaseManager.psm1" -Force
# Create GitHub release
if ($env:PROJECT_DIRECTORY) {
"Using specified project directory '$env:PROJECT_DIRECTORY'" | Write-Verbose
$private:ProjectDir = $env:PROJECT_DIRECTORY
}else {
$private:superProjectDir = git rev-parse --show-superproject-working-tree
if ($private:superProjectDir) {
$private:ProjectDir = $private:superProjectDir
"Using superproject directory '$private:ProjectDir'" | Write-Verbose
}else {
"Using default project directory '$private:ProjectDir'" | Write-Verbose
}
}
$private:createReleaseArgs = @{
Namespace = $env:RELEASE_NAMESPACE
Repository = $env:RELEASE_REPOSITORY
ApiKey = $env:GITHUB_API_TOKEN
TagName = $env:RELEASE_TAG_REF
TargetCommitish = if (Test-Path -Path $private:ProjectDir -PathType Container) {
Push-Location $private:ProjectDir
git rev-parse $env:RELEASE_TAG_REF
Pop-Location
}
Name = if ($env:RELEASE_NAME) {
"Using specified release name '$env:RELEASE_NAME'" | Write-Verbose
$env:RELEASE_NAME
}else {
"Using specified ref '$env:RELEASE_TAG_REF' as the release name" | Write-Verbose
$env:RELEASE_TAG_REF
}
}
if ($env:RELEASE_NOTES_PATH) {
"Sourcing from specified release notes path '$env:RELEASE_NOTES_PATH'" | Write-Verbose
$private:createReleaseArgs['ReleaseNotesPath'] = if ([System.IO.Path]::IsPathRooted($env:RELEASE_NOTES_PATH)) { $env:RELEASE_NOTES_PATH }
else { "$private:ProjectDir/$env:RELEASE_NOTES_PATH" }
}elseif ($env:RELEASE_NOTES_CONTENT) {
"Using specified release notes content" | Write-Verbose
$private:createReleaseArgs['ReleaseNotesContent'] = $env:RELEASE_NOTES_CONTENT
}else {
$private:defaultReleaseNotesPath = "$(git rev-parse --show-toplevel)/.release-notes.md"
if (Test-Path -Path $private:defaultReleaseNotesPath -PathType Leaf) {
"Sourcing from 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 ($env:RELEASE_DRAFT) { $private:createReleaseArgs['Draft'] = [System.Convert]::ToBoolean($env:RELEASE_DRAFT) }
if ($env:RELEASE_PRERELEASE) { $private:createReleaseArgs['Prerelease'] = [System.Convert]::ToBoolean($env:RELEASE_PRERELEASE) }
$response = Create-GitHubRelease @private:createReleaseArgs
$responseContent = $response.Content | ConvertFrom-Json
# Upload release assets
if ($env:RELEASE_ASSETS) {
try {
$private:releaseAssetsArr = $env:RELEASE_ASSETS -Split "`n" | % { $_.Trim() } | ? { $_ }
"Release assets (Specified):" | Write-Verbose
$private:releaseAssetsArr | Out-String -Stream | % { $_.Trim() } | ? { $_ } | Write-Verbose
Push-Location $private:ProjectDir
$private:assets = $private:releaseAssetsArr | % { Convert-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 = $env:GITHUB_API_TOKEN
}
Upload-GitHubReleaseAsset @private:uploadReleaseAssetsArgs
}
}catch {
throw
}finally {
Pop-Location
}