-
Notifications
You must be signed in to change notification settings - Fork 9
/
create-release-with-assets-and-rename.ps1
63 lines (50 loc) · 2.04 KB
/
create-release-with-assets-and-rename.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
56
57
58
59
60
61
62
63
param (
$AccessToken = $(throw "Need access token as first parameter"),
$DllPath = $(throw "Need filepath to dll as second parameter!"),
$ZipFilePath = $(throw "Need filepath to download as third parameter!"))
# reconstruct version
$vPSObject = get-command $DllPath
$Major = $vPSObject[0].Version.Major
$Minor = $vPSObject[0].Version.Minor
$Build = $vPSObject[0].Version.Build
$Revision = $vPSObject[0].Version.Revision
$Version = "$($Major).$($Minor).$($Build).$($Revision)"
$Version = $Version.TrimStart()
# construct tag name
$TagName = "v$($Version)"
# construct publish name
$FileName = [System.IO.Path]::GetFileNameWithoutExtension($DllPath)
$PublishName = "$($FileName) $($Version)"
$DownloadName = "$($PublishName).zip"
# create header
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $($AccessToken)")
$headers.Add("Content-Type", "text/plain")
$headers.Add("Cookie", "_octo=GH1.1.132013813.1594973163; logged_in=no")
# create body
$body = "{
`n `"tag_name`": `"$($TagName)`",
`n `"target_commitish`": `"master`",
`n `"name`": `"$($PublishName)`",
`n `"body`": `"Test Release`",
`n `"draft`": false,
`n `"prerelease`": true
`n}"
$response = Invoke-RestMethod 'https://api.github.com/repos/sswelm/PersistentThrust/releases' -Method 'POST' -Headers $headers -Body $body
# retrieve releaseId
$ReleaseId = $response.id
if ($ReleaseId -eq $null)
{
return
}
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $($AccessToken)")
$headers.Add("Content-Type", "application/zip")
$headers.Add("Cookie", "_octo=GH1.1.132013813.1594973163; logged_in=no")
# read a file a an biary
$body = Get-Content($ZipFilePath) -Raw
$uri = "https://uploads.github.com/repos/sswelm/PersistentThrust/releases/$($ReleaseId)/assets?name=$($DownloadName)"
$response = Invoke-RestMethod $uri -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
# rename file to download name
Rename-Item -Path $ZipFilePath -NewName $DownloadName