Last active
February 6, 2016 19:12
-
-
Save JanDeDobbeleer/ee4c7f9b4289016b2216 to your computer and use it in GitHub Desktop.
Powershell Github release
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function GitHub-Release($versionNumber, $commitId, $preRelease, $releaseNotes, $artifactOutputDirectory, $artifact, $gitHubUsername, $gitHubRepository, $gitHubApiKey) | |
{ | |
$draft = $TRUE | |
$releaseData = @{ | |
tag_name = [string]::Format("v{0}", $versionNumber); | |
target_commitish = $commitId; | |
name = [string]::Format("v{0}", $versionNumber); | |
body = $releaseNotes; | |
draft = $draft; | |
prerelease = $preRelease; | |
} | |
$auth = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($gitHubApiKey + ":x-oauth-basic")); | |
$releaseParams = @{ | |
Uri = "https://api.github.com/repos/$gitHubUsername/$gitHubRepository/releases"; | |
Method = 'POST'; | |
Headers = @{ | |
Authorization = $auth; | |
} | |
ContentType = 'application/json'; | |
Body = (ConvertTo-Json $releaseData -Compress) | |
} | |
$result = Invoke-RestMethod @releaseParams | |
$uploadUri = $result | Select -ExpandProperty upload_url | |
Write-Host $uploadUri | |
$uploadUri = $uploadUri -creplace '\{\?name,label\}' #, "?name=$artifact" | |
$uploadUri = $uploadUri + "?name=$artifact" | |
$uploadFile = Join-Path -path $artifactOutputDirectory -childpath $artifact | |
$uploadParams = @{ | |
Uri = $uploadUri; | |
Method = 'POST'; | |
Headers = @{ | |
Authorization = $auth; | |
} | |
ContentType = 'application/zip'; | |
InFile = $uploadFile | |
} | |
$result = Invoke-RestMethod @uploadParams | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment