Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync eng/common directory with azure-sdk-tools for PR 1031 #15284

Merged
1 commit merged into from
Sep 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions eng/common/scripts/New-ReleaseAsset.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,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