You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by mo...@apache.org on 2017/02/17 08:38:11 UTC

zeppelin git commit: [ZEPPELIN-2123] Travis build status check script

Repository: zeppelin
Updated Branches:
  refs/heads/master fe8b226f0 -> 05f293553


[ZEPPELIN-2123] Travis build status check script

### What is this PR for?
This script is designed to check contributors travis CI build state when pullrequest is created.

### What type of PR is it?
Feature

### Todos
* [x] - check travis build status

### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-2123

### How should this be tested?

Run script with `python ./travis_check.py [Author] [Branch name] [Commit hash]`.
For example
```
moon$ python ./travis_check.py Leemoonsoo ZEPPELIN-2120 44b9403
[2017-02-16 18:55:43] Author: Leemoonsoo, branch: ZEPPELIN-2120, commit: 44b9403
[2017-02-16 18:55:43] --------------------------------
[2017-02-16 18:55:48] Get build status ...
https://travis-ci.org/Leemoonsoo/zeppelin/builds/202172366
[1] OK
[2] Running ...
[3] Running ...
[4] OK
[5] OK
[6] Running ...
[7] OK
[8] Error 1
[9] Running ...
1 job(s) failed, 4 job(s) running
```

### 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 <mo...@apache.org>

Closes #2026 from Leemoonsoo/ZEPPELIN-2123 and squashes the following commits:

fc8fce3 [Lee moon soo] branch name is not really necessary
93179ab [Lee moon soo] Add some comments and remove test code
7de1c24 [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/05f29355
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/05f29355
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/05f29355

Branch: refs/heads/master
Commit: 05f2935536fd5f90b8b096d972d7c567fb61af0f
Parents: fe8b226
Author: Lee moon soo <mo...@apache.org>
Authored: Fri Feb 17 16:28:19 2017 +0900
Committer: Lee moon soo <mo...@apache.org>
Committed: Fri Feb 17 17:38:04 2017 +0900

----------------------------------------------------------------------
 travis_check.py | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/05f29355/travis_check.py
----------------------------------------------------------------------
diff --git a/travis_check.py b/travis_check.py
new file mode 100644
index 0000000..c110472
--- /dev/null
+++ b/travis_check.py
@@ -0,0 +1,103 @@
+#
+# 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.
+#
+
+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]
+
+def info(msg):
+    print("[" + time.strftime("%Y-%m-%d %H:%M:%S") + "] " + msg)
+
+
+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 printBuildStatus(build):
+    failure = 0
+    running = 0
+    for index, job in enumerate(build["matrix"]):
+        result = job["result"]
+        if job["started_at"] == None and result == None:
+            print("[" + str(index+1) + "] Not started")
+            running = running + 1
+        elif job["started_at"] != None and job["finished_at"] == None:
+            print("[" + str(index+1) + "] Running ...")
+            running = running + 1
+        elif job["started_at"] != None and job["finished_at"] != None:
+            if result == None:
+                print("[" + str(index+1) + "] Not completed")
+                failure = failure + 1
+            elif result == 0:
+                print("[" + str(index+1) + "] OK")
+            else:
+                print("[" + str(index+1) + "] Error " + str(result))
+                failure = failure + 1
+        else:
+            print("[" + str(index+1) + "] Unknown state")
+            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("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")
+
+    if failure != 0:
+        sys.exit(1)
+
+    if failure == 0 and running == 0:
+        info("CI Green!")
+        sys.exit(0)
+
+info("Timeout")
+sys.exit(1)