Skip to content

Instantly share code, notes, and snippets.

@elarib
Forked from fulldecent/travis-local.md
Last active November 21, 2020 05:50
Show Gist options
  • Save elarib/acd616d4752a921ba87bc832f934d61f to your computer and use it in GitHub Desktop.
Save elarib/acd616d4752a921ba87bc832f934d61f to your computer and use it in GitHub Desktop.
Run Travis build locally

travis-local.md

Preconditions:

  1. POSIX or Windows system
  2. Install Docker
  3. A GitHub repo that already builds on Travis

Postcondition:

  • Identical output as if run from Travis

Project status:

  • Alpha quality, please post notes here and fork baby fork, I will try to test and accept changes here

Notes:

  1. Install Travis on Docker

    # choose the image according to the language chosen in .travis.yml
    $ docker run -it -u travis quay.io/travisci/travis-jvm /bin/bash
    
    # now that you are in the docker image, switch to the travis user
    sudo su travis
    
    # Install a recent ruby 
    rvm install 2.6.1
    rvm use 2.6.1
    
    # Install travis-build to generate a .sh out of .travis.yml
    cd builds \
    git clone https://github.com/travis-ci/travis-build
    cd travis-build
    mkdir -p ~/.travis
    ln -s $PWD ~/.travis/travis-build
    gem sources -a http://rubygems.org
    gem install bundler
    bundle install --gemfile ~/.travis/travis-build/Gemfile
    bundler binstubs travis
    
    # Create ssh key for Github
    ssh-keygen -t rsa -b 4096 -C “YOUR EMAIL REGISTERED IN GITHUB”
    
    # Click enter to use default location for key
    # You can choose empty passphrase by clicking enter twice
    # Now that we have the key, let’s share with Github
    less ~/.ssh/id_rsa.pub
    
    # Copy the contents of the id_rsa.pub
  2. Go to your Github SSH key settings

  3. Create a new ssh key with title: “docker key”: “PASTE THE KEY CONTENTS HERE”

  4. Go back to docker terminal

    # Create project dir, assuming your project is `AUTHOR/PROJECT` on GitHub
    cd ~/builds \
    mkdir AUTHOR \
    cd AUTHOR \
    git clone git@github.com:AUTHOR/PROJECT.git \
    cd PROJECT
    
    # change to the branch or commit you want to investigate
    # compile travis script into bash script
    travis compile > ci.sh
    
    # Go to bash script and fix the branch name
    vi ci.sh
    
    # in Vi type “/branch” to search and add the right branch name
    # — branch\=\’\NEW_BRANCH’\
    # You most likely will need to edit ci.sh as it ignores ‘matrix’ and ‘env’ keywords
    bash ci.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment