Skip to content
This repository was archived by the owner on Sep 2, 2019. It is now read-only.

Commit cfdebbd

Browse files
committed
Add github uploader.
1 parent 20694aa commit cfdebbd

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

dist/dist.bat

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ pushd ffxiv
4747
if %errorlevel% neq 0 exit /b %errorlevel%
4848
popd ffxiv
4949

50+
set /p version=<..\src\version
51+
set /p tag=<..\src\tag
52+
SET OWNER=ZCube
53+
SET REPO=ACTWebSocket
54+
55+
xcopy /hrkyd ACTWebSocketOverlay_latest.zip ACTWebSocketOverlay_%version%.*
56+
xcopy /hrkyd ACTWebSocketOverlay_ffxiv_latest.zip ACTWebSocketOverlay_ffxiv_%version%.*
57+
58+
echo ==========================================================================================
59+
@py -2 github_uploader.py %GITHUB_TOKEN% %OWNER% %REPO% %tag% ACTWebSocketOverlay_%version%.zip
60+
@py -2 github_uploader.py %GITHUB_TOKEN% %OWNER% %REPO% %tag% ACTWebSocketOverlay_ffxiv_%version%.zip
61+
echo ==========================================================================================
62+
5063

5164
:SetVariables
5265
FOR /F "tokens=3 delims= " %%G IN ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Personal"') DO (SET DocumentDir=%%G)

dist/github_uploader.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import pycurl
2+
import certifi
3+
import json
4+
import os
5+
import mimetypes
6+
from StringIO import StringIO
7+
8+
from subprocess import check_output
9+
import re
10+
import glob
11+
import sys
12+
13+
dev = False
14+
15+
if len(sys.argv) > 1:
16+
dev = True
17+
18+
out = check_output(["git", "describe", "--long"]).replace('-', '.', 1).replace("\r","").replace("\n","")
19+
arr = out.split(".")
20+
var = arr[0:-1]
21+
if len(var) < 3:
22+
var = var + ['0'] * (3 - len(arr))
23+
24+
if dev:
25+
vars = var + [arr[-1].split('-')[0]]
26+
varl = var + [arr[-1][0]+'-'+sys.argv[1]]
27+
else:
28+
vars = var + [arr[-1].split('-')[0]]
29+
varl = var + [arr[-1]]
30+
31+
def tagOnly():
32+
return ".".join(var[0:3])
33+
34+
def tagOnlyWithComma():
35+
return ".".join(var[0:3])
36+
37+
def longVersion():
38+
return ".".join(varl)
39+
40+
def longVersionWithComma():
41+
return ",".join(varl)
42+
43+
def shortVersion():
44+
return ".".join(vars)
45+
46+
def shortVersionWithComma():
47+
return ",".join(vars)
48+
49+
50+
51+
def get_releases(owner, repo):
52+
buffer = StringIO()
53+
c = pycurl.Curl()
54+
c.setopt(pycurl.CAINFO, certifi.where())
55+
c.setopt(c.URL, "https://api.github.com/repos/{}/{}/releases".format(owner, repo))
56+
c.setopt(c.WRITEDATA, buffer)
57+
c.setopt(c.WRITEFUNCTION, buffer.write)
58+
c.perform()
59+
c.close()
60+
body = buffer.getvalue()
61+
return json.loads(body)
62+
63+
def upload_file(url, filename, token):
64+
buffer = StringIO()
65+
c = pycurl.Curl()
66+
c.setopt(pycurl.CAINFO, certifi.where())
67+
c.setopt(c.URL, url + "?name={0}".format(os.path.basename(filename)))
68+
c.setopt(c.HTTPHEADER, [
69+
"Content-type: application/octet-stream",
70+
"Authorization: token {}".format(token)])
71+
c.setopt(c.POST, 1)
72+
c.setopt(c.UPLOAD, 1)
73+
c.setopt(c.READFUNCTION, open(filename, 'rb').read)
74+
filesize = os.path.getsize(filename)
75+
c.setopt(c.INFILESIZE, filesize)
76+
c.setopt(c.WRITEDATA, buffer)
77+
c.setopt(c.WRITEFUNCTION, buffer.write)
78+
c.perform()
79+
c.close()
80+
body = buffer.getvalue()
81+
return json.loads(body)
82+
83+
apitoken = sys.argv[1]
84+
owner = sys.argv[2]
85+
repo = sys.argv[3]
86+
tag = sys.argv[4]
87+
file = sys.argv[5]
88+
89+
releases = get_releases(owner, repo)
90+
for release in releases:
91+
if release["tag_name"] == tag:
92+
upload_url = release["assets_url"].replace("api.github", "uploads.github")
93+
print(upload_url)
94+
s = upload_file(upload_url, file, apitoken)
95+
print(s)

src/tag

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.3

src/tag.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@VERSION_TAG@

0 commit comments

Comments
 (0)