summaryrefslogtreecommitdiff
path: root/scripts/gh-push.py
blob: dd3b9408e5d5558c1df8725570cc1b2768209ae9 (plain)
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
#!/usr/bin/env python

import sys, os, re
from gh import gh

if len(sys.argv) != 2:
    print("Usage: python gh-push.py FILENAME")
    sys.exit(1)

f = sys.argv[1]
fname = os.path.basename(f)

print('Pulling info on draft release...')
draft = [r for r in gh('releases') if r['draft']][0]
print('Found: ' + draft['name'])

existing = [a for a in draft['assets'] if a['name'] == fname]
if (len(existing) > 0):
    print('Asset %s exists, deleting.' % fname)
    gh('releases/assets/' + str(existing[0]['id']),
        ['-X', 'DELETE'])

print('Uploading %s...' % f)

upload_url = re.sub(
    '\\{.*\\}', '?name=' + fname,
    draft['upload_url'])

resp = gh(upload_url, [
    '-H', 'Content-type: application/octet-stream',
    '--data-binary', '@' + f
    ])

print('Done.')