From 9911b004ed3dda8826a23f04de7e5c5ccf1a90e2 Mon Sep 17 00:00:00 2001 From: azure-sdk Date: Thu, 1 Oct 2020 17:58:33 +0000 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools repository for Tools PR 1031 --- eng/common/scripts/New-ReleaseAsset.ps1 | 62 +++++++++++++++++++++++++ eng/common/scripts/logging.ps1 | 2 +- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 eng/common/scripts/New-ReleaseAsset.ps1 diff --git a/eng/common/scripts/New-ReleaseAsset.ps1 b/eng/common/scripts/New-ReleaseAsset.ps1 new file mode 100644 index 000000000..83efcc097 --- /dev/null +++ b/eng/common/scripts/New-ReleaseAsset.ps1 @@ -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 diff --git a/eng/common/scripts/logging.ps1 b/eng/common/scripts/logging.ps1 index 19a6fa5bc..9b327fd81 100644 --- a/eng/common/scripts/logging.ps1 +++ b/eng/common/scripts/logging.ps1 @@ -31,7 +31,7 @@ function LogDebug { if ($isDevOpsRun) { - Write-Host "##vso[task.LogIssue type=debug;]$args" + Write-Host "[debug]$args" } else {