spacemacs/.circleci/format

104 lines
2.7 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
## Formatting check script for CircleCI
##
## Copyright (c) 2012-2014 Sylvain Benner
2018-05-20 11:54:20 +00:00
## Copyright (c) 2014-2018 Sylvain Benner & Contributors
##
## 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
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-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
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:"
emacs -batch -l /opt/spacedoc/emacs-tools/docfmt/run.el -no-site-file \
-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
exit 1
fi
2018-05-20 11:54:20 +00:00
echo_headline "TESTING DOCUMENTATION WITH SDN EXPORT:"
emacs -batch -l /opt/spacedoc/emacs-tools/export/run.el -no-site-file \
-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
2018-05-20 11:54:20 +00:00
echo_headline "VALIDATING DOCUMENTATION:"
2018-05-23 01:14:58 +00:00
sdn validate /opt/spacedoc/emacs-tools/export/target
2018-05-20 11:54:20 +00:00
if [ $? -ne 0 ]; then
echo "Validation failed."
exit 2
fi
echo "Done."
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."