You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by si...@apache.org on 2018/06/07 05:32:50 UTC

[bookkeeper] branch master updated: Improve merge script on checking the statuses of github checks

This is an automated email from the ASF dual-hosted git repository.

sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 2043418  Improve merge script on checking the statuses of github checks
2043418 is described below

commit 204341825d616ee8e31317a2a0230049b2f4d03f
Author: Sijie Guo <si...@apache.org>
AuthorDate: Wed Jun 6 22:32:39 2018 -0700

    Improve merge script on checking the statuses of github checks
    
    Descriptions of the changes in this PR:
    
    *Motivation*
    
    Sometimes Jenkins CI job might already succeed, however they failed on publishing the build status
    to Github due to timeout (one example is attached below). In this case, we don't need to rerun the jenkins check again.
    
    ```
    Setting status of 55c1d54f3293e5166c59f238afd3fb3d98c7eb67 to SUCCESS with url https://builds.apache.org/job/bookkeeper_precommit_client_tests/21/ and message: 'SUCCESS
     '
    Using context: Jenkins: Client Tests
    Could not update commit status of the Pull Request on GitHub.
    org.kohsuke.github.HttpException: Server returned HTTP response code: -1, message: 'null' for URL: https://api.github.com/repos/apache/bookkeeper/statuses/55c1d54f3293e5166c59f238afd3fb3d98c7eb67
    	at org.kohsuke.github.Requester.parse(Requester.java:633)
    	at org.kohsuke.github.Requester.parse(Requester.java:631)
    	at org.kohsuke.github.Requester.parse(Requester.java:631)
    	at org.kohsuke.github.Requester.parse(Requester.java:594)
    	at org.kohsuke.github.Requester._to(Requester.java:272)
    	at org.kohsuke.github.Requester.to(Requester.java:234)
    	at org.kohsuke.github.GHRepository.createCommitStatus(GHRepository.java:1075)
    	at org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus.createCommitStatus(GhprbSimpleStatus.java:281)
    	at org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus.onBuildComplete(GhprbSimpleStatus.java:239)
    	at org.jenkinsci.plugins.ghprb.GhprbBuilds.onCompleted(GhprbBuilds.java:205)
    	at org.jenkinsci.plugins.ghprb.GhprbBuildListener.onCompleted(GhprbBuildListener.java:28)
    	at hudson.model.listeners.RunListener.fireCompleted(RunListener.java:211)
    	at hudson.model.Run.execute(Run.java:1769)
    	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    	at hudson.model.ResourceController.execute(ResourceController.java:97)
    	at hudson.model.Executor.run(Executor.java:429)
    Caused by: java.net.SocketTimeoutException: Read timed out
    	at sun.reflect.GeneratedConstructorAccessor10056.newInstance(Unknown Source)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    	at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1944)
    	at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1939)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1938)
    	at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1508)
    	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
    	at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
    	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:347)
    	at org.kohsuke.github.Requester.parse(Requester.java:602)
    	... 15 more
    Caused by: java.net.SocketTimeoutException: Read timed out
    	at java.net.SocketInputStream.socketRead0(Native Method)
    	at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
    	at java.net.SocketInputStream.read(SocketInputStream.java:171)
    	at java.net.SocketInputStream.read(SocketInputStream.java:141)
    	at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
    	at sun.security.ssl.InputRecord.read(InputRecord.java:503)
    	at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)
    	at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:940)
    	at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
    	at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
    	at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
    	at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
    	at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:735)
    	at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
    	at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1587)
    	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
    	at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
    	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:347)
    	at org.kohsuke.github.Requester.parse(Requester.java:602)
    	... 13 more
    Finished: SUCCESS
    ```
    
    *Changes*
    
    Improve the merge script to check jenkins status before treating the checks as failed.
    
    Author: Sijie Guo <si...@apache.org>
    
    Reviewers: Enrico Olivelli <eo...@gmail.com>
    
    This closes #1497 from sijie/improve_merge_script
---
 dev/bk-merge-pr.py | 58 +++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 20 deletions(-)

diff --git a/dev/bk-merge-pr.py b/dev/bk-merge-pr.py
index e623d5c..a75ea4b 100755
--- a/dev/bk-merge-pr.py
+++ b/dev/bk-merge-pr.py
@@ -487,23 +487,39 @@ def check_ci_status(pr):
         else:
             check_individual_ci_status(ci_status, comments)
 
+def is_check_passed(check):
+    passed = check["state"] == "success"
+    if (not passed) and is_jenkins_check(check):
+        try:
+            return is_jenkins_passed(check["target_url"])
+        except:
+            fail("failed to fetch the jenkins build status for check '%s'.\nPlease manually check its build status at %s" % (check["context"], check["target_url"]))
+    return passed
+
+def is_jenkins_check(check):
+    return check["context"].startswith("Jenkins:")
+
+def is_jenkins_passed(url):
+    jenkins_status = get_json("%sapi/json" % (url))
+    return "SUCCESS" == jenkins_status['result'] 
+
+def is_integration_test_check(check):
+    return check["context"] == u"Jenkins: Integration Tests"
 
 def check_individual_ci_status(ci_status, comments):
-    postcommit_java9_success = False
-    postcommit_java8_success = False
-    integration_tests_success = False
-    travis_success = False
+    ci_failures = []
+    ci_integration_test_failures = []
     for status in ci_status["statuses"]:
-        if status["context"] == u"Jenkins: Maven clean install (Java 9)":
-            postcommit_java9_success = status["state"] == "success"
-        elif status["context"] == u"Jenkins: Maven clean install (Java 8)": 
-            postcommit_java8_success = status["state"] == "success"
-        elif status["context"] == u"Jenkins: Integration Tests": 
-            integration_tests_success = status["state"] == "success"
-        elif status["context"] == u"continuous-integration/travis-ci/pr":
-            travis_success = status["state"] == "success"
-
-    if postcommit_java8_success and postcommit_java9_success and travis_success and not integration_tests_success:
+        is_passed = is_check_passed(status) 
+        is_integration_test = is_integration_test_check(status)
+
+        if is_integration_test and (not is_passed):
+            ci_integration_test_failures.append(status)
+        else:
+            if not is_passed:
+                ci_failures.append(status)
+
+    if len(ci_integration_test_failures) != 0 and len(ci_failures) == 0:
         # all ci passed except integration tests
         ignore_it_ci_comments = [c for c in comments if c["body"].upper() == "IGNORE IT CI"]
         if len(ignore_it_ci_comments) > 0:
@@ -512,12 +528,14 @@ def check_individual_ci_status(ci_status, comments):
                 + "Proceed at your own peril!\n\n"
         else:
             fail("The PR has not passed integration tests CI")
-    else:
-        fail("The PR has not passed CI:\n" \
-            + "\t Travis: %s\n" % travis_success \
-            + "\t PostCommit (Java 8): %s\n" % postcommit_java8_success \
-            + "\t PostCommit (Java 9): %s\n" % postcommit_java9_success \
-            + "\t Integration Tests: %s\n" % integration_tests_success)
+    elif len(ci_failures) == 0 or len(ci_integration_test_failures) == 0:
+        fail_msg = "The PR has not passed CI:\n"
+        print ""
+        for status in ci_failures:
+            fail_msg += "\t %s = %s\n" % (status["context"], status["state"])
+        for status in ci_integration_test_failures:
+            fail_msg += "\t %s = %s\n" % (status["context"], status["state"])
+        fail(fail_msg)
 
 def ask_release_for_github_issues(branch, labels):
     print "=== Add release to github issues ==="

-- 
To stop receiving notification emails like this one, please contact
sijie@apache.org.