spacemacs/.circleci/format
2018-05-23 19:14:52 +03:00

104 lines
2.7 KiB
Bash
Executable file

#!/usr/bin/env bash
## Formatting check script for CircleCI
##
## Copyright (c) 2012-2014 Sylvain Benner
## 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
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "${DIR}/shared"
if [[ -z "${CIRCLE_PR_NUMBER// }" ]]; then
echo "Skipping formatting check for branch update."
exit 0
fi
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"
echo "PATCH_URL: \"${pr_patch_URL}\""
curl "${pr_patch_URL}" --output /tmp/patch --silent
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"
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
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."
if [ ${#changed_f_as_args[@]} -ne 0 ]; then
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[@]}")
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
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[@]}")
if [ $? -ne 0 ]; then
echo "Documentation needs some fixing ;)"
exit 1
fi
echo_headline "VALIDATING DOCUMENTATION:"
sdn validate /opt/spacedoc/emacs-tools/export/target
if [ $? -ne 0 ]; then
echo "Validation failed."
exit 2
fi
echo "Done."
else
echo "This commit doesn't change documentation files."
fi
echo "All test passed."