From a9599c9e4c10ad2d665e23c399510e2303fbf7a2 Mon Sep 17 00:00:00 2001 From: Kim Neunert Date: Fri, 6 Dec 2019 16:51:00 +0100 Subject: [PATCH] travis-CI integration --- .travis.yml | 46 +++++++++++++++++++++++++++++++ README.md | 2 ++ pytest.ini | 2 ++ tests/conftest.py | 13 ++++++--- tests/install_bitcoind.sh | 57 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 .travis.yml create mode 100644 pytest.ini create mode 100755 tests/install_bitcoind.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..2030a0f76 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,46 @@ +language: python +os: linux +dist: xenial +cache: + pip: true + ccache: true + directories: + - tests/bitcoin + +addons: + apt: + sources: + - sourceline: 'ppa:bitcoin/bitcoin' + packages: + - libdb4.8-dev + - libdb4.8++-dev + - build-essential + - curl + - git + - libsdl2-dev + - libsdl2-image-dev + - gcc-arm-none-eabi + - libnewlib-arm-none-eabi + - libudev-dev + - libtool + - autotools-dev + - automake + - pkg-config + - bsdmainutils + - libssl-dev + - libevent-dev + - libboost-system-dev + - libboost-filesystem-dev + - libboost-chrono-dev + - libboost-test-dev + - libboost-thread-dev + - libusb-1.0-0-dev + - protobuf-compiler + - cython3 + - ccache + +before_install: + - set -o errexit; source ./tests/install_bitcoind.sh +script: + - pip install -e . + - pytest \ No newline at end of file diff --git a/README.md b/README.md index eed71755e..2a6abccb8 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Specter Desktop +[![Build Status](https://travis-ci.org/cryptoadvance/specter-desktop.svg?branch=master)](https://travis-ci.org/cryptoadvance/specter-desktop) + ## DISCLAIMER This software is **WORK IN PROGRESS and NOT READY TO USE YET**. Currently tested only in Chrome, so in other browsers it may look weird. diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 000000000..40ac2d8c8 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +norecursedirs = tests/bitcoin \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index a3950effc..f7fb1bc6a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -54,10 +54,14 @@ def start_bitcoind(bitcoind_path, cleanup_at_exit=True, rpc_port=18543): # This is not needed bitcoind_path += " -datadir={} ".format(datadir) print(" --> About to execute: {}".format(bitcoind_path)) - bitcoind_proc = subprocess.Popen(bitcoind_path, shell=True) + # exec will prevent creating a child-process and will make bitcoind_proc.terminate() work as expected + bitcoind_proc = subprocess.Popen("exec " + bitcoind_path, shell=True) + print(" --> Running bitcoind-process with pid {}".format(bitcoind_proc.pid)) def cleanup_bitcoind(): - bitcoind_proc.kill() + bitcoind_proc.kill() # much faster then terminate() and speed is key here over being nice + print(" --> Killed bitcoind-process with pid {}".format(bitcoind_proc.pid)) shutil.rmtree(datadir) + print(" --> removed temp-dir") if cleanup_at_exit: atexit.register(cleanup_bitcoind) ip_address = '127.0.0.1' @@ -122,7 +126,10 @@ def bitcoin_regtest(docker): if docker: bitcoind_path = 'docker' else: - bitcoind_path = 'bitcoind ' # Let's take the one on the path for now + if os.path.isfile('tests/bitcoin/src/bitcoind'): + bitcoind_path = 'tests/bitcoin/src/bitcoind ' # always prefer the self-compiled bitcoind if existing + else: + bitcoind_path = 'bitcoind ' # Alternatively take the one on the path for now btc_conn['rpc'], btc_conn['rpc_username'], btc_conn['rpc_password'], btc_conn['rpc_host'], btc_conn['rpc_port'] = start_bitcoind(bitcoind_path) return btc_conn diff --git a/tests/install_bitcoind.sh b/tests/install_bitcoind.sh new file mode 100755 index 000000000..48c75995b --- /dev/null +++ b/tests/install_bitcoind.sh @@ -0,0 +1,57 @@ +echo " --> install_bitcoind.sh Start $(date)" +START=$(date +%s.%N) +# Clone bitcoind if it doesn't exist, or update it if it does +# (copied from HWI) +cd tests +bitcoind_setup_needed=false +if [ ! -d "./bitcoin/.git" ]; then + echo " --> cloning bitcoin" + git clone https://github.com/bitcoin/bitcoin.git + cd bitcoin + bitcoind_setup_needed=true +else + cd bitcoin + echo " --> fetching bitcoin" + git fetch +fi + +# Determine if we need to pull. From https://stackoverflow.com/a/3278427 +UPSTREAM=${1:-'@{u}'} +LOCAL=$(git rev-parse @) +if [ -f ../bitcoin_pin ]; then + PINNED=$(cat ../bitcoin_pin) +fi +if [ -z $PINNED ]; then + REMOTE=$(git rev-parse "$UPSTREAM") + BASE=$(git merge-base @ "$UPSTREAM") + if [ $LOCAL = $REMOTE ]; then + echo "Up-to-date" + elif [ $LOCAL = $BASE ]; then + git pull + bitcoind_setup_needed=true + fi +else + if [ $LOCAL = $PINNED ]; then + echo " --> Pinned: $PINNED! Checkout not needed!" + else + echo " --> Pinned: $PINNED! Checkout needed!" + git pull + git checkout $PINNED + bitcoind_setup_needed=true + fi +fi + + +# Build bitcoind. This is super slow, but it is cached so it runs fairly quickly. +if [ "$bitcoind_setup_needed" = "true" ] ; then + echo " --> Setup needed. Starting autogen" + ./autogen.sh + echo " --> Starting configure" + ./configure --with-miniupnpc=no --without-gui --disable-zmq --disable-tests --disable-bench --with-libs=no --with-utils=no +fi +make -j$(nproc) src/bitcoind +cd ../.. #travis is sourcing this script +echo " --> Finished build bitcoind" +END=$(date +%s.%N) +DIFF=$(echo "$END - $START" | bc) +echo " --> install_bitcoind.sh End $(date) took $DIFF" \ No newline at end of file