diff --git a/.ci/after_failure.sh b/.ci/after_failure.sh new file mode 100755 index 000000000..ca758e464 --- /dev/null +++ b/.ci/after_failure.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +if [ "$TRAVIS_PULL_REQUEST" != "false" ] ; then + if [ "$LINT" = "vimlint-errors" ] ; then + if [[ -f build_log ]]; then + if [[ -d build/GitHub.vim ]]; then + rm -rf build/GitHub.vim + fi + VIMLINT_LOG=`cat build_log` + echo "$VIMLINT_LOG" + git clone https://github.com/wsdjeg/GitHub.vim.git build/GitHub.vim + docker run -it --rm \ + -v $PWD/.ci:/.ci \ + -v $PWD/build:/build \ + spacevim/vims neovim-stable -u .ci/common/github_commenter.vim + rm build_log + fi + elif [ "$LINT" = "vint-errors" ] ; then + if [[ -f build_log ]]; then + if [[ -d build/GitHub.vim ]]; then + rm -rf build/GitHub.vim + fi + VIMLINT_LOG=`cat build_log` + echo "$VIMLINT_LOG" + git clone https://github.com/wsdjeg/GitHub.vim.git build/GitHub.vim + docker run -it --rm \ + -v $PWD/.ci:/.ci \ + -v $PWD/build:/build \ + spacevim/vims neovim-stable -u .ci/common/github_commenter.vim + rm build_log + fi + elif [ "$LINT" = "vader" ] ; then + echo "" + fi +fi diff --git a/.ci/after_success.sh b/.ci/after_success.sh new file mode 100755 index 000000000..e69de29bb diff --git a/.ci/common/github_commenter.vim b/.ci/common/github_commenter.vim new file mode 100644 index 000000000..0885e967d --- /dev/null +++ b/.ci/common/github_commenter.vim @@ -0,0 +1,48 @@ +exe 'set nocp' +set rtp+=build/GitHub.vim +so build/GitHub.vim/plugin/github.vim +so build/GitHub.vim/autoload/github/api/issues.vim +so build/GitHub.vim/autoload/github/api/util.vim +let s:log = filereadable('build_log') ? system('cat build_log') : '' +function! s:update_log(log, summary, new_log) abort + let log = split(a:log, "\n") + let begin = -1 + let end = -1 + for i in range(len(log)) + if log[i] =~ a:summary + let begin = i + endif + if begin != -1 && log[i] ==# '' + let end = i + endif + endfor + return a:log . "\n" . a:new_log + +endfunction +if !empty(s:log) + if $LINT == 'vader' + let s:summary = $VIM . ' ' . $LINT . ' build log' + else + let s:summary = $LINT . ' build log' + endif + let s:log = '
' . s:summary . "\n" . s:log . "\n
" + let s:comments = github#api#issues#List_comments('SpaceVim', 'SpaceVim',$TRAVIS_PULL_REQUEST ,'') + if empty(s:comments) + call github#api#issues#Create_comment('SpaceVim','SpaceVim', $TRAVIS_PULL_REQUEST, {'body': s:log}, 'SpaceVimBot', $BOTSECRET) + else + let s:nr = 0 + for s:comment in s:comments + if s:comment.user.login ==# 'SpaceVimBot' + let s:nr = s:comment.id + break + endif + endfor + if s:nr == 0 + call github#api#issues#Create_comment('SpaceVim','SpaceVim', $TRAVIS_PULL_REQUEST, {'body': s:log}, 'SpaceVimBot', $BOTSECRET) + else + call github#api#issues#Edit_comment('SpaceVim','SpaceVim', s:nr, + \ {'body': s:update_log(s:comment.body, s:summary, s:log)}, 'SpaceVimBot', $BOTSECRET) + endif + endif +endif +quit diff --git a/.ci/install.ps1 b/.ci/install.ps1 old mode 100644 new mode 100755 diff --git a/.ci/install.sh b/.ci/install.sh new file mode 100755 index 000000000..0d773384e --- /dev/null +++ b/.ci/install.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# Fail on unset variables and command errors +set -ue -o pipefail + +# Prevent commands misbehaving due to locale differences +export LC_ALL=C + +docker pull spacevim/vims + +git fetch origin dev:dev + +if [ "${LINT#vimlint}" != "$LINT" ]; then + git clone --depth=1 https://github.com/syngan/vim-vimlint /tmp/vimlint + git clone --depth=1 https://github.com/ynkdir/vim-vimlparser /tmp/vimlparser +elif [ "${LINT#vint}" != "$LINT" ]; then + pip install vim-vint +elif [ "${LINT#vader}" != "$LINT" ]; then + git clone --depth=1 https://github.com/Shougo/dein.vim.git ~/.cache/vimfiles/repos/github.com/Shougo/dein.vim +fi diff --git a/.ci/install/linux.sh b/.ci/install/linux.sh new file mode 100644 index 000000000..e3cd0f12d --- /dev/null +++ b/.ci/install/linux.sh @@ -0,0 +1,55 @@ +install_vim() { + local URL=https://github.com/vim/vim + local tag=$1 + local ext=$([[ $tag == "HEAD" ]] && echo "" || echo "-b $tag") + local tmp="$(mktemp -d)" + local out="$HOME/cache/vim-$tag" + local ncpu=$(awk '/^processor/{n+=1}END{print n}' /proc/cpuinfo) + git clone --depth 1 --single-branch $ext $URL $tmp + cd $tmp + ./configure --prefix=$out \ + --enable-fail-if-missing \ + --with-features=huge \ + --enable-pythoninterp \ + --enable-python3interp \ + --enable-luainterp + make -j$ncpu + make install + ln -s $out $HOME/vim +} + +install_nvim() { + local URL=https://github.com/neovim/neovim + local tag=$1 + local ext=$([[ $tag == "HEAD" ]] && echo "" || echo "-b $tag") + local tmp="$(mktemp -d)" + local out="$HOME/cache/nvim-$tag" + local ncpu=$(awk '/^processor/{n+=1}END{print n}' /proc/cpuinfo) + git clone --depth 1 --single-branch $ext $URL $tmp + cd $tmp + make deps + make -j$ncpu \ + CMAKE_BUILD_TYPE=Release \ + CMAKE_EXTRA_FLAGS="-DTRAVIS_CI_BUILD=ON -DCMAKE_INSTALL_PREFIX:PATH=$out" + make install + python -m pip install --user neovim + python3 -m pip install --user neovim + ln -sf $out $HOME/vim +} + +install() { + local vim=$1 + local tag=$2 + + [[ -d $HOME/vim ]] && rm -f $HOME/vim + if [[ $tag != "HEAD" ]] && [[ -d "$HOME/cache/$vim-$tag" ]]; then + echo "Use a cached version '$HOME/cache/$vim-$tag'." + ln -sf $HOME/cache/$vim-$tag $HOME/vim + return + fi + if [[ $vim == "nvim" ]]; then + install_nvim $tag + else + install_vim $tag + fi +} diff --git a/.ci/script.sh b/.ci/script.sh new file mode 100755 index 000000000..e8942c175 --- /dev/null +++ b/.ci/script.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +set -ex +if [ "$LINT" = "vimlint" ]; then + for file in $(git diff --name-only HEAD dev | grep .vim$); + do + sh /tmp/vimlint/bin/vimlint.sh -l /tmp/vimlint -p /tmp/vimlparser $file; + done +elif [ "$LINT" = "vimlint-errors" ]; then + if [[ -f build_log ]]; then + rm build_log + fi + for file in $(git diff --name-only HEAD dev | grep .vim$); + do + /tmp/vimlint/bin/vimlint.sh -E -l /tmp/vimlint -p /tmp/vimlparser $file >> build_log; + done + if [[ -f build_log ]]; then + cat build_log + exit 2 + fi +elif [ "$LINT" = "vint" ]; then + vint . +elif [ "$LINT" = "vint-errors" ]; then + vint --error . +elif [ "$LINT" = "vader" ]; then + pip install covimerage + make test_coverage + covimerage -vv xml --omit 'build/*' + pip install codecov + codecov -X search gcov pycov -f coverage.xml +fi +set +x diff --git a/.travis.yml b/.travis.yml index d8a2878fb..464d7eaff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,13 @@ language: python +dist: trusty sudo: false +services: + - docker + +git: + depth: 3 + notifications: slack: on_success: never @@ -9,62 +16,27 @@ notifications: on_success: never # default: change on_failure: never # default: always cache: - pip: true + - directories: + - $HOME/cache/ env: global: - - DEPS=$HOME/deps - - PATH=$DEPS/bin:$PATH - matrix: - - LINT=vimlint-errors - - LINT=vimlint - - LINT=vint-errors - - LINT=vint - - LINT=vader + - PATH=$HOME/vim/bin:$PATH -matrix: +jobs: + include: + - env: LINT=vimlint-errors VIM=nvim VIM_VERSION=v0.2.0 + - env: LINT=vimlint VIM=nvim VIM_VERSION=v0.2.0 + - env: LINT=vint-errors VIM=nvim VIM_VERSION=v0.2.0 + - env: LINT=vint VIM=nvim VIM_VERSION=v0.2.0 + - env: LINT=vader VIM=vim VIM_VERSION=v8.0.0027 + - env: LINT=vader VIM=nvim VIM_VERSION=v0.2.0 allow_failures: - - env: LINT=vimlint - - env: LINT=vint + - env: LINT=vimlint VIM=nvim VIM_VERSION=v0.2.0 + - env: LINT=vint VIM=nvim VIM_VERSION=v0.2.0 -install: - - | - set -e - if [ "${LINT#vimlint}" != "$LINT" ]; then - git clone --depth=1 https://github.com/syngan/vim-vimlint /tmp/vimlint - git clone --depth=1 https://github.com/ynkdir/vim-vimlparser /tmp/vimlparser - elif [ "${LINT#vint}" != "$LINT" ]; then - virtualenv /tmp/vint && source /tmp/vint/bin/activate && pip install vim-vint - elif [ "${LINT#vader}" != "$LINT" ]; then - git clone --depth=1 https://github.com/Shougo/dein.vim.git ~/.cache/vimfiles/repos/github.com/Shougo/dein.vim - C_OPTS="--prefix=$DEPS --with-features=huge --disable-gui --enable-pythoninterp" - (git clone --depth 1 https://github.com/vim/vim /tmp/vim && - cd /tmp/vim && - ./configure $C_OPTS && - make install) - fi -script: - - | - set -ex - if [ "$LINT" = "vimlint" ]; then - for file in $(git diff --name-only HEAD dev | grep .vim$); - do - sh /tmp/vimlint/bin/vimlint.sh -l /tmp/vimlint -p /tmp/vimlparser $file; - done - elif [ "$LINT" = "vimlint-errors" ]; then - for file in $(git diff --name-only HEAD dev | grep .vim$); - do - sh /tmp/vimlint/bin/vimlint.sh -E -l /tmp/vimlint -p /tmp/vimlparser $file; - done - elif [ "$LINT" = "vint" ]; then - vint . - elif [ "$LINT" = "vint-errors" ]; then - vint --error . - elif [ "$LINT" = "vader" ]; then - pip install covimerage - make test_coverage - covimerage -vv xml --omit 'build/*' - pip install codecov - codecov -X search gcov pycov -f coverage.xml - fi - set +x + +install: .ci/install.sh +script: .ci/script.sh +after_success: .ci/after_success.sh +after_failure: .ci/after_failure.sh diff --git a/Makefile b/Makefile index 5264f7965..2f42f114a 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,18 @@ +DOCKER = docker run -it --rm -v $(PWD):/testplugin -v $(PWD)/test:/test -v $(PWD)/build:/build "spacevim/vims" + +ifeq ($(VIM),nvim) + DEFAULT_VIM:=$(DOCKER) neovim-stable +else + DEFAULT_VIM:=$(DOCKER) vim8 +endif + test: build/vader | build - vim -Nu test/vimrc -c 'Vader! test/**' + $(DEFAULT_VIM) -Nu test/vimrc -c 'Vader! test/**' COVIMERAGE=$(shell command -v ccovimerage 2>/dev/null || echo build/covimerage/bin/covimerage) test_coverage: $(COVIMERAGE) build/vader | build - $(COVIMERAGE) run vim -Nu test/vimrc -c 'Vader! test/**' + $(COVIMERAGE) run $(DEFAULT_VIM) -Nu test/vimrc -c 'Vader! test/**' build/covimerage: virtualenv $@ diff --git a/config/functions.vim b/config/functions.vim index cc756e5f8..61f9ccee3 100644 --- a/config/functions.vim +++ b/config/functions.vim @@ -204,3 +204,11 @@ fu! UpdateStarredRepos() endfor return 1 endf + + +function! TestBot(argv) abort +endfunction + +function! TestBot(argv) abort + +endfunction