Skip to content

Instantly share code, notes, and snippets.

@pop
Last active February 15, 2017 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pop/01197f361dc0988a0f02d891c8a386f2 to your computer and use it in GitHub Desktop.
Save pop/01197f361dc0988a0f02d891c8a386f2 to your computer and use it in GitHub Desktop.
A talk about using CI

Continuous Integration

That thing you're not using that you really should.

What is CI?

In software engineering, continuous integration (CI) is the practice of merging all developer working copies to a shared mainline several times a day. Grady Booch first named and proposed CI in his 1991 method,[1] although he did not advocate integrating several times a day.

TLDR The process of telling a computer to run your software tests, builds, and anything else a computer can do automagically.

How do I do CI?

There's tons of cool tools out there:

  • Travis
    • Heavy GitHub integration
    • Popular and quick to setup
  • Circle
    • "Ship your own Travis"
  • Jenkins
    • Swiss army knife of CI
    • Very feature rich
  • Buildbot
    • Highly customizable

Demo: Setup Travis on a GitHub repo

  1. Go to your GH repo's settings page.
  2. Go to 'Integrations & Services' and select 'Travis' under the add service dropdown.
  3. Click 'Add Service'.
  4. Go to travis-ci.org and login.
  5. Next to 'My Repositories' click the + and toggle the repo from the list.
  6. Click that the gear icon for that repo.
  7. Toggle on Build only if .travis.yml is present and toggle off Build pushes.
  8. Clone your repository locally.
$ git clone https://github.com/your-user/your-repo.git
$ cd your-repo
$ git checkout -b travis-ci
  1. Add the following travis.yml, main.py, and test_main.py.

travis.yml:

langauge: python
python:
  - "2.6"
  - "2.7"
  - "3.2"
  - "3.3"
  - "3.4"
  - "3.5"
  - "3.5-dev" # 3.5 development branch
  - "3.6"
  - "3.6-dev" # 3.6 development branch
  - "3.7-dev" # 3.7 development branch
  - "nightly" # currently points to 3.7-dev
# command to install dependencies
install: "pip install --user -r requirements.txt"
# command to run tests
script: pytest

main.py:

def rev_sort(x=[]):
    """
    Returns a reverse sorted list
    """
    # TODO: Implement!
    return x

test_main.py:

def test_sorted():
    assert rev_sort([5,4,3,2,1]) == [5,4,3,2,1]

def test_unsorted():
    assert rev_sort([1,3,2,4,5,6]) == [6,5,4,3,2,1]
    
def test_empty():
    assert rev_sort([]) == []

For fun let's just put something in requirements.txt:

pygal
  1. Commit your changes and push them to a new branch.
$ git add .
$ git commit -m "Initial code and travis-ci"
[travis-ci (root-commit) b6d46e6] Initial code and travis-ci
 4 files changed, 31 insertions(+)
 create mode 100644 .travis.yml
 create mode 100644 main.py
 create mode 100644 requirements.txt
 create mode 100644 test_main.py
$ git push origin travis-ci
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 706 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
To https://github.com/your-user/your-repo.git
 * [new branch]      travis-ci -> travis-ci
  1. In GH, create a PR. Watch Travis begin to build your project in the 'Merge this PR' box.
  2. Navigate to the TravisCI build page for logs and failure/success info.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment