2017-08-31 18:42:19 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
## Formatting check script for CircleCI
|
|
|
|
##
|
2017-08-13 00:57:13 +00:00
|
|
|
## Copyright (c) 2012-2014 Sylvain Benner
|
2018-05-20 11:54:20 +00:00
|
|
|
## Copyright (c) 2014-2018 Sylvain Benner & Contributors
|
2017-08-13 00:57:13 +00:00
|
|
|
##
|
|
|
|
## Author: Eugene Yaremenko
|
|
|
|
## URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
##
|
|
|
|
## This file is not part of GNU Emacs.
|
|
|
|
##
|
|
|
|
## License: GPLv3
|
2017-08-07 04:07:33 +00:00
|
|
|
|
2017-08-31 14:26:04 +00:00
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
source "${DIR}/shared"
|
2017-08-07 04:07:33 +00:00
|
|
|
|
2017-09-23 19:43:04 +00:00
|
|
|
if [[ -z "${CIRCLE_PR_NUMBER// }" ]]; then
|
|
|
|
echo "Skipping formatting check for branch update."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2017-09-24 17:45:00 +00:00
|
|
|
pr_patch_URL="https://patch-diff.githubusercontent.com/raw/"
|
|
|
|
pr_patch_URL+="${CIRCLE_PROJECT_USERNAME}/"
|
|
|
|
pr_patch_URL+="${CIRCLE_PROJECT_REPONAME}/pull/"
|
|
|
|
pr_patch_URL+="${CIRCLE_PR_NUMBER}.patch"
|
2017-08-07 04:07:33 +00:00
|
|
|
|
2017-09-24 17:45:00 +00:00
|
|
|
echo "PATCH_URL: \"${pr_patch_URL}\""
|
2017-08-31 14:26:04 +00:00
|
|
|
|
2017-09-24 17:45:00 +00:00
|
|
|
curl "${pr_patch_URL}" --output /tmp/patch --silent
|
2017-08-07 04:07:33 +00:00
|
|
|
first_commit=$(echo $(head -n 1 /tmp/patch) | sed -n 's/From \([a-zA-Z0-9]\+\).*/\1/p')
|
|
|
|
|
|
|
|
if [[ -z "${first_commit// }" ]]; then
|
2017-08-13 00:57:13 +00:00
|
|
|
echo "Can't find first commit"
|
2017-08-07 04:07:33 +00:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "First commit: ${first_commit}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
git diff --name-only "${first_commit}^" HEAD > /tmp/changed_files
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Git diff failed"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
changed_f_as_args=()
|
|
|
|
while read p
|
|
|
|
do
|
|
|
|
if [ -f "$p" ]; then
|
|
|
|
if [ ${p: -4} == ".org" ]; then
|
|
|
|
changed_f_as_args+=("${p}")
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done </tmp/changed_files
|
|
|
|
|
2018-05-23 01:17:55 +00:00
|
|
|
echo_headline "CHECKING FOR MISPLACED SPACES AND TABS:"
|
|
|
|
old_head=$(git rev-parse --short HEAD)
|
|
|
|
git reset -q "${first_commit}^"
|
|
|
|
git add -N .
|
|
|
|
git diff --check --color > space_test_result
|
|
|
|
if [[ -s space_test_result ]]; then
|
|
|
|
cat space_test_result
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
git reset $old_head
|
|
|
|
echo "Done."
|
|
|
|
|
2017-08-07 04:07:33 +00:00
|
|
|
if [ ${#changed_f_as_args[@]} -ne 0 ]; then
|
2017-08-16 15:50:02 +00:00
|
|
|
|
2018-05-20 11:54:20 +00:00
|
|
|
echo_headline "TESTING DOCUMENTATION FORMATTING:"
|
2018-07-19 23:47:51 +00:00
|
|
|
emacs -batch -l /opt/spacedoc/emacs_tools/docfmt/run.el -no-site-file \
|
2018-05-20 11:54:20 +00:00
|
|
|
-q $(printf "%s " "${changed_f_as_args[@]}")
|
2017-08-16 15:50:02 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Documentation formatting script failed"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
git diff --color HEAD > spacefmt_result
|
|
|
|
if [[ -s spacefmt_result ]]; then
|
|
|
|
echo_headline "PLEASE APPLY CHANGES BELOW:"
|
|
|
|
cat spacefmt_result
|
2018-08-22 15:18:05 +00:00
|
|
|
git diff HEAD > /tmp/format.patch
|
|
|
|
bar=$(curl -sF 'file=@/tmp/format.patch' https://file.io)
|
|
|
|
uploaded=$(echo $bar | jq '.success')
|
|
|
|
if [ "${uploaded}" = true ] ; then
|
|
|
|
patch_link=$(echo $bar | jq '.link')
|
|
|
|
echo
|
|
|
|
echo_headline "You can run this commands:"
|
|
|
|
echo "curl ${patch_link} | git apply -v --index"
|
|
|
|
echo "git commit -m \"fixed formatting\""
|
|
|
|
echo "git push"
|
|
|
|
printf '=%.0s' {1..80}
|
|
|
|
fi
|
2017-08-16 15:50:02 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-05-20 11:54:20 +00:00
|
|
|
echo_headline "TESTING DOCUMENTATION WITH SDN EXPORT:"
|
2018-07-19 23:47:51 +00:00
|
|
|
emacs -batch -l /opt/spacedoc/emacs_tools/export/run.el -no-site-file \
|
2018-05-20 11:54:20 +00:00
|
|
|
-q /root/.emacs.d/ $(printf "%s " "${changed_f_as_args[@]}")
|
2017-08-07 04:07:33 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Documentation needs some fixing ;)"
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-08-16 15:50:02 +00:00
|
|
|
else
|
|
|
|
echo "This commit doesn't change documentation files."
|
2017-08-07 04:07:33 +00:00
|
|
|
fi
|
|
|
|
|
2017-08-16 15:50:02 +00:00
|
|
|
echo "All test passed."
|