That thing you're not using that you really should.
TLDR The process of telling a computer to run your software tests, builds, and anything else a computer can do automagically.
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
- Go to your GH repo's settings page.
- Go to 'Integrations & Services' and select 'Travis' under the
add service
dropdown. - Click 'Add Service'.
- Go to travis-ci.org and login.
- Next to 'My Repositories' click the
+
and toggle the repo from the list. - Click that the gear icon for that repo.
- Toggle on
Build only if .travis.yml is present
and toggle offBuild pushes
. - Clone your repository locally.
$ git clone https://github.com/your-user/your-repo.git
$ cd your-repo
$ git checkout -b travis-ci
- Add the following
travis.yml
,main.py
, andtest_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
- 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
- In GH, create a PR. Watch Travis begin to build your project in the 'Merge this PR' box.
- Navigate to the TravisCI build page for logs and failure/success info.