Browse Source

Improve detection of changed files inside Travis-CI

Hamilton Turner 11 years ago
parent
commit
f97824e8f4
3 changed files with 52 additions and 3 deletions
  1. 9 0
      .travis.yml
  2. 2 3
      toolset/run-ci.py
  3. 41 0
      toolset/setup/travis-ci/add_commit_range.sh

+ 9 - 0
.travis.yml

@@ -144,16 +144,25 @@ env:
     - TESTDIR=yesod
     - TESTDIR=yesod
 
 
 before_install:
 before_install:
+  # Enables $TRAVIS_COMMIT_RANGE for pull requests
+  - time ./toolset/setup/travis-ci/add_commit_range.sh
+  
+  # Configure Travis-CI build environment for TFB
+  #   e.g. setup databases, users, etc
   - time ./toolset/run-ci.py cisetup $TESTDIR
   - time ./toolset/run-ci.py cisetup $TESTDIR
 
 
 addons:
 addons:
   postgresql: "9.3" 
   postgresql: "9.3" 
 
 
 install:
 install:
+  # Install prerequisites
   - time ./toolset/run-ci.py prereq $TESTDIR
   - time ./toolset/run-ci.py prereq $TESTDIR
+  
+  # Install software for this framework  
   - time ./toolset/run-ci.py install $TESTDIR
   - time ./toolset/run-ci.py install $TESTDIR
    
    
 script: 
 script: 
+  # Pick one test in this directory and verify
   - time ./toolset/run-ci.py verify $TESTDIR
   - time ./toolset/run-ci.py verify $TESTDIR
 
 
 notifications:
 notifications:

+ 2 - 3
toolset/run-ci.py

@@ -39,11 +39,10 @@ class CIRunnner:
     self.mode = mode
     self.mode = mode
 
 
     try:
     try:
-      # See http://git.io/hs_qRQ
-      #   TRAVIS_COMMIT_RANGE is empty for pull requests
       is_pull_req = (os.environ['TRAVIS_PULL_REQUEST'] != "false")
       is_pull_req = (os.environ['TRAVIS_PULL_REQUEST'] != "false")
       if is_pull_req:
       if is_pull_req:
-        self.commit_range = "%s..FETCH_HEAD" % os.environ['TRAVIS_BRANCH']
+        # See add_commit_range in setup/travis-ci
+        self.commit_range = "prbase..prhead"
       else:  
       else:  
         self.commit_range = os.environ['TRAVIS_COMMIT_RANGE']
         self.commit_range = os.environ['TRAVIS_COMMIT_RANGE']
     except KeyError:
     except KeyError:

+ 41 - 0
toolset/setup/travis-ci/add_commit_range.sh

@@ -0,0 +1,41 @@
+#!/bin/bash
+#
+# Our travis setup relies heavily on rapidly cancelling 
+# jobs that are unneeded. For example, if only files
+# in aspnet/ were modified, then we don't need to run 
+# a job that verifies the framework tests in go/
+#
+# Detecting what files have been changed for a pull 
+# request is a a bit tricky, as Travis-CI currently 
+# does not provide a commit range for pull requests
+# (see travis-ci/travis-ci#1719). This script provides
+# a commit range by adding a branch prbase on the 
+# first commit in the pull request and a branch 
+# prhead on the commit that travis is currently 
+# building. 
+
+# This makes 
+#     git diff prbase:prhead 
+# equivalent to what you'd expect from 
+#     git diff $TRAVIS_COMMIT_RANGE
+
+if [ "${TRAVIS_PULL_REQUEST}" = "false" ]
+  then 
+  echo "This is not a pull request, nothing to do"
+  exit 0
+fi
+
+# Find the first commit in the pull request
+#   - download github PR patch file
+#   - grep commit SHA from first line
+#   - remove newline
+PR_FIRST=$(curl -s https://github.com/${TRAVIS_REPO_SLUG}/pull/${TRAVIS_PULL_REQUEST}.patch | head -1 | grep -o -E '\b[0-9a-f]{40}\b' | tr -d '\n')
+
+# Create new branch for first commit in pull request
+git branch -f prbase ${PR_FIRST}
+
+# Create new branch for last commit in pull request
+git branch -f prhead ${TRAVIS_COMMIT}
+
+echo "Set prbase branch to commit ${PR_FIRST}"
+echo "Set prhead branch to commit ${TRAVIS_COMMIT}"