1
0
mirror of https://github.com/ru-de/faq.git synced 2024-11-29 22:02:19 +00:00
faq-de/pages/files/ci/check.sh

60 lines
2.4 KiB
Bash
Raw Normal View History

2016-01-18 23:38:49 +00:00
#!/bin/bash
2016-01-19 08:15:30 +00:00
DIR=`dirname $0`
2016-01-18 23:38:49 +00:00
2018-01-14 14:53:37 +00:00
git config --global core.quotepath false
2020-11-12 22:42:41 +00:00
PULL_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
2020-11-12 22:42:41 +00:00
curl "https://github-api-bot.herokuapp.com/diff?repo=${GITHUB_REPOSITORY}&pr=${PULL_NUMBER}" > /tmp/pr.diff
2018-08-08 20:16:16 +00:00
if [ "$?" != "0" ]; then
echo "Can't get github pull request diff, probably rate limit? Try to restart CI build"
exit 1
fi
2018-05-06 00:29:15 +00:00
cat /tmp/pr.diff | diff_liner > /tmp/pr_liner.json
2016-01-18 23:38:49 +00:00
2018-05-06 00:29:15 +00:00
rm -f /tmp/comments.json
touch /tmp/comments.json
2020-11-12 22:42:41 +00:00
curl -s -X GET -G https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${PULL_NUMBER}/files | jq -r '.[] | .filename' | grep "^D" -v | sed 's/^.\t//g' | grep "\.md$" > /tmp/changed_files
2018-05-06 00:29:15 +00:00
while read FILE; do
COMMIT=$(git log --pretty=format:"%H" -1 "$FILE");
echo "Проверка изменений в файле $FILE на опечатки... ";
2016-01-18 23:38:49 +00:00
2018-05-06 00:29:15 +00:00
cat "$FILE" | sed 's/https\?:[^ ]*//g' | sed "s/[(][^)]*\.md[)]//g" | sed "s/[(]files[^)]*[)]//g" | hunspell -d dictionary,russian-aot-utf8,ru_RU,de_DE-utf8,en_US-utf8 > /tmp/hunspell.out
cat /tmp/hunspell.out | hunspell_parser > /tmp/hunspell_parsed.json
/tmp/check_spell -file "$FILE" -commit=$COMMIT -pr-liner /tmp/pr_liner.json -hunspell-parsed-file /tmp/hunspell_parsed.json >> /tmp/comments.json
2018-05-06 00:29:15 +00:00
echo "Проверка изменений в файле $FILE на недоступные ссылки... ";
2016-01-18 23:38:49 +00:00
2020-11-12 22:42:41 +00:00
/tmp/check_links -file "$FILE" -commit=$COMMIT -pr-liner /tmp/pr_liner.json -expected-codes files/ci/expected_codes.csv >> /tmp/comments.json
2017-01-12 23:27:07 +00:00
2018-05-06 00:29:15 +00:00
echo
done < /tmp/changed_files
2018-05-06 00:29:15 +00:00
jq -s '[.[][]]' /tmp/comments.json > /tmp/comments_array.json
2017-01-12 23:27:07 +00:00
2018-05-13 20:22:55 +00:00
cat /tmp/comments_array.json
2018-06-07 20:10:19 +00:00
EXIT_CODE=0
2017-01-12 23:27:07 +00:00
2018-06-07 20:10:19 +00:00
if [ "$(cat /tmp/comments_array.json)" != "[]" ]; then
2020-11-12 22:42:41 +00:00
curl "https://github-api-bot.herokuapp.com/comments?repo=${GITHUB_REPOSITORY}&pr=${PULL_NUMBER}" > /tmp/pr_comments.json
2018-05-13 21:36:32 +00:00
2018-08-08 20:16:16 +00:00
if [ "$?" != "0" ]; then
echo "Can't get github comments, probably rate limit? Try to restart ci build"
exit 1
fi
2018-05-13 21:36:32 +00:00
github_comments_diff -comments /tmp/comments_array.json -exists-comments /tmp/pr_comments.json > /tmp/send_comments.json
2020-11-12 22:42:41 +00:00
curl -XPOST "https://github-api-bot.herokuapp.com/send_review?repo=${GITHUB_REPOSITORY}&pr=${PULL_NUMBER}&body=Спасибо%20за%20PR.%20Обратите%20внимание%20на%20результаты%20автоматической%20проверки%20орфографии%20и%20ссылок" -d @/tmp/send_comments.json
2018-06-07 20:10:19 +00:00
EXIT_CODE=1
2018-05-06 00:29:15 +00:00
fi
2016-01-19 08:52:01 +00:00
exit $EXIT_CODE