diff --git a/.travis.yml b/.travis.yml index ec1f57dd0..40ff3358a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,14 +16,24 @@ env: - BOT_NAME=emacspace - BOT_EMAIL=emacspace@gmail.com before_script: -- docker pull jare/spacedoc:latest +- docker pull jare/spacetools:latest script: ".travisci/test.sh" before_deploy: - - ".travisci/pub_prep.sh" + - > + if ! [ "$BEFORE_DEPLOY_RUN" ]; then + export BEFORE_DEPLOY_RUN=1; + .travisci/pub_prep.sh + fi deploy: - skip_cleanup: true - provider: script - script: ".travisci/pub.sh" - on: - all_branches: true - condition: $TRAVIS_REPO_SLUG = "syl20bnr/spacemacs" + - provider: script + skip_cleanup: true + script: ".travisci/pub_org_fmt.sh" + on: + all_branches: true + condition: $TRAVIS_REPO_SLUG = "syl20bnr/spacemacs" + - provider: script + skip_cleanup: true + script: ".travisci/pub_html.sh" + on: + all_branches: true + condition: $TRAVIS_REPO_SLUG = "syl20bnr/spacemacs" diff --git a/.travisci/pub.sh b/.travisci/pub_html.sh similarity index 69% rename from .travisci/pub.sh rename to .travisci/pub_html.sh index 534fe7ee5..e954fb48c 100755 --- a/.travisci/pub.sh +++ b/.travisci/pub_html.sh @@ -11,11 +11,12 @@ ## ## License: GPLv3 -echo_headline () { - printf '=%.0s' {1..70} - printf "\n$1\n" - printf '=%.0s' {1..70} - echo +fold_start() { + echo -e "travis_fold:start:$1\033[33;1m$2\033[0m" +} + +fold_end() { + echo -e "\ntravis_fold:end:$1\r" } cd ~/.emacs.d @@ -29,21 +30,16 @@ else exit 0 fi -echo_headline "CONFIGURING GIT USER:" -git config --global user.name "${BOT_NAME}" -git config --global user.email "${BOT_EMAIL}" -git config --global push.default simple -git config --global hub.protocol https -export GITHUB_TOKEN=$BOT_TK - -echo_headline "CLONING TARGET REPOSITORY:" +fold_start "CLONING_TARGET_REPOSITORY" target_URL="https://github.com/syl20bnr/${PUBLISH}.git" git clone "${target_URL}" -b gh-pages "/tmp/${PUBLISH}" if [ $? -ne 0 ]; then echo "Failed to clone \"${target_URL}\"" exit 2 fi -echo "Done." +fold_end "CLONING_TARGET_REPOSITORY" + +fold_start "SELECTING_CHANGED_FILES" rsync -avh ~/.emacs.d/export/ "/tmp/${PUBLISH}" git add --all git diff --cached --exit-code @@ -51,19 +47,10 @@ if [ $? -eq 0 ]; then echo "Nothing to commit - exiting." exit 0 fi +fold_end "SELECTING_CHANGED_FILES" -hub_version="2.2.9" -hub_url="https://github.com/github/hub/releases/download/" -hub_url+="v${hub_version}/hub-linux-amd64-${hub_version}.tgz" - +fold_start "PUSHING_CHANGES_TO_${BOT_NAME}/${PUBLISH}" cd "/tmp/${PUBLISH}" -echo_headline "PUSHING CHANGES TO ${BOT_NAME}/${PUBLISH}:" -curl -L $hub_url | tar \ - --strip-components=2 \ - -xz \ - --wildcards \ - -C /tmp/ \ - "*hub" /tmp/hub add --all /tmp/hub commit -m "doc update:$(date -u)" if [ $? -ne 0 ]; then @@ -89,12 +76,13 @@ if [ $? -ne 0 ]; then echo "hub push to \"${BOT_NAME}\" failed" exit 2 fi -echo_headline "OPENING PR TO syl20bnr/${PUBLISH}.git" +fold_end "PUSHING_CHANGES_TO_${BOT_NAME}/${PUBLISH}" + +fold_start "OPENING_PR_TO_syl20bnr/${PUBLISH}.git" echo "Documentation updates (autoexport)" > msg echo "beep beep boop... Beep?" >> msg /tmp/hub pull-request -F msg if [ $? -ne 0 ]; then echo "Seems like PR already exists (not a problem)" fi -echo "DONE!" -exit 0 +fold_end "OPENING_PR_TO_syl20bnr/${PUBLISH}.git" diff --git a/.travisci/pub_org_fmt.sh b/.travisci/pub_org_fmt.sh new file mode 100755 index 000000000..c7185dfe3 --- /dev/null +++ b/.travisci/pub_org_fmt.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +## Documentation publishing script for Travis CI integration +## +## 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 + +fold_start() { + echo -e "travis_fold:start:$1\033[33;1m$2\033[0m" +} + +fold_end() { + echo -e "\ntravis_fold:end:$1\r" +} + +cd ~/.emacs.d + +if [ "$TRAVIS_BRANCH" = "master" ] || [ "$TRAVIS_BRANCH" = "develop" ]; then + PUBLISH="spacemacs" +else + echo "branch is \"${TRAVIS_BRANCH}\". Won't publish." + exit 0 +fi + +fold_start "CLONING_TARGET_REPOSITORY" +target_URL="https://github.com/syl20bnr/${PUBLISH}.git" +git clone "${target_URL}" -b "${TRAVIS_BRANCH}" "/tmp/${PUBLISH}" +if [ $? -ne 0 ]; then + echo "Failed to clone \"${target_URL}\"" + exit 2 +fi +fold_end "CLONING_TARGET_REPOSITORY" + +fold_start "SELECTING_CHANGED_FILES" +rsync -avh ~/.emacs.d "/tmp/${PUBLISH}" +git add -u +git diff --cached --exit-code +if [ $? -eq 0 ]; then + echo "Nothing to commit - exiting." + exit 0 +fi +fold_end "SELECTING_CHANGED_FILES" + +fold_start "PUSHING_CHANGES_TO_${BOT_NAME}/${PUBLISH}" +cd "/tmp/${PUBLISH}" +/tmp/hub add --all +/tmp/hub commit -m "documentation fixes:$(date -u)" +if [ $? -ne 0 ]; then + echo "hub commit failed" + exit 2 +fi +/tmp/hub fork +if [ $? -ne 0 ]; then + echo "hub fork failed" + exit 2 +fi +mkdir -p ~/.ssh +printf "Host github.com\n" > ~/.ssh/config +printf " StrictHostKeyChecking no\n" >> ~/.ssh/config +printf " UserKnownHostsFile=/dev/null\n" >> ~/.ssh/config +fork_url="https://${BOT_NAME}:${BOT_TK}" +fork_url+="@github.com/${BOT_NAME}/${PUBLISH}.git" +git remote set-url "${BOT_NAME}" "${fork_url}" +/tmp/hub push -f "${BOT_NAME}" "${TRAVIS_BRANCH}" > /dev/null 2>&1 +# 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 +fold_end "PUSHING_CHANGES_TO_${BOT_NAME}/${PUBLISH}" + +fold_start "OPENING_PR_TO_syl20bnr/${PUBLISH}.git" +echo "[Spacebot]Documentation fixes" > msg +echo "Merge with care - I'm just a stupid bot. Beep boop." >> msg +/tmp/hub pull-request -F msg +if [ $? -ne 0 ]; then + echo "Seems like PR already exists (not a problem)" +fi +fold_end "OPENING_PR_TO_syl20bnr/${PUBLISH}.git" diff --git a/.travisci/pub_prep.sh b/.travisci/pub_prep.sh index db5ef66b8..a4735dc35 100755 --- a/.travisci/pub_prep.sh +++ b/.travisci/pub_prep.sh @@ -11,19 +11,30 @@ ## ## License: GPLv3 -echo_headline () { - printf '=%.0s' {1..70} - printf "\n$1\n" - printf '=%.0s' {1..70} - echo +fold_start() { + echo -e "travis_fold:start:$1\033[33;1m$2\033[0m" } +fold_end() { + echo -e "\ntravis_fold:end:$1\r" +} + +fold_start "FORMATTING_DOCUMENTATION" +docker run --rm -v "${TRAVIS_BUILD_DIR}":/tmp/docs/ \ + jare/spacetools docfmt /tmp/docs/ +if [ $? -ne 0 ]; then + echo "Formatting failed." + exit 2 +fi +fold_end "FORMATTING_DOCUMENTATION" + rm -rf ~/.emacs.d mv "${TRAVIS_BUILD_DIR}" ~/.emacs.d -ln -sf ~/.emacs.d "${TRAVIS_BUILD_DIR}" cd ~/.emacs.d +cp ./.travisci/.spacemacs ~/ +ln -sf ~/.emacs.d "${TRAVIS_BUILD_DIR}" -echo_headline "INSTALLING \"${EVM_EMACS}\":" +fold_start "INSTALLING_${EVM_EMACS}" curl -fsSkL https://gist.github.com/rejeep/ebcd57c3af83b049833b/raw \ > /tmp/x.sh && source /tmp/x.sh evm install $EVM_EMACS --use --skip @@ -31,25 +42,45 @@ if [ $? -ne 0 ]; then echo "Installation failed" exit 2 fi -echo "DONE!" +fold_end "INSTALLING_${EVM_EMACS}" -echo_headline "INSTALLING DEPENDENCIES:" -cp ~/.emacs.d/.travisci/.spacemacs ~/ -cd ~/.emacs.d -emacs -batch -l init.el +fold_start "INSTALLING_DEPENDENCIES" +emacs -batch -l init.el > /dev/null if [ $? -ne 0 ]; then echo "Dependencies installation failed." exit 2 fi -echo "DONE!" +fold_end "INSTALLING_DEPENDENCIES" -echo_headline "EXPORTING DOCUMENTATION:" +fold_start "EXPORTING_DOCUMENTATION" emacs -batch -l init.el -l core/core-documentation.el \ -f spacemacs/publish-doc if [ $? -ne 0 ]; then echo "spacemacs/publish-doc failed" exit 2 fi -echo "DONE!" +fold_end "EXPORTING_DOCUMENTATION" -exit 0 +fold_start "INSTALLING_HUB" +hub_version="2.2.9" +hub_url="https://github.com/github/hub/releases/download/" +hub_url+="v${hub_version}/hub-linux-amd64-${hub_version}.tgz" +curl -L $hub_url | tar \ + --strip-components=2 \ + -xz \ + --wildcards \ + -C /tmp/ \ + "*hub" +if [ $? -ne 0 ]; then + echo "Hub installation failed." + exit 2 +fi +fold_end "INSTALLING_HUB" + +fold_start "CONFIGURING_GIT_USER" +git config --global user.name "${BOT_NAME}" +git config --global user.email "${BOT_EMAIL}" +git config --global push.default simple +git config --global hub.protocol https +export GITHUB_TOKEN=$BOT_TK +fold_end "CONFIGURING_GIT_USER" diff --git a/.travisci/test.sh b/.travisci/test.sh index 9a3e40cec..7b3b92467 100755 --- a/.travisci/test.sh +++ b/.travisci/test.sh @@ -10,52 +10,3 @@ ## This file is not part of GNU Emacs. ## ## License: GPLv3 - -echo_headline () { - printf '=%.0s' {1..70} - printf "\n$1\n" - printf '=%.0s' {1..70} - echo -} - -echo_headline "CHECKING FOR MISPLACED SPACES AND TABS:" -git diff --check --color > /tmp/space_test_result -if [[ -s /tmp/space_test_result ]]; then - echo_headline "PLEASE FIX ISSUES BELOW:" - cat /tmp/space_test_result - exit 2 -fi -echo "Done." - -echo_headline "FORMATTING DOCUMENTATION:" -docker run --rm -v "${TRAVIS_BUILD_DIR}":/tmp/docs/ \ - jare/spacedoc format /tmp/docs/ -if [ $? -ne 0 ]; then - echo "Formatting failed." - exit 2 -fi - -git diff --color HEAD > /tmp/spacefmt_result -if [[ -s /tmp/spacefmt_result ]]; then - echo_headline "PLEASE APPLY CHANGES BELOW:" - cat /tmp/spacefmt_result - exit 2 -fi - -echo_headline "TESTING DOCUMENTATION WITH SDN EXPORT:" -docker run --rm -v "${TRAVIS_BUILD_DIR}":/tmp/docs/ \ - -v /tmp/sdn-files/:/tmp/export/ \ - jare/spacedoc export /tmp/docs/ -if [ $? -ne 0 ]; then - echo "Exporting failed." - exit 2 -fi - -echo_headline "VALIDATING DOCUMENTATION:" -docker run --rm -v /tmp/sdn-files/:/tmp/sdn-files/ \ - jare/spacedoc validate /tmp/sdn-files/ -if [ $? -ne 0 ]; then - echo "Validation failed." - exit 2 -fi -echo "Done."