-
Notifications
You must be signed in to change notification settings - Fork 468
/
Copy pathCreateGitHubRelease.ps1
57 lines (45 loc) · 1.39 KB
/
CreateGitHubRelease.ps1
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
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$buildNumber,
[Parameter(Mandatory=$True,Position=2)]
[string]$reposOwner,
[Parameter(Mandatory=$True,Position=3)]
[string]$reposName,
[Parameter(Mandatory=$True,Position=4)]
[string]$branch,
[Parameter(Mandatory=$True,Position=5)]
[string]$apiKey
)
Write-Host "Info..."
Write-Host "Build Number" $buildNumber
Write-Host "Repos Owner" $reposOwner
Write-Host "Repos Name" $reposName
Write-Host "Branch" $branch
$TfsBuildVersionRegEx = "_v(\d+)\.(\S+)\.(\d+)"
if($buildNumber -match $TfsBuildVersionRegEx){
$versionNumber = $matches[0].Replace("_","")
Write-Host "Version Number" $versionNumber
}
else{
throw "Build format does not match the expected pattern (buildName_version)"
}
$body = @{
tag_name = $versionNumber;
target_commitish= $branch;
name= $versionNumber;
body= "Release version " + $versionNumber;
}
$releaseParams = @{
Uri = "https://api.github.com/repos/$reposOwner/$reposName/releases";
Method = 'POST';
Headers = @{
Authorization = 'Basic ' + [Convert]::ToBase64String(
[Text.Encoding]::ASCII.GetBytes($apiKey + ":x-oauth-basic"));
}
ContentType = 'application/json';
Body = (ConvertTo-Json $body -Compress)
}
Write-Host "Creating release in GitHub for version" $versionNumber
Invoke-RestMethod @releaseParams
Write-Host 'Finished!'