mirror of https://github.com/axmolengine/axmol.git
refining exception handling
This commit is contained in:
parent
e944dae338
commit
b1714d74e5
|
@ -8,28 +8,8 @@ import urllib
|
||||||
import base64
|
import base64
|
||||||
import requests
|
import requests
|
||||||
import sys
|
import sys
|
||||||
|
import traceback
|
||||||
|
|
||||||
#get payload from os env
|
|
||||||
payload_str = os.environ['payload']
|
|
||||||
#parse to json obj
|
|
||||||
payload = json.loads(payload_str)
|
|
||||||
|
|
||||||
#get pull number
|
|
||||||
pr_num = payload['number']
|
|
||||||
print 'pr_num:' + str(pr_num)
|
|
||||||
|
|
||||||
#build for pull request action 'open' and 'synchronize', skip 'close'
|
|
||||||
action = payload['action']
|
|
||||||
print 'action: ' + action
|
|
||||||
if((action != 'opened') and (action != 'synchronize')):
|
|
||||||
print 'pull request #' + str(pr_num) + ' is closed, no build triggered'
|
|
||||||
exit(0)
|
|
||||||
|
|
||||||
|
|
||||||
pr = payload['pull_request']
|
|
||||||
url = pr['html_url']
|
|
||||||
print "url:" + url
|
|
||||||
pr_desc = '<h3><a href='+ url + '> pr#' + str(pr_num) + '</a></h3>'
|
|
||||||
#set Jenkins build description using submitDescription to mock browser behavior
|
#set Jenkins build description using submitDescription to mock browser behavior
|
||||||
#TODO: need to set parent build description
|
#TODO: need to set parent build description
|
||||||
def set_description(desc):
|
def set_description(desc):
|
||||||
|
@ -39,77 +19,93 @@ def set_description(desc):
|
||||||
req.add_header('Content-Type', 'application/x-www-form-urlencoded')
|
req.add_header('Content-Type', 'application/x-www-form-urlencoded')
|
||||||
base64string = base64.encodestring(os.environ['JENKINS_ADMIN']+ ":" + os.environ['JENKINS_ADMIN_PW']).replace('\n', '')
|
base64string = base64.encodestring(os.environ['JENKINS_ADMIN']+ ":" + os.environ['JENKINS_ADMIN_PW']).replace('\n', '')
|
||||||
req.add_header("Authorization", "Basic " + base64string)
|
req.add_header("Authorization", "Basic " + base64string)
|
||||||
urllib2.urlopen(req)
|
try:
|
||||||
try:
|
urllib2.urlopen(req)
|
||||||
|
raise(12345)
|
||||||
|
except:
|
||||||
|
traceback.format_exc()
|
||||||
|
def main():
|
||||||
|
#get payload from os env
|
||||||
|
payload_str = os.environ['payload']
|
||||||
|
#parse to json obj
|
||||||
|
payload = json.loads(payload_str)
|
||||||
|
|
||||||
|
#get pull number
|
||||||
|
pr_num = payload['number']
|
||||||
|
print 'pr_num:' + str(pr_num)
|
||||||
|
|
||||||
|
#build for pull request action 'open' and 'synchronize', skip 'close'
|
||||||
|
action = payload['action']
|
||||||
|
print 'action: ' + action
|
||||||
|
if((action != 'opened') and (action != 'synchronize')):
|
||||||
|
print 'pull request #' + str(pr_num) + ' is closed, no build triggered'
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
pr = payload['pull_request']
|
||||||
|
url = pr['html_url']
|
||||||
|
print "url:" + url
|
||||||
|
pr_desc = '<h3><a href='+ url + '> pr#' + str(pr_num) + '</a></h3>'
|
||||||
set_description(pr_desc)
|
set_description(pr_desc)
|
||||||
except:
|
|
||||||
e = sys.exc_info()[0]
|
|
||||||
print e
|
|
||||||
|
|
||||||
#get statuses url
|
#get statuses url
|
||||||
statuses_url = pr['statuses_url']
|
statuses_url = pr['statuses_url']
|
||||||
|
|
||||||
#get pr target branch
|
#get pr target branch
|
||||||
branch = pr['head']['ref']
|
branch = pr['head']['ref']
|
||||||
|
|
||||||
#set commit status to pending
|
#set commit status to pending
|
||||||
target_url = os.environ['BUILD_URL']
|
target_url = os.environ['BUILD_URL']
|
||||||
data = {"state":"pending", "target_url":target_url}
|
data = {"state":"pending", "target_url":target_url}
|
||||||
acccess_token = os.environ['GITHUB_ACCESS_TOKEN']
|
acccess_token = os.environ['GITHUB_ACCESS_TOKEN']
|
||||||
Headers = {"Authorization":"token " + acccess_token}
|
Headers = {"Authorization":"token " + acccess_token}
|
||||||
try:
|
|
||||||
requests.post(statuses_url, data=json.dumps(data), headers=Headers)
|
|
||||||
|
|
||||||
#reset path to workspace root
|
try:
|
||||||
os.system("cd " + os.environ['WORKSPACE']);
|
requests.post(statuses_url, data=json.dumps(data), headers=Headers)
|
||||||
|
raise(test123)
|
||||||
|
except:
|
||||||
|
traceback.format_exc()
|
||||||
|
|
||||||
#fetch pull request to local repo
|
#build
|
||||||
git_fetch_pr = "git fetch origin pull/" + str(pr_num) + "/head"
|
#TODO: support android-mac build currently
|
||||||
os.system(git_fetch_pr)
|
#TODO: add android-windows7 build
|
||||||
|
#TODO: add android-linux build
|
||||||
|
#TODO: add ios build
|
||||||
|
#TODO: add mac build
|
||||||
|
#TODO: add win32 build
|
||||||
|
if(branch == 'develop'):
|
||||||
|
ret = os.system("python build/android-build.py -n -j5 testcpp")
|
||||||
|
elif(branch == 'master'):
|
||||||
|
ret = os.system("samples/Cpp/TestCpp/proj.android/build_native.sh")
|
||||||
|
|
||||||
#checkout
|
#get build result
|
||||||
git_checkout = "git checkout -b " + "pull" + str(pr_num) + " FETCH_HEAD"
|
print "build finished and return " + str(ret)
|
||||||
os.system(git_checkout)
|
if ret == 0:
|
||||||
|
exit_code = 0
|
||||||
|
data['state'] = "success"
|
||||||
|
|
||||||
#update submodule
|
else:
|
||||||
git_update_submodule = "git submodule update --init --force"
|
exit_code = 1
|
||||||
os.system(git_update_submodule)
|
data['state'] = "failure"
|
||||||
except:
|
|
||||||
e = sys.exc_info()[0]
|
|
||||||
print e
|
|
||||||
|
|
||||||
|
|
||||||
#build
|
|
||||||
#TODO: support android-mac build currently
|
|
||||||
#TODO: add android-windows7 build
|
|
||||||
#TODO: add android-linux build
|
|
||||||
#TODO: add ios build
|
|
||||||
#TODO: add mac build
|
|
||||||
#TODO: add win32 build
|
|
||||||
if(branch == 'develop'):
|
|
||||||
ret = os.system("python build/android-build.py -n -j5 testcpp")
|
|
||||||
elif(branch == 'master'):
|
|
||||||
ret = os.system("samples/Cpp/TestCpp/proj.android/build_native.sh")
|
|
||||||
|
|
||||||
#get build result
|
|
||||||
print "build finished and return " + str(ret)
|
|
||||||
if ret == 0:
|
|
||||||
exit_code = 0
|
|
||||||
data['state'] = "success"
|
|
||||||
|
|
||||||
else:
|
|
||||||
exit_code = 1
|
|
||||||
data['state'] = "failure"
|
|
||||||
try:
|
|
||||||
#set commit status
|
#set commit status
|
||||||
requests.post(statuses_url, data=json.dumps(data), headers=Headers)
|
try:
|
||||||
|
requests.post(statuses_url, data=json.dumps(data), headers=Headers)
|
||||||
|
raise(test123)
|
||||||
|
except:
|
||||||
|
traceback.format_exc()
|
||||||
|
|
||||||
#clean workspace
|
#clean workspace
|
||||||
os.system("cd " + os.environ['WORKSPACE']);
|
os.system("cd " + os.environ['WORKSPACE']);
|
||||||
os.system("git checkout develop")
|
os.system("git checkout develop")
|
||||||
os.system("git branch -D pull" + str(pr_num))
|
os.system("git branch -D pull" + str(pr_num))
|
||||||
except:
|
|
||||||
e = sys.exc_info()[0]
|
|
||||||
print e
|
|
||||||
exit(exit_code)
|
|
||||||
|
|
||||||
|
exit(exit_code)
|
||||||
|
|
||||||
|
# -------------- main --------------
|
||||||
|
if __name__ == '__main__':
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except:
|
||||||
|
traceback.format_exc()
|
||||||
|
exit(1)
|
||||||
|
|
Loading…
Reference in New Issue