-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrelease_github.py
66 lines (55 loc) · 1.77 KB
/
release_github.py
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
64
65
66
# Public domain license.
# $version: 1
import sys
from git import Repo
import os.path
from github import Github
from github import GithubException
def PublishToGithub(token, mod_name, version, last_change, is_draft, is_prerelease, zip_file):
"""create tag and publish a release,
Returns:
1: succeed
0: failed
"""
sys.stdout.write(" * Github connection...")
github = None
repo = None
user = None
try:
github = Github(token)
user = github.get_user()
except Exception:
print(" failed.")
return 0
try:
repo = user.get_repo(mod_name)
print(" user: {}, repo: {}".format(user.login, repo.name))
except Exception:
print(" failed to get {}".format(mod_name))
return 0
tags = repo.get_tags()
count = tags.totalCount
if count == 0 or (count > 0 and tags[0].name != version):
print(" * getting last commit sha ...")
sha = repo.get_commits()[0].sha
try:
repo.create_git_ref('refs/tags/{}'.format(version), sha)
except GithubException:
print(" * could not create tag on the repo.")
else:
print(" * the tag "+version+" is found, skiping ...")
rel = repo.create_git_release(tag=version, name="Version " + version,
message=last_change,
draft=is_draft, prerelease=is_prerelease)
print(" * uploading asset ...")
rel.upload_asset(path=zip_file, content_type="application/zip")
print(" * git fetch origin ...")
gitrepo = Repo(os.getcwd())
try:
gitrepo.remotes.origin.fetch()
except:
print(" * fetch() failed, check ssh from the cmd")
return 0
else:
print(" * success.")
return 1