2013-12-30 21:11:32 +08:00
|
|
|
#Github pull reqest builder for Jenkins
|
|
|
|
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import urllib2
|
|
|
|
import urllib
|
|
|
|
import base64
|
|
|
|
import requests
|
2014-01-02 10:19:48 +08:00
|
|
|
import sys
|
2014-01-02 17:09:49 +08:00
|
|
|
import traceback
|
2014-01-06 20:58:00 +08:00
|
|
|
import platform
|
2014-01-24 14:40:15 +08:00
|
|
|
import subprocess
|
2014-03-20 16:19:35 +08:00
|
|
|
import codecs
|
2014-05-07 19:01:46 +08:00
|
|
|
from shutil import copy
|
2013-12-30 21:11:32 +08:00
|
|
|
|
|
|
|
#set Jenkins build description using submitDescription to mock browser behavior
|
2014-05-07 19:01:46 +08:00
|
|
|
#TODO: need to set parent build description
|
|
|
|
|
2014-01-06 20:58:00 +08:00
|
|
|
def set_description(desc, url):
|
2013-12-30 21:11:32 +08:00
|
|
|
req_data = urllib.urlencode({'description': desc})
|
2014-01-06 20:58:00 +08:00
|
|
|
req = urllib2.Request(url + 'submitDescription', req_data)
|
2013-12-31 18:29:32 +08:00
|
|
|
#print(os.environ['BUILD_URL'])
|
2013-12-30 21:11:32 +08:00
|
|
|
req.add_header('Content-Type', 'application/x-www-form-urlencoded')
|
|
|
|
base64string = base64.encodestring(os.environ['JENKINS_ADMIN']+ ":" + os.environ['JENKINS_ADMIN_PW']).replace('\n', '')
|
|
|
|
req.add_header("Authorization", "Basic " + base64string)
|
2014-01-02 17:09:49 +08:00
|
|
|
try:
|
|
|
|
urllib2.urlopen(req)
|
|
|
|
except:
|
2014-01-04 16:25:31 +08:00
|
|
|
traceback.print_exc()
|
2014-05-07 19:01:46 +08:00
|
|
|
|
2014-05-07 20:34:06 +08:00
|
|
|
def check_current_3rd_libs():
|
2014-05-07 19:01:46 +08:00
|
|
|
#get current_libs config
|
2014-05-12 18:49:52 +08:00
|
|
|
backup_files = range(2)
|
|
|
|
current_files = range(2)
|
|
|
|
config_file_paths = ['external/config.json','templates/lua-template-runtime/runtime/config.json']
|
|
|
|
for i, config_file_path in enumerate(config_file_paths):
|
|
|
|
if not os.path.isfile(config_file_path):
|
|
|
|
raise Exception("Could not find 'external/config.json'")
|
2014-05-07 19:01:46 +08:00
|
|
|
|
2014-05-12 18:49:52 +08:00
|
|
|
with open(config_file_path) as data_file:
|
|
|
|
data = json.load(data_file)
|
2014-05-07 19:01:46 +08:00
|
|
|
|
2014-05-12 18:49:52 +08:00
|
|
|
current_3rd_libs_version = data["version"]
|
|
|
|
filename = current_3rd_libs_version + '.zip'
|
|
|
|
node_name = os.environ['NODE_NAME']
|
|
|
|
backup_file = '../../../cocos-2dx-external/node/' + node_name + '/' + filename
|
|
|
|
backup_files[i] = backup_file
|
|
|
|
current_file = filename
|
|
|
|
current_files[i] = current_file
|
|
|
|
if os.path.isfile(backup_file):
|
|
|
|
copy(backup_file, current_file)
|
|
|
|
#run download-deps.py
|
2014-05-07 20:34:06 +08:00
|
|
|
os.system('python download-deps.py -r no')
|
|
|
|
#backup file
|
2014-05-12 18:49:52 +08:00
|
|
|
for i, backup_file in enumerate(backup_files):
|
|
|
|
current_file = current_files[i]
|
|
|
|
copy(current_file, backup_file)
|
2014-05-07 19:01:46 +08:00
|
|
|
|
2014-01-02 17:09:49 +08:00
|
|
|
def main():
|
|
|
|
#get payload from os env
|
|
|
|
payload_str = os.environ['payload']
|
2014-01-17 17:13:33 +08:00
|
|
|
payload_str = payload_str.decode('utf-8','ignore')
|
2014-01-02 17:09:49 +08:00
|
|
|
#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
|
2014-01-06 20:58:00 +08:00
|
|
|
|
2014-02-07 14:57:07 +08:00
|
|
|
#pr = payload['pull_request']
|
2014-01-09 12:47:46 +08:00
|
|
|
|
2014-02-07 14:57:07 +08:00
|
|
|
url = payload['html_url']
|
2014-01-02 17:09:49 +08:00
|
|
|
print "url:" + url
|
2014-01-06 20:58:00 +08:00
|
|
|
pr_desc = '<h3><a href='+ url + '> pr#' + str(pr_num) + ' is '+ action +'</a></h3>'
|
|
|
|
|
|
|
|
|
2013-12-30 21:11:32 +08:00
|
|
|
|
2014-01-02 17:09:49 +08:00
|
|
|
#get statuses url
|
2014-02-07 14:57:07 +08:00
|
|
|
statuses_url = payload['statuses_url']
|
2014-01-02 17:09:49 +08:00
|
|
|
|
|
|
|
#get pr target branch
|
2014-02-07 14:57:07 +08:00
|
|
|
branch = payload['branch']
|
2014-01-02 17:09:49 +08:00
|
|
|
|
|
|
|
#set commit status to pending
|
2014-01-23 00:21:58 +08:00
|
|
|
#target_url = os.environ['BUILD_URL']
|
|
|
|
jenkins_url = os.environ['JENKINS_URL']
|
|
|
|
job_name = os.environ['JOB_NAME'].split('/')[0]
|
|
|
|
build_number = os.environ['BUILD_NUMBER']
|
2014-01-24 12:05:31 +08:00
|
|
|
target_url = jenkins_url + 'job/' + job_name + '/' + build_number + '/'
|
2014-01-06 20:58:00 +08:00
|
|
|
|
|
|
|
set_description(pr_desc, target_url)
|
2014-02-07 14:57:07 +08:00
|
|
|
|
2014-01-09 12:47:46 +08:00
|
|
|
|
2014-01-02 17:09:49 +08:00
|
|
|
data = {"state":"pending", "target_url":target_url}
|
2014-01-04 16:25:31 +08:00
|
|
|
access_token = os.environ['GITHUB_ACCESS_TOKEN']
|
|
|
|
Headers = {"Authorization":"token " + access_token}
|
2014-01-02 17:09:49 +08:00
|
|
|
|
|
|
|
try:
|
|
|
|
requests.post(statuses_url, data=json.dumps(data), headers=Headers)
|
|
|
|
except:
|
2014-01-04 16:25:31 +08:00
|
|
|
traceback.print_exc()
|
2014-01-02 17:09:49 +08:00
|
|
|
|
2014-01-03 10:59:37 +08:00
|
|
|
#reset path to workspace root
|
|
|
|
os.system("cd " + os.environ['WORKSPACE']);
|
2014-04-28 10:45:55 +08:00
|
|
|
os.system("git checkout v3")
|
2014-01-07 15:41:18 +08:00
|
|
|
os.system("git branch -D pull" + str(pr_num))
|
|
|
|
#clean workspace
|
2014-03-11 22:05:50 +08:00
|
|
|
print "Before checkout: git clean -xdf -f"
|
2014-03-11 21:39:31 +08:00
|
|
|
os.system("git clean -xdf -f")
|
2014-01-03 10:59:37 +08:00
|
|
|
#fetch pull request to local repo
|
2014-02-07 14:57:07 +08:00
|
|
|
git_fetch_pr = "git fetch origin pull/" + str(pr_num) + "/merge"
|
2014-03-26 14:29:53 +08:00
|
|
|
ret = os.system(git_fetch_pr)
|
|
|
|
if(ret != 0):
|
2014-04-08 16:35:01 +08:00
|
|
|
return(2)
|
2014-01-03 10:59:37 +08:00
|
|
|
|
|
|
|
#checkout
|
|
|
|
git_checkout = "git checkout -b " + "pull" + str(pr_num) + " FETCH_HEAD"
|
|
|
|
os.system(git_checkout)
|
|
|
|
|
2014-03-11 22:05:50 +08:00
|
|
|
# After checkout a new branch, clean workspace again
|
|
|
|
print "After checkout: git clean -xdf -f"
|
|
|
|
os.system("git clean -xdf -f")
|
|
|
|
|
2014-01-03 10:59:37 +08:00
|
|
|
#update submodule
|
|
|
|
git_update_submodule = "git submodule update --init --force"
|
2014-03-18 14:37:23 +08:00
|
|
|
ret = os.system(git_update_submodule)
|
|
|
|
if(ret != 0):
|
2014-04-08 16:35:01 +08:00
|
|
|
return(2)
|
2014-01-06 20:58:00 +08:00
|
|
|
|
2014-05-07 19:01:46 +08:00
|
|
|
#copy check_current_3rd_libs
|
2014-05-07 20:34:06 +08:00
|
|
|
check_current_3rd_libs()
|
2014-05-07 19:01:46 +08:00
|
|
|
|
2014-01-08 16:21:11 +08:00
|
|
|
# Generate binding glue codes
|
2014-04-28 10:45:55 +08:00
|
|
|
if(branch == 'v3'):
|
2014-03-27 14:28:40 +08:00
|
|
|
ret = os.system("python tools/jenkins-scripts/gen_jsb.py")
|
2014-04-28 10:45:55 +08:00
|
|
|
elif(branch == 'v2'):
|
2014-03-20 16:19:35 +08:00
|
|
|
os.chdir('tools/tojs')
|
|
|
|
if(platform.system() == 'Windows'):
|
|
|
|
os.environ['NDK_ROOT'] = os.environ['NDK_ROOT_R8E']
|
2014-03-27 14:28:40 +08:00
|
|
|
ret = os.system("genbindings-win32.bat")
|
2014-03-20 16:19:35 +08:00
|
|
|
os.environ['NDK_ROOT'] = os.environ['NDK_ROOT_R9B']
|
|
|
|
else:
|
2014-03-27 14:28:40 +08:00
|
|
|
ret = os.system("./genbindings.sh")
|
2014-03-20 16:19:35 +08:00
|
|
|
os.chdir('../..')
|
2014-03-27 14:28:40 +08:00
|
|
|
if(ret != 0):
|
|
|
|
return(1)
|
2014-01-08 16:21:11 +08:00
|
|
|
|
2014-01-07 15:41:18 +08:00
|
|
|
#make temp dir
|
2014-03-11 21:39:31 +08:00
|
|
|
print "current dir is: " + os.environ['WORKSPACE']
|
2014-01-07 15:41:18 +08:00
|
|
|
os.system("cd " + os.environ['WORKSPACE']);
|
|
|
|
os.mkdir("android_build_objs")
|
2014-01-06 20:58:00 +08:00
|
|
|
#add symbol link
|
2014-03-11 19:39:20 +08:00
|
|
|
PROJECTS=["cpp-empty-test", "cpp-tests"]
|
|
|
|
|
|
|
|
print platform.system()
|
|
|
|
if(platform.system() == 'Darwin'):
|
|
|
|
for item in PROJECTS:
|
|
|
|
cmd = "ln -s " + os.environ['WORKSPACE']+"/android_build_objs/ " + os.environ['WORKSPACE']+"/tests/"+item+"/proj.android/obj"
|
|
|
|
os.system(cmd)
|
|
|
|
elif(platform.system() == 'Windows'):
|
|
|
|
for item in PROJECTS:
|
|
|
|
p = item.replace("/", os.sep)
|
|
|
|
cmd = "mklink /J "+os.environ['WORKSPACE']+os.sep+"tests"+os.sep +p+os.sep+"proj.android"+os.sep+"obj " + os.environ['WORKSPACE']+os.sep+"android_build_objs"
|
|
|
|
print cmd
|
|
|
|
os.system(cmd)
|
2014-01-06 20:58:00 +08:00
|
|
|
|
2014-01-02 17:09:49 +08:00
|
|
|
#build
|
|
|
|
#TODO: add android-linux build
|
|
|
|
#TODO: add mac build
|
2014-01-24 14:40:15 +08:00
|
|
|
node_name = os.environ['NODE_NAME']
|
2014-04-28 10:45:55 +08:00
|
|
|
if(branch == 'v3'):
|
2014-01-24 14:40:15 +08:00
|
|
|
if(node_name == 'android_mac') or (node_name == 'android_win7'):
|
2014-04-15 18:15:31 +08:00
|
|
|
#modify tests/cpp-empty-test/Classes/AppDelegate.cpp to support Console
|
|
|
|
modify_file = 'tests/cpp-empty-test/Classes/AppDelegate.cpp'
|
|
|
|
data = codecs.open(modify_file, encoding='UTF-8').read()
|
|
|
|
data = re.sub("director->setDisplayStats\(true\);", "director->setDisplayStats(true); director->getConsole()->listenOnTCP(5678);", data)
|
|
|
|
codecs.open(modify_file, 'wb', encoding='UTF-8').write(data)
|
2014-04-17 17:04:28 +08:00
|
|
|
#modify tests/cpp-empty-test/proj.android/AndroidManifest.xml to support Console
|
|
|
|
modify_file = 'tests/cpp-empty-test/proj.android/AndroidManifest.xml'
|
|
|
|
data = codecs.open(modify_file, encoding='UTF-8').read()
|
|
|
|
data = re.sub('<uses-feature android:glEsVersion="0x00020000" />', '<uses-feature android:glEsVersion="0x00020000" /> <uses-permission android:name="android.permission.INTERNET"/>', data)
|
|
|
|
codecs.open(modify_file, 'wb', encoding='UTF-8').write(data)
|
2014-03-11 21:39:31 +08:00
|
|
|
print "Start build android..."
|
2014-03-18 17:27:57 +08:00
|
|
|
ret = os.system("python build/android-build.py -n -j10 all")
|
2014-04-15 18:15:31 +08:00
|
|
|
# create and save apk
|
|
|
|
if(ret == 0):
|
|
|
|
sample_dir = 'tests/cpp-empty-test/proj.android/'
|
|
|
|
os.system('android update project -p cocos/2d/platform/android/java/ -t android-13')
|
|
|
|
os.system('android update project -p ' + sample_dir + ' -t android-13')
|
|
|
|
os.system('ant debug -f ' + sample_dir + 'build.xml')
|
|
|
|
local_apk = sample_dir + 'bin/CppEmptyTest-debug.apk'
|
|
|
|
remote_apk = 'apks/cpp_empty_test/cpp_empty_test_' + str(pr_num) + '.apk'
|
|
|
|
os.system('tools/jenkins-scripts/upload_apk.sh ' + local_apk + ' ' + remote_apk)
|
2014-01-24 14:40:15 +08:00
|
|
|
elif(node_name == 'win32_win7'):
|
|
|
|
ret = subprocess.call('"%VS110COMNTOOLS%..\IDE\devenv.com" "build\cocos2d-win32.vc2012.sln" /Build "Debug|Win32"', shell=True)
|
2014-02-07 14:57:07 +08:00
|
|
|
elif(node_name == 'ios_mac'):
|
|
|
|
ret = os.system("tools/jenkins-scripts/ios-build.sh")
|
2014-03-07 11:25:35 +08:00
|
|
|
elif(node_name == 'linux_centos'):
|
|
|
|
os.chdir("build/")
|
|
|
|
ret = os.system("cmake ../")
|
|
|
|
ret = os.system("make -j10")
|
|
|
|
os.chdir("../")
|
2014-04-28 10:45:55 +08:00
|
|
|
elif(branch == 'v2'):
|
2014-03-20 16:19:35 +08:00
|
|
|
SAMPLES_DIRS = ['Cpp/HelloCpp', 'Cpp/SimpleGame', 'Cpp/TestCpp', 'Javascript/TestJavascript', 'Lua/HelloLua', 'Lua/TestLua']
|
|
|
|
SAMPLES_NAMES = ['HelloCpp', 'SimpleGame', 'TestCpp', 'TestJavascript', 'HelloLua', 'TestLua']
|
|
|
|
if(node_name == 'android_mac'):
|
|
|
|
for item in SAMPLES_DIRS:
|
|
|
|
proj_dir = "samples/" + item + "/proj.android"
|
|
|
|
os.system('ln -s ../../../../android_build_objs obj')
|
|
|
|
os.system(proj_dir + "/build_native.sh")
|
|
|
|
if (ret != 0):
|
|
|
|
break
|
|
|
|
elif(node_name == 'win32_win7'):
|
|
|
|
ret = subprocess.call('"%VS110COMNTOOLS%..\IDE\devenv.com" "cocos2d-win32.vc2012.sln" /Build "Debug|Win32"', shell=True)
|
|
|
|
elif(node_name == 'ios_mac'):
|
|
|
|
for i, item in enumerate(SAMPLES_DIRS):
|
|
|
|
cmd = "xcodebuild -project samples/" + item + "/proj.ios/" + SAMPLES_NAMES[i] + ".xcodeproj -scheme " + SAMPLES_NAMES[i] + ' -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)"'
|
|
|
|
cmd_clean = cmd + ' clean'
|
|
|
|
cmd_build = cmd + ' build'
|
|
|
|
ret = os.system(cmd_clean)
|
|
|
|
if(ret != 0):
|
|
|
|
break
|
|
|
|
ret = os.system(cmd_build)
|
|
|
|
if(ret != 0):
|
|
|
|
break
|
|
|
|
elif(node_name == 'linux_centos'):
|
|
|
|
data = codecs.open('cocos2dx/proj.linux/cocos2dx.mk', encoding='UTF-8').read()
|
|
|
|
data = re.sub('-lglfw','-L$(GLFW_279_LIB) -lglfw', data)
|
|
|
|
codecs.open('cocos2dx/proj.linux/cocos2dx.mk', 'wb', encoding='UTF-8').write(data)
|
|
|
|
ret = os.system('make -j10')
|
2014-01-26 18:27:27 +08:00
|
|
|
else:
|
|
|
|
ret = 0
|
2014-01-02 17:09:49 +08:00
|
|
|
|
|
|
|
#get build result
|
|
|
|
print "build finished and return " + str(ret)
|
2014-01-23 00:21:58 +08:00
|
|
|
|
2014-01-04 16:25:31 +08:00
|
|
|
exit_code = 1
|
2014-01-02 17:09:49 +08:00
|
|
|
if ret == 0:
|
|
|
|
exit_code = 0
|
|
|
|
else:
|
|
|
|
exit_code = 1
|
2014-01-23 00:21:58 +08:00
|
|
|
|
2013-12-31 18:29:32 +08:00
|
|
|
#clean workspace
|
2014-03-21 13:57:38 +08:00
|
|
|
os.system("cd " + os.environ['WORKSPACE'])
|
|
|
|
os.system("git reset --hard")
|
|
|
|
os.system("git clean -xdf -f")
|
2014-04-28 10:45:55 +08:00
|
|
|
os.system("git checkout v3")
|
2013-12-31 18:29:32 +08:00
|
|
|
os.system("git branch -D pull" + str(pr_num))
|
2013-12-30 21:11:32 +08:00
|
|
|
|
2014-01-06 20:58:00 +08:00
|
|
|
return(exit_code)
|
2014-01-02 17:09:49 +08:00
|
|
|
|
|
|
|
# -------------- main --------------
|
|
|
|
if __name__ == '__main__':
|
2014-01-06 20:58:00 +08:00
|
|
|
sys_ret = 0
|
2014-01-02 17:09:49 +08:00
|
|
|
try:
|
2014-01-06 20:58:00 +08:00
|
|
|
sys_ret = main()
|
2014-01-02 17:09:49 +08:00
|
|
|
except:
|
2014-01-04 16:25:31 +08:00
|
|
|
traceback.print_exc()
|
2014-01-06 20:58:00 +08:00
|
|
|
sys_ret = 1
|
|
|
|
finally:
|
|
|
|
sys.exit(sys_ret)
|