From f81fd1ddb69e4a142d42a5d59338daaae1aed150 Mon Sep 17 00:00:00 2001 From: Antonin RAFFIN Date: Thu, 7 May 2020 17:59:51 +0200 Subject: [PATCH] Add travis file --- .travis.yml | 49 +++++++++++++++++++++++++++++++++++++ docs/conf.py | 1 + scripts/run_tests_travis.sh | 32 ++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 .travis.yml create mode 100755 scripts/run_tests_travis.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3333342 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,49 @@ +language: python +python: + - "3.6" + +env: + global: + - DOCKER_IMAGE=stablebaselines/stable-baselines3-cpu:0.6.0a5 + +notifications: + email: false + +services: + - docker + +install: + - docker pull ${DOCKER_IMAGE} + +script: + - ./scripts/run_tests_travis.sh "${TEST_GLOB}" + +jobs: + include: + # Big test suite. Run in parallel to decrease wall-clock time, and to avoid OOM error from leaks + - stage: Test + name: "Unit Tests a-h" + env: TEST_GLOB="[a-h]*" + + - name: "Unit Tests i-l" + env: TEST_GLOB="[i-l]*" + + - name: "Unit Tests m-sa" + env: TEST_GLOB="{[m-r]*,sa*}" + + - name: "Unit Tests sb-z" + env: TEST_GLOB="{s[b-z]*,[t-z]*}" + + - name: "Sphinx Documentation" + script: + - 'docker run -it --rm --mount src=$(pwd),target=/root/code/stable-baselines3,type=bind ${DOCKER_IMAGE} bash -c "cd /root/code/stable-baselines3/ && pushd docs/ && make clean && make html"' + + - name: "Type Checking" + script: + - 'docker run --rm --mount src=$(pwd),target=/root/code/stable-baselines3,type=bind ${DOCKER_IMAGE} bash -c "cd /root/code/stable-baselines3/ && pytype --version && pytype"' + + - stage: Codacy Trigger + if: type != pull_request + script: + # When all test coverage reports have been uploaded, instruct Codacy to start analysis. + - 'docker run -it --rm --network host --ipc=host --mount src=$(pwd),target=/root/code/stable-baselines3,type=bind --env CODACY_PROJECT_TOKEN=${CODACY_PROJECT_TOKEN} ${DOCKER_IMAGE} bash -c "cd /root/code/stable-baselines3/ && java -jar /root/code/codacy-coverage-reporter.jar final"' diff --git a/docs/conf.py b/docs/conf.py index 424ee5e..5768fc6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -218,4 +218,5 @@ texinfo_documents = [ # kornia's hack to get rtd builder to install latest pytorch if on_rtd: + os.system('pip install gym') os.system('pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html') diff --git a/scripts/run_tests_travis.sh b/scripts/run_tests_travis.sh new file mode 100755 index 0000000..ac2650d --- /dev/null +++ b/scripts/run_tests_travis.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +DOCKER_CMD="docker run -it --rm --network host --ipc=host --mount src=$(pwd),target=/root/code/stable-baselines3,type=bind" +BASH_CMD="cd /root/code/stable-baselines3/" + +if [[ $# -ne 1 ]]; then + echo "usage: $0 " + exit 1 +fi + +if [[ ${DOCKER_IMAGE} = "" ]]; then + echo "Need DOCKER_IMAGE environment variable to be set." + exit 1 +fi + +TEST_GLOB=$1 + +set -e # exit immediately on any error + +# For pull requests from fork, Codacy token is not available, leading to build failure +if [[ ${CODACY_PROJECT_TOKEN} = "" ]]; then + echo "WARNING: CODACY_PROJECT_TOKEN not set. Skipping Codacy upload." + echo "(This is normal when building in a fork and can be ignored.)" + ${DOCKER_CMD} ${DOCKER_IMAGE} \ + bash -c "${BASH_CMD} && \ + pytest --cov-config .coveragerc --cov-report term --cov=. -v tests/test_${TEST_GLOB}" +else + ${DOCKER_CMD} --env CODACY_PROJECT_TOKEN=${CODACY_PROJECT_TOKEN} ${DOCKER_IMAGE} \ + bash -c "${BASH_CMD} && \ + pytest --cov-config .coveragerc --cov-report term --cov-report xml --cov=. -v tests/test_${TEST_GLOB} && \ + java -jar /root/code/codacy-coverage-reporter.jar report -l python -r coverage.xml --partial" +fi