Skip to content

Instantly share code, notes, and snippets.

@JanDeDobbeleer
Last active February 6, 2016 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JanDeDobbeleer/ee4c7f9b4289016b2216 to your computer and use it in GitHub Desktop.
Save JanDeDobbeleer/ee4c7f9b4289016b2216 to your computer and use it in GitHub Desktop.
Powershell Github release
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