Repository: zeppelin Updated Branches: refs/heads/branch-0.7 ec3d0d32b -> f0ef74b11
[ZEPPELIN-2123] [branch-0.7] backport travis_check.py to branch-0.7 ### What is this PR for? ZEPPELIN-2123 introduces travis_check.py to scale out CI capacity. However travis_check.py does not exists in branch-0.7, and PR to branch-0.7 marked as a green without regardless of the actual build result. Since we're planning to make more releases from branch-0.7 and target branch of some PRs are branch-0.7, i think we need travis_check.py on branch-0.7, too. ### What type of PR is it? Feature ### Todos * [x] - bring travis_check.py to branch-0.7 ### What is the Jira issue? https://issues.apache.org/jira/browse/ZEPPELIN-2123 ### How should this be tested? Check Jenkins successfully read build status from travis for PR targeting branch-0.7. (this PR) ### Questions: * Does the licenses files need update? no * Is there breaking changes for older versions? no * Does this needs documentation? no Author: Lee moon soo <m...@apache.org> Closes #2082 from Leemoonsoo/branch-0.7_travis_check_backport and squashes the following commits: f24a5e0 [Lee moon soo] Lambda to function 1c5559f [Lee moon soo] make 3rd param override check interval. usage in the comment ab31b21 [Lee moon soo] increase polling count. beautifulize output 92577b5 [Lee moon soo] Flush output 7267943 [Lee moon soo] branch name is not really necessary bf655a1 [Lee moon soo] Add some comments and remove test code f30c3c1 [Lee moon soo] Travis build status check script Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/f0ef74b1 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/f0ef74b1 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/f0ef74b1 Branch: refs/heads/branch-0.7 Commit: f0ef74b119f8d7ea7c5f7d0f9eaa74a50eb69d25 Parents: ec3d0d3 Author: Lee moon soo <m...@apache.org> Authored: Sat Feb 18 14:25:38 2017 +0900 Committer: Lee moon soo <m...@apache.org> Committed: Sat Mar 4 15:34:15 2017 +0900 ---------------------------------------------------------------------- travis_check.py | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/f0ef74b1/travis_check.py ---------------------------------------------------------------------- diff --git a/travis_check.py b/travis_check.py new file mode 100644 index 0000000..a2fa288 --- /dev/null +++ b/travis_check.py @@ -0,0 +1,122 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# This script checks build status of given pullrequest identified by author and commit hash. +# +# usage) +# python travis_check.py [author] [commit hash] [check interval (optional)] +# +# example) +# # full hash +# python travis_check.py Leemoonsoo 1f2549a38f440ebfbfe2d32a041684e3e39b496c +# +# # with short hash +# python travis_check.py Leemoonsoo 1f2549a +# +# # with custom check interval +# python travis_check.py Leemoonsoo 1f2549a 5,60,60 + +import os, sys, getopt, traceback, json, requests, time + +author = sys.argv[1] +commit = sys.argv[2] + +# check interval in sec +check = [5, 60, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 600, 600, 600, 600, 600, 600] + +if len(sys.argv) > 3: + check = map(lambda x: int(x), sys.argv[3].split(",")) + +def info(msg): + print("[" + time.strftime("%Y-%m-%d %H:%M:%S") + "] " + msg) + sys.stdout.flush() + +info("Author: " + author + ", commit: " + commit) + + +def getBuildStatus(author, commit): + travisApi = "https://api.travis-ci.org/" + + # get latest 25 builds + resp = requests.get(url=travisApi + "/repos/" + author + "/zeppelin/builds") + data = json.loads(resp.text) + + build = None + for b in data: + if b["commit"][:len(commit)] == commit: + resp = requests.get(url=travisApi + "/repos/" + author + "/zeppelin/builds/" + str(b["id"])) + build = json.loads(resp.text) + break + + return build + +def status(index, msg, jobId): + return '{:20}'.format("[" + str(index+1) + "] " + msg) + "https://travis-ci.org/" + author + "/zeppelin/jobs/" + str(jobId) + +def printBuildStatus(build): + failure = 0 + running = 0 + + for index, job in enumerate(build["matrix"]): + result = job["result"] + jobId = job["id"] + + if job["started_at"] == None and result == None: + print(status(index, "Not started", jobId)) + running = running + 1 + elif job["started_at"] != None and job["finished_at"] == None: + print(status(index, "Running ...", jobId)) + running = running + 1 + elif job["started_at"] != None and job["finished_at"] != None: + if result == None: + print(status(index, "Not completed", jobId)) + failure = failure + 1 + elif result == 0: + print(status(index, "OK", jobId)) + else: + print(status(index, "Error " + str(result), jobId)) + failure = failure + 1 + else: + print(status(index, "Unknown state", jobId)) + failure = failure + 1 + + return failure, running + + +for sleep in check: + info("--------------------------------") + time.sleep(sleep); + info("Get build status ...") + build = getBuildStatus(author, commit) + if build == None: + info("Can't find build for commit= " + commit) + sys.exit(1) + + print("Build https://travis-ci.org/" + author + "/zeppelin/builds/" + str(build["id"])) + failure, running = printBuildStatus(build) + + print(str(failure) + " job(s) failed, " + str(running) + " job(s) running/pending") + + if failure != 0: + sys.exit(1) + + if failure == 0 and running == 0: + info("CI Green!") + sys.exit(0) + +info("Timeout") +sys.exit(1)