spacemacs/.travisci/pub_auto_update.sh

111 lines
2.9 KiB
Bash
Raw Normal View History

2017-08-16 15:50:02 +00:00
#!/usr/bin/env bash
2021-01-08 08:08:08 +00:00
## Auto-update publishing script for Travis CI integration
2017-08-16 15:50:02 +00:00
##
## Copyright (c) 2012-2014 Sylvain Benner
2018-05-19 20:42:12 +00:00
## Copyright (c) 2014-2018 Sylvain Benner & Contributors
2017-08-16 15:50:02 +00:00
##
## Author: Eugene Yaremenko
## URL: https://github.com/syl20bnr/spacemacs
##
## This file is not part of GNU Emacs.
##
## License: GPLv3
2018-10-13 08:47:20 +00:00
fold_start() {
echo -e "travis_fold:start:$1\033[33;1m$2\033[0m"
}
fold_end() {
echo -e "\ntravis_fold:end:$1\r"
2017-08-16 15:50:02 +00:00
}
2018-05-19 20:42:12 +00:00
cd ~/.emacs.d
2017-08-16 15:50:02 +00:00
if [ "$TRAVIS_BRANCH" = "develop" ]; then
2018-10-13 08:47:20 +00:00
PUBLISH="spacemacs"
2018-05-19 20:42:12 +00:00
else
echo "branch is \"${TRAVIS_BRANCH}\". Won't publish."
exit 0
fi
2017-08-19 13:45:24 +00:00
2019-12-09 21:40:56 +00:00
export GITHUB_TOKEN=$BOT_TK
2018-10-13 08:47:20 +00:00
fold_start "CLONING_TARGET_REPOSITORY"
2019-01-22 18:07:06 +00:00
target_URL="https://github.com/${SPACEMACS_REPO_SLUG}.git"
2018-10-13 08:47:20 +00:00
git clone "${target_URL}" -b "${TRAVIS_BRANCH}" "/tmp/${PUBLISH}"
2018-05-19 20:42:12 +00:00
if [ $? -ne 0 ]; then
echo "Failed to clone \"${target_URL}\""
exit 2
fi
2018-10-13 08:47:20 +00:00
fold_end "CLONING_TARGET_REPOSITORY"
2021-01-08 08:08:08 +00:00
fold_start "APPLYING_DOCUMENTATION_PATCH"
cd "/tmp/${PUBLISH}"
2019-12-09 21:01:48 +00:00
if [ ! -f /tmp/docfmt.patch ]; then
echo "Documentation doesn't need fixes. Aborting."
2021-01-08 08:58:05 +00:00
else
git am < /tmp/docfmt.patch
if [ $? -ne 0 ]; then
echo "Failed to apply documentation fixes patch"
exit 2
fi
2018-05-19 20:42:12 +00:00
fi
2021-01-08 08:08:08 +00:00
fold_end "APPLYING_DOCUMENTATION_PATCH"
fold_start "APPLYING_BUILT_IN_PATCH"
cd "/tmp/${PUBLISH}"
if [ ! -f /tmp/built_in.patch ]; then
echo "Built-in files don't need updating. Aborting."
2021-01-08 08:58:05 +00:00
else
git am < /tmp/built_in.patch
if [ $? -ne 0 ]; then
echo "Failed to apply built-in patch."
exit 2
fi
2021-01-08 08:08:08 +00:00
fi
fold_end "APPLYING_BUILT_IN_PATCH"
2017-08-16 15:50:02 +00:00
2019-12-09 20:47:10 +00:00
fold_start "CHECKING_IF_SPACEMACS_HEAD_IS_THE_SAME"
cd ~/.emacs.d
git remote update
2019-12-09 21:28:20 +00:00
base_revision=$(cat /tmp/base_revision)
2019-12-09 20:47:10 +00:00
rem_rev=$(git rev-parse '@{u}')
2019-12-09 21:28:20 +00:00
echo "Base revision: $base_revision"
2019-12-09 20:47:10 +00:00
echo "Remote revision: $rem_rev"
2019-12-09 21:28:20 +00:00
if [ "$base_revision" != "$rem_rev" ]; then
2021-01-08 08:08:08 +00:00
echo "Looks like Spacemacs head has changed since CI started."
2019-12-09 20:47:10 +00:00
echo "Aborting."
exit 0
fi
fold_end "CHECKING_IF_SPACEMACS_HEAD_IS_THE_SAME"
2018-10-13 08:47:20 +00:00
fold_start "PUSHING_CHANGES_TO_${BOT_NAME}/${PUBLISH}"
2019-12-09 20:47:10 +00:00
cd "/tmp/${PUBLISH}"
2018-05-19 20:42:12 +00:00
/tmp/hub fork
if [ $? -ne 0 ]; then
echo "hub fork failed"
exit 2
fi
fork_url="https://${BOT_NAME}:${BOT_TK}"
fork_url+="@github.com/${BOT_NAME}/${PUBLISH}.git"
git remote set-url "${BOT_NAME}" "${fork_url}"
2018-10-13 08:47:20 +00:00
/tmp/hub push -f "${BOT_NAME}" "${TRAVIS_BRANCH}" > /dev/null 2>&1
2018-05-19 20:42:12 +00:00
# prevent token leak ^^^^^^^^^^^^^^
# But it's actually not necessary since TravisCI masks secrets in logs
if [ $? -ne 0 ]; then
echo "hub push to \"${BOT_NAME}\" failed"
exit 2
fi
2018-10-13 08:47:20 +00:00
fold_end "PUSHING_CHANGES_TO_${BOT_NAME}/${PUBLISH}"
2019-01-22 18:07:06 +00:00
fold_start "OPENING_PR_TO_SPACEMACS_REPO"
2021-01-08 08:08:08 +00:00
echo "[bot] Auto-update" > msg
2018-10-13 23:01:01 +00:00
echo >> msg
2018-10-13 08:47:20 +00:00
echo "Merge with care - I'm just a stupid bot. Beep boop." >> msg
2018-10-13 21:47:08 +00:00
/tmp/hub pull-request -b "${TRAVIS_BRANCH}" -F msg
2018-05-19 20:42:12 +00:00
if [ $? -ne 0 ]; then
echo "Seems like PR already exists (not a problem)"
fi
2019-01-22 18:07:06 +00:00
fold_end "OPENING_PR_TO_SPACEMACS_REPO"