Created
August 26, 2015 22:58
-
-
Save miohtama/1424c0b6169080ef6142 to your computer and use it in GitHub Desktop.
drone.io continuous integration + Python 3.4 + Selenium + SSH key setup for private repos + codecov coverage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Setup test running for Ubuntu 12.02 / Drone IO | |
# | |
# As drone.io build command put: | |
# | |
# # Launch the droneio test script from the repo | |
# bash bin/droneio.bash # Whereever you put this script in your source code control | |
# | |
# | |
# Abort on error | |
set -e | |
# Set this flag if you want to debug output from the bash execution | |
# set -x | |
# This is the name of the project and also name of the Python package | |
PROJECT_NAME=myproject | |
CHECKOUT_HOME=/home/ubuntu/src/bitbucket.org/miohtama/$PROJECT_NAME | |
# Get the private key used to checkout the private repos from Drone IO environment. | |
# This key is used to checkout private repos from Github / Bitbucket. | |
# 1. Create SSH key pair | |
# 2. Create user on Github / Bitbucket, set the public key for this user, then the let the user access to your private repos | |
# 3. Export the private SSH key, convert it to a single line entry, lines separated by comma (replace \n with ,) | |
# In Drone IO project environment variables set the key as SSH_PRIV_KEY="-----BEGIN RSA PRIVATE KEY-----,...,1TX/Pk9TBggjCvIzWEQfm5W1/VSv9TLt6pVFhORPdYMmCItCtjB49w==,-----END RSA PRIVATE KEY-----". | |
# You need to separate lines by comma and store the key as single liner, as the Drone IO settings storage gets confused otherwise. | |
# Example: cat ~/.ssh/key | tr "\n" "," | |
echo $SSH_PRIV_KEY | tr "," "\n" > /tmp/private-key | |
chmod o-wrx,g-rwx /tmp/private-key | |
eval `ssh-agent` | |
ssh-add /tmp/private-key | |
# Need to upgrade to Python 3.4, at the writing of this drone.io only offers Python 3.3 | |
sudo add-apt-repository ppa:fkrull/deadsnakes > /dev/null 2>&1 | |
sudo apt-get -qq update > /dev/null 2>&1 | |
sudo apt-get -qq install python3.4-dev > /dev/null 2>&1 | |
# Creteat test virtualenv | |
python3.4 -m venv venv | |
. venv/bin/activate | |
# Make sure pip itself is up to date | |
echo "Installing requirements" | |
pip install -U --quiet pip | |
pip install -r requirements.txt --quiet | |
# Make sure our script hooks are installed in bin/ | |
python setup.py develop | |
# Create PostgreSQL database for the tests | |
# http://docs.drone.io/databases.html - no IF NOT EXISTS for psql | |
set +e | |
psql -c 'CREATE DATABASE test;' -U postgres | |
set -e | |
# Make sure we have X11 set up so Selenium can launch Firefox | |
sudo start xvfb | |
# Run tests using py.test test runner. We set timeout, so that if a test gets stuck it doesn't hang the run. | |
# We also print 10 slowest tests. | |
echo "Running tests" | |
py.test --splinter-webdriver=firefox --splinter-make-screenshot-on-failure=true --ini=ci.ini --timeout=200 --durations=10 $PROJECT_NAME --cov-report xml --cov trees --cov-config .coveragerc | |
echo "Done with tests" | |
# Upload coverage report to codecov | |
codecov --token=$CODECOV_TOK | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment