Browse Source

Move Travis-CI setup inside run-ci so it can be skipped if unneeded

Hamilton Turner 11 years ago
parent
commit
b35c7227a6
2 changed files with 39 additions and 27 deletions
  1. 1 25
      .travis.yml
  2. 38 2
      toolset/run-ci.py

+ 1 - 25
.travis.yml

@@ -150,31 +150,8 @@ env:
     - TESTDIR=yesod
 
 before_install:
-  - sudo apt-get update
-  - sudo apt-get install openssh-server
-  
-  # Needed to cancel build jobs from run-ci.py
-  # Only install travis command line if this is not a pull request
-  # as it takes a long time and is not used for pull requests
-  - '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && time gem install travis -v 1.6.16 --no-rdoc --no-ri || true'
- 
-  # Run as travis use (who has passwordless sudo)
-  - ssh-keygen -f /home/travis/.ssh/id_rsa -N '' -t rsa  
-  - cat /home/travis/.ssh/id_rsa.pub > /home/travis/.ssh/authorized_keys
-  - chmod 600 /home/travis/.ssh/authorized_keys
-  
-  # Setup database manually
-  # NOTE: Do not run database installation! It restarts mysql with a different 
-  # configuration and will break travis's mysql setup
-  - mysql -uroot < config/create.sql
-  
-  # Setup Postgres
-  - psql --version
-  - sudo useradd benchmarkdbuser -p benchmarkdbpass
-  - sudo -u postgres psql template1 < config/create-postgres-database.sql
-  - sudo -u benchmarkdbuser psql hello_world < config/create-postgres.sql
-  
   - time ./toolset/run-ci.py cisetup
+
 addons:
   postgresql: "9.3" 
 
@@ -183,7 +160,6 @@ install:
   - time ./toolset/run-ci.py install $TESTDIR
    
 script: 
-  # Run test verification 
   - time ./toolset/run-ci.py verify $TESTDIR
 
 notifications:

+ 38 - 2
toolset/run-ci.py

@@ -52,7 +52,7 @@ class CIRunnner:
       log.warning("I should only be used for automated integration tests e.g. Travis-CI")
       log.warning("Were you looking for run-tests.py?")
       last_commit = subprocess.check_output("git rev-parse HEAD^", shell=True).rstrip('\n')
-      self.commit_range = "%s...master" % last_commit
+      self.commit_range = "%s...HEAD" % last_commit
 
     log.info("Using commit range %s", self.commit_range)
     log.info("Running `git diff --name-only %s`" % self.commit_range)
@@ -179,7 +179,43 @@ class CIRunnner:
       return 1
 
   def run_travis_setup(self):
-    print "running travis setup"
+    log.info("Setting up Travis-CI")
+    
+    script = '''
+    sudo apt-get update
+    sudo apt-get install openssh-server
+
+    # Run as travis user (who already has passwordless sudo)
+    ssh-keygen -f /home/travis/.ssh/id_rsa -N '' -t rsa
+    cat /home/travis/.ssh/id_rsa.pub > /home/travis/.ssh/authorized_keys
+    chmod 600 /home/travis/.ssh/authorized_keys
+
+    # Setup database manually
+    # NOTE: Do not run database installation! It restarts mysql with a different
+    # configuration and will break travis's mysql setup
+    mysql -uroot < config/create.sql
+
+    # Setup Postgres
+    psql --version
+    sudo useradd benchmarkdbuser -p benchmarkdbpass
+    sudo -u postgres psql template1 < config/create-postgres-database.sql
+    sudo -u benchmarkdbuser psql hello_world < config/create-postgres.sql
+    '''
+
+    def sh(command):
+      log.info("Running `%s`", command)
+      subprocess.check_call(command, shell=True)  
+
+    for command in script.split('\n'):
+      command = command.lstrip()
+      if command != "" and command[0] != '#':
+        sh(command.lstrip())
+
+    # Needed to cancel build jobs from run-ci.py
+    if not self.travis.is_pull_req:
+      sh('time gem install travis -v 1.6.16 --no-rdoc --no-ri')
+
+
 
   def cancel_unneeded_jobs(self):
     log.info("I am jobcleaner")