From 5e51dc9f51736abe76f8c52c595b33b3e15147cf Mon Sep 17 00:00:00 2001 From: Evgeniy Sokolov Date: Tue, 2 Jan 2018 16:28:17 +0100 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20travis=20=D0=B8=20=D0=BB=D0=BE=D0=BA?= =?UTF-8?q?=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20docker-compose=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BE=D0=BA?= =?UTF-8?q?=20(#327)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 13 ++----------- files/Dockerfile | 9 +++++++++ files/check-install.sh | 32 ++++++++++++++++++++++++++++++++ files/{.travis.sh => check.sh} | 32 ++++++++++++++++---------------- files/docker-compose.yml | 12 ++++++++++++ 5 files changed, 71 insertions(+), 27 deletions(-) create mode 100644 files/Dockerfile create mode 100644 files/check-install.sh rename files/{.travis.sh => check.sh} (71%) create mode 100644 files/docker-compose.yml diff --git a/.travis.yml b/.travis.yml index 99d2d0d..ce84e32 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,19 +3,10 @@ sudo: required before_install: - export GOPATH="${TRAVIS_BUILD_DIR}/Godeps/_workspace:$GOPATH" - export PATH="${TRAVIS_BUILD_DIR}/Godeps/_workspace/bin:$PATH" - - sudo apt-get -qq update - - sudo apt-get install -y hunspell hunspell-ru hunspell-en-us hunspell-de-de - - curl -s https://extensions.libreoffice.org/extensions/russian-spellcheck-dictionary.-based-on-works-of-aot-group > .dict_page - - cat .dict_page | grep -oP " .current_release - - echo -n $(cat .current_release) > .current_release - - echo -n "/@@download[^\"]+" >> .current_release - - cat .dict_page | grep -oP -f .current_release | wget -q -i - -O dictionary.otx - - unzip dictionary.otx - - git config core.quotepath false - - go get -u github.com/russross/blackfriday-tool + - sudo env PATH=$PATH GOPATH=$GOPATH sh files/check-install.sh script: - - sh files/.travis.sh + - sh files/check.sh notifications: email: false diff --git a/files/Dockerfile b/files/Dockerfile new file mode 100644 index 0000000..d573a6a --- /dev/null +++ b/files/Dockerfile @@ -0,0 +1,9 @@ +# check https://docs.travis-ci.com/user/common-build-problems/#Running-a-Container-Based-Docker-Image-Locally +FROM travisci/ci-garnet:packer-1512502276-986baf0 +MAINTAINER Evgenii Sokolov + +ENV GOPATH "/home/travis/gopath" +ENV GOROOT "/home/travis/.gimme/versions/go1.7.4.linux.amd64" +ENV PATH "$GOPATH/bin:$GOROOT/bin:$PATH" +COPY check-install.sh /tmp +RUN sh /tmp/check-install.sh diff --git a/files/check-install.sh b/files/check-install.sh new file mode 100644 index 0000000..3dceb3d --- /dev/null +++ b/files/check-install.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +set -e + +apt-get -qq update +apt-get install -y hunspell hunspell-ru hunspell-en-us hunspell-de-de +curl -s https://extensions.libreoffice.org/extensions/russian-spellcheck-dictionary.-based-on-works-of-aot-group > .dict_page +cat .dict_page | grep -oP " .current_release +echo -n $(cat .current_release) > .current_release +echo -n "/@@download[^\"]+" >> .current_release +cat .dict_page | grep -oP -f .current_release | wget -q -i - -O /tmp/dictionary.otx +unzip /tmp/dictionary.otx -d /tmp +cp /tmp/*.dic /usr/share/hunspell +cp /tmp/*.aff /usr/share/hunspell +chmod +r /usr/share/hunspell/* + +dicList=""russian-aot"" +for dic in $dicList + do + cat /usr/share/hunspell/$dic.dic | iconv --from KOI8-R --to UTF-8 > /usr/share/hunspell/$dic-utf8.dic + cat /usr/share/hunspell/$dic.aff | iconv --from KOI8-R --to UTF-8 | sed 's/SET KOI8-R/SET UTF-8/' > /usr/share/hunspell/$dic-utf8.aff +done + +dicList=""de_DE" "en_US"" +for dic in $dicList + do + cat /usr/share/hunspell/$dic.dic | iconv --from ISO8859-1 --to UTF-8 > /usr/share/hunspell/$dic-utf8.dic + cat /usr/share/hunspell/$dic.aff | iconv --from ISO8859-1 --to UTF-8 | sed 's/SET ISO8859-1/SET UTF-8/' > /usr/share/hunspell/$dic-utf8.aff +done + +git config --global core.quotepath false +go get -u github.com/russross/blackfriday-tool diff --git a/files/.travis.sh b/files/check.sh similarity index 71% rename from files/.travis.sh rename to files/check.sh index 2da5592..eab31dc 100644 --- a/files/.travis.sh +++ b/files/check.sh @@ -3,21 +3,20 @@ DIR=`dirname $0` EXIT_CODE=0 -find *.md -exec blackfriday-tool {} {}.html \; -go build -o $DIR/spell-checker $DIR/spell-checker.go +cat $DIR/dictionary.dic | tr '\n' '|' | sed 's/\x27/\\x27/g' > /tmp/dictionary_processed -cat $DIR/dictionary.dic | tr '\n' '|' | sed 's/\x27/\\x27/g' > dictionary_processed - -DICT_REGEXP=$(cat dictionary_processed | sed 's/|/[^[:alnum:]]\\|/g') -DICT_REGEXP_EOF=$(cat dictionary_processed | sed 's/|$//g' | sed 's/|/$\\|/g') +DICT_REGEXP=$(cat /tmp/dictionary_processed | sed 's/|/[^[:alnum:]]\\|/g') +DICT_REGEXP_EOF=$(cat /tmp/dictionary_processed | sed 's/|$//g' | sed 's/|/$\\|/g') DICT_REGEXP="$DICT_REGEXP$DICT_REGEXP_EOF$" -git diff HEAD^ --name-status | grep "^D" -v | sed 's/^.\t//g' | grep "\.md$" > changed_files +git diff HEAD^ --name-status | grep "^D" -v | sed 's/^.\t//g' | grep "\.md$" > /tmp/changed_files + +go build -o /tmp/spell-checker $DIR/spell-checker.go while read FILE; do echo -n "Проверка файла $FILE на опечатки... "; - OUTPUT=$(cat "$FILE" | sed "s/$DICT_REGEXP//gi" | sed 's/https\?:[^ ]*//g' | sed "s/[(][^)]*\.md[)]//g" | hunspell -d russian-aot,ru_RU,de_DE,en_US | $DIR/spell-checker); + OUTPUT=$(cat "$FILE" | sed "s/$DICT_REGEXP//gi" | sed 's/https\?:[^ ]*//g' | sed "s/[(][^)]*\.md[)]//g" | hunspell -d russian-aot-utf8,ru_RU,de_DE-utf8,en_US-utf8 | /tmp/spell-checker); OUTPUT_EXIT_CODE=$? if [ $OUTPUT_EXIT_CODE -ne 0 ]; then @@ -28,14 +27,13 @@ while read FILE; do echo "пройдена"; fi - echo -done < changed_files + rm -f /tmp/file.html + blackfriday-tool $FILE /tmp/file.html -while read FILE; do - if [ -f "${FILE}.html" ]; then - grep -Po '(?<=href=")http[^"]*(?=")' "${FILE}.html" > links + if [ -f "/tmp/file.html" ]; then + grep -Po '(?<=href=")http[^"]*(?=")' "/tmp/file.html" > /tmp/links - if [ -s links ]; then + if [ -s /tmp/links ]; then echo "Проверка файла $FILE на недоступные ссылки... "; while read LINK; do @@ -54,11 +52,13 @@ while read FILE; do echo fi - done < links + done < /tmp/links echo fi fi -done < changed_files + + echo +done < /tmp/changed_files exit $EXIT_CODE diff --git a/files/docker-compose.yml b/files/docker-compose.yml new file mode 100644 index 0000000..f946b1b --- /dev/null +++ b/files/docker-compose.yml @@ -0,0 +1,12 @@ +version: "3.2" + +services: + ru_de_checker: + build: + context: . + dockerfile: Dockerfile + container_name: ru_de_checker + user: travis + command: bash -c "env && cd /home/travis/ru-de-faq && sh files/check.sh" + volumes: + - ../.:/home/travis/ru-de-faq