From 28dc4afb90b5541076d5e8e785474b714c74de38 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 29 Oct 2019 06:42:19 +0000 Subject: [PATCH] Add Travis CI --- .pre-commit-config.yaml | 27 +++++++++++++++++++++++++++ .travis.yml | 35 +++++++++++++++++++++++++++++++++++ .travis/precommit.sh | 21 +++++++++++++++++++++ .travis/unittest.sh | 29 +++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 .pre-commit-config.yaml create mode 100644 .travis.yml create mode 100755 .travis/precommit.sh create mode 100755 .travis/unittest.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..4102b69a9 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,27 @@ +- repo: https://github.com/PaddlePaddle/mirrors-yapf.git + sha: 0d79c0c469bab64f7229c9aca2b1186ef47f0e37 + hooks: + - id: yapf + files: \.py$ +- repo: https://github.com/pre-commit/pre-commit-hooks + sha: a11d9314b22d8f8c7556443875b731ef05965464 + hooks: + - id: check-merge-conflict + - id: check-symlinks + - id: detect-private-key + files: (?!.*paddle)^.*$ + - id: end-of-file-fixer + files: \.md$ + - id: trailing-whitespace + files: \.md$ +- repo: https://github.com/Lucas-C/pre-commit-hooks + sha: v1.0.1 + hooks: + - id: forbid-crlf + files: \.md$ + - id: remove-crlf + files: \.md$ + - id: forbid-tabs + files: \.md$ + - id: remove-tabs + files: \.md$ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..f085319fa --- /dev/null +++ b/.travis.yml @@ -0,0 +1,35 @@ +language: cpp +cache: ccache +sudo: required +dist: trusty +services: + - docker +os: + - linux +env: + - JOB=PRE_COMMIT + +addons: + apt: + packages: + - git + - python + - python-pip + - python2.7-dev + ssh_known_hosts: 13.229.163.131 +before_install: + - sudo pip install -U virtualenv pre-commit pip + - docker pull paddlepaddle/paddle:latest + +script: + - exit_code=0 + - .travis/precommit.sh || exit_code=$(( exit_code | $? )) + - docker run -i --rm -v "$PWD:/py_unittest" paddlepaddle/paddle:latest /bin/bash -c + 'cd /py_unittest; sh .travis/unittest.sh' || exit_code=$(( exit_code | $? )) + - | + script/deploy_doc.sh + +notifications: + email: + on_success: change + on_failure: always diff --git a/.travis/precommit.sh b/.travis/precommit.sh new file mode 100755 index 000000000..bcbfb2bb5 --- /dev/null +++ b/.travis/precommit.sh @@ -0,0 +1,21 @@ +#!/bin/bash +function abort(){ + echo "Your commit not fit PaddlePaddle code style" 1>&2 + echo "Please use pre-commit scripts to auto-format your code" 1>&2 + exit 1 +} + +trap 'abort' 0 +set -e +cd `dirname $0` +cd .. +export PATH=/usr/bin:$PATH +pre-commit install + +if ! pre-commit run -a ; then + ls -lh + git diff --exit-code + exit 1 +fi + +trap : 0 diff --git a/.travis/unittest.sh b/.travis/unittest.sh new file mode 100755 index 000000000..c4d1b79cc --- /dev/null +++ b/.travis/unittest.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +abort(){ + echo "Run unittest failed" 1>&2 + echo "Please check your code" 1>&2 + exit 1 +} + +unittest(){ + if [ $? != 0 ]; then + exit 1 + fi + find "./ppdet/modeling" -name 'tests' -type d -print0 | \ + xargs -0 -I{} -n1 bash -c \ + 'python -m unittest discover -v -s {}' +} + +trap 'abort' 0 +set -e + +# install python dependencies +if [ -f "requirements.txt" ]; then + pip install -r requirements.txt +fi +export PYTHONPATH=`pwd`:$PYTHONPATH + +unittest . + +trap : 0 -- GitLab