You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ap...@apache.org on 2019/04/29 16:06:33 UTC

[arrow] branch master updated: ARROW-4694: [CI] Improve detect-changes.py on Travis PRs

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 56a1292  ARROW-4694: [CI] Improve detect-changes.py on Travis PRs
56a1292 is described below

commit 56a1292fe2dae172e096ef633bfd27d8c866d667
Author: Antoine Pitrou <an...@python.org>
AuthorDate: Mon Apr 29 18:06:23 2019 +0200

    ARROW-4694: [CI] Improve detect-changes.py on Travis PRs
    
    Author: Antoine Pitrou <an...@python.org>
    
    Closes #4223 from pitrou/ARROW-4694-improve-detect-changes and squashes the following commits:
    
    d4cb46d2e <Antoine Pitrou> Move logic into get_travis_commit_range()
    7b355e082 <Antoine Pitrou> Dump env vars
    656eca4a8 <Antoine Pitrou> ARROW-4694:  Improve detect-changes.py on Travis PRs
---
 ci/detect-changes.py | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/ci/detect-changes.py b/ci/detect-changes.py
index 8c7ce17..1a30eb5 100644
--- a/ci/detect-changes.py
+++ b/ci/detect-changes.py
@@ -20,6 +20,7 @@ from __future__ import print_function
 import functools
 import os
 import pprint
+import re
 import sys
 import subprocess
 
@@ -27,6 +28,16 @@ import subprocess
 perr = functools.partial(print, file=sys.stderr)
 
 
+def dump_env_vars(prefix, pattern=None):
+    if pattern is not None:
+        match = lambda s: re.search(pattern, s)
+    else:
+        match = lambda s: True
+    for name in sorted(os.environ):
+        if name.startswith(prefix) and match(name):
+            perr("- {0}: {1!r}".format(name, os.environ[name]))
+
+
 def run_cmd(cmdline):
     proc = subprocess.Popen(cmdline,
                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -52,6 +63,7 @@ def list_affected_files(commit_range):
     """
     Return a list of files changed by the given git commit range.
     """
+    perr("Getting affected files from", repr(commit_range))
     out = run_cmd(["git", "diff", "--name-only", commit_range])
     return list(filter(None, (s.strip() for s in out.decode().splitlines())))
 
@@ -61,10 +73,20 @@ def get_travis_head_commit():
 
 
 def get_travis_commit_range():
-    cr = os.environ['TRAVIS_COMMIT_RANGE']
-    # See
-    # https://github.com/travis-ci/travis-ci/issues/4596#issuecomment-139811122
-    return cr.replace('...', '..')
+    if os.environ['TRAVIS_EVENT_TYPE'] == 'pull_request':
+        # TRAVIS_COMMIT_RANGE is too pessimistic for PRs, as it may contain
+        # unrelated changes.  Instead, use the same strategy as on AppVeyor
+        # below.
+        run_cmd(["git", "fetch", "-q", "origin",
+                 "+refs/heads/{0}".format(os.environ['TRAVIS_BRANCH'])])
+        merge_base = run_cmd(["git", "merge-base",
+                              "HEAD", "FETCH_HEAD"]).decode().strip()
+        return "{0}..HEAD".format(merge_base)
+    else:
+        cr = os.environ['TRAVIS_COMMIT_RANGE']
+        # See
+        # https://github.com/travis-ci/travis-ci/issues/4596#issuecomment-139811122
+        return cr.replace('...', '..')
 
 
 def get_travis_commit_description():
@@ -188,6 +210,8 @@ def get_windows_shell_eval(env):
 
 
 def run_from_travis():
+    perr("Environment variables (excerpt):")
+    dump_env_vars('TRAVIS_', '(BRANCH|COMMIT|PULL)')
     if (os.environ['TRAVIS_REPO_SLUG'] == 'apache/arrow' and
             os.environ['TRAVIS_BRANCH'] == 'master' and
             os.environ['TRAVIS_EVENT_TYPE'] != 'pull_request'):
@@ -214,6 +238,8 @@ def run_from_travis():
 
 
 def run_from_appveyor():
+    perr("Environment variables (excerpt):")
+    dump_env_vars('APPVEYOR_', '(PULL|REPO)')
     if not os.environ.get('APPVEYOR_PULL_REQUEST_HEAD_COMMIT'):
         # Not a PR build, test everything
         affected = dict.fromkeys(ALL_TOPICS, True)