forked from Azure/azure-sdk-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNew-ReleaseAsset.ps1
More file actions
62 lines (47 loc) · 1.76 KB
/
New-ReleaseAsset.ps1
File metadata and controls
62 lines (47 loc) · 1.76 KB
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
<#
.SYNOPSIS
Uploads the release asset and returns the resulting object from the upload
.PARAMETER ReleaseTag
Tag to look up release
.PARAMETER AssetPath
Location of the asset file to upload
.PARAMETER GitHubRepo
Name of the GitHub repo to search (of the form Azure/azure-sdk-for-cpp)
#>
param (
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $ReleaseTag,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $AssetPath,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $GitHubRepo,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $GitHubPat
)
# Get information about release at $ReleaseTag
$releaseInfoUrl = "https://api.github.com/repos/$GitHubRepo/releases/tags/$ReleaseTag"
Write-Verbose "Requesting release info from $releaseInfoUrl"
$release = Invoke-RestMethod `
-Uri $releaseInfoUrl `
-Method GET
$assetFilename = Split-Path $AssetPath -Leaf
# Upload URL comes in the literal form (yes, those curly braces) of:
# https://uploads.github.com/repos/Azure/azure-sdk-for-cpp/releases/123/assets{?name,label}
# Converts to something like:
# https://uploads.github.com/repos/Azure/azure-sdk-for-cpp/releases/123/assets?name=foo.tar.gz
# Docs: https://docs.github.com/en/rest/reference/repos#get-a-release-by-tag-name
$uploadUrl = $release.upload_url.Split('{')[0] + "?name=$assetFilename"
Write-Verbose "Uploading $assetFilename to $uploadUrl"
$asset = Invoke-RestMethod `
-Uri $uploadUrl `
-Method POST `
-InFile $AssetPath `
-Credential $credentials `
-Headers @{ Authorization = "token $GitHubPat" } `
-ContentType "application/gzip"
Write-Verbose "Upload complete. Browser download URL: $($asset.browser_download_url)"
return $asset