[CI] move built-in auto update to CircleCI

This commit is contained in:
JAremko 2021-06-30 19:19:45 +03:00 committed by Eugene Yaremenko
parent 728c0ffb48
commit 40ea399d8e
12 changed files with 162 additions and 424 deletions

View File

@ -27,17 +27,42 @@ jobs:
- checkout
- run:
name: Select changed files
command: ./.circleci/select
command: ./.circleci/select_pr_changed
- run:
name: export changed documentation files for validation
command: ./.circleci/validoc/export
command: ./.circleci/org/export
- run:
name: validating changed documentation files
command: ./.circleci/validoc/validate
command: ./.circleci/org/validate
"Update built-in files":
docker:
- image: jare/spacemacs-circleci:latest
environment:
- BASH_ENV: ".circleci/shared"
- PUBLISH: "spacemacs_built_in"
working_directory: ~/.emacs.d
steps:
- checkout
- run:
name: Make patch file
command: ./.circleci/update/upd_built_in
- run:
name: Open PR if built in files must be updated
command: ./.circleci/update/maybe_pr
workflows:
version: 2
build:
validate_pr_files:
jobs:
- "Validate PR"
- "Validate Documentation"
update_built_in:
triggers:
- schedule:
cron: "0 0,6,12,18 * * *"
filters:
branches:
only:
- develop
jobs:
- "Update built-in files"

View File

@ -16,7 +16,6 @@ dev_b="develop"
mst_b="master"
prj_owner="syl20bnr"
prj_repo="spacemacs"
bot_login="emacspace"
api_URL_root="https://api.github.com"
upstream_data_URL_root="${api_URL_root}/"
@ -44,6 +43,18 @@ echo_headline () {
echo
}
init_hub () {
mkdir -p ~/.ssh
printf "Host github.com\n" > ~/.ssh/config
printf " StrictHostKeyChecking no\n" >> ~/.ssh/config
printf " UserKnownHostsFile=/dev/null\n" >> ~/.ssh/config
git config --global user.name $UPD_BOT_LONIG
git config --global user.email "not@an.actual.email.beep.boop"
git config --global push.default simple
git config --global hub.protocol https
export GITHUB_TOKEN=$UPD_BOT_GIT_TK
}
select_changed_orgs () {
changed_f_as_args=()
while read p
@ -72,6 +83,14 @@ skip_when_branch_update () {
fi
}
cleanup () {
rm -rf ~/.emacs.d/elpa ~/.emacs.d/.cache ~/.spacemacs
skip_when_non_official_repo () {
if [[ "${CIRCLE_PROJECT_REPONAME}" != "${prj_repo}" || \
"${CIRCLE_PROJECT_USERNAME}" != "${prj_owner}" ]]; then
echo "Skipping for non official repository."
exit 0
fi
}
cleanup () {
rm -rf ~/.emacs.d/elpa ~/.emacs.d/.cache /tmp/* ~/.spacemacs
}

70
.circleci/update/maybe_pr Executable file
View File

@ -0,0 +1,70 @@
#!/usr/bin/env bash
## open_pr Opens PR to Spacemacs repository with built-in updates
##
## Copyright (c) 2014-2021 Sylvain Benner & Contributors
##
## Author: Eugene Yaremenko
## URL: https://github.com/syl20bnr/spacemacs
##
## This file is not part of GNU Emacs.
##
## License: GPLv3
skip_when_non_official_repo
if [ ! -f /tmp/built_in.patch ]; then
echo "Nothing to update."
exit 0
fi
echo_headline "Setting up bot account"
hub_init
echo_headline "Cloning target repository"
target_URL="https://github.com/${prj_owner}/${prj_repo}.git"
git clone "${target_URL}" -b "${CIRCLE_BRANCH}" "/tmp/${PUBLISH}"
if [ $? -ne 0 ]; then
echo "Failed to clone \"${target_URL}\""
exit 2
fi
cd "/tmp/${PUBLISH}"
echo_headline "Applying built-in patch"
if [ ! -f /tmp/built_in.patch ]; then
echo "Built-in files don't need updating. Aborting."
else
git am < /tmp/built_in.patch
if [ $? -ne 0 ]; then
echo "Failed to apply built-in patch."
exit 2
fi
fi
echo_headline "Pushing changes to bot repository"
/tmp/hub fork
if [ $? -ne 0 ]; then
echo "hub fork failed"
exit 2
fi
fork_url="https://${UPD_BOT_LONIG}:${UPD_BOT_GIT_TK}"
fork_url+="@github.com/${UPD_BOT_LONIG}/${PUBLISH}.git"
git remote set-url "${UPD_BOT_LONIG}" "${fork_url}"
/tmp/hub push -f "${UPD_BOT_LONIG}" "${CIRCLE_BRANCH}" > /dev/null 2>&1
# prevent token leak ^^^^^^^^^^^^^^
if [ $? -ne 0 ]; then
echo "hub push to \"${BOT_NAME}\" failed"
exit 2
fi
echo_headline "Opening PR to Spacemacs repo"
echo "[bot] Auto-update" > msg
echo >> msg
echo "Merge with care - I'm just a stupid bot. Beep boop." >> msg
/tmp/hub pull-request -b "${CIRCLE_BRANCH}" -F msg
if [ $? -ne 0 ]; then
echo "Seems like PR already exists (not a problem)"
fi
echo_headline "Done!"

41
.circleci/update/upd_built_in Executable file
View File

@ -0,0 +1,41 @@
#!/usr/bin/env bash
## Upd_built_in updater script for Spacemacs' built-in files
##
## Copyright (c) 2014-2021 Sylvain Benner & Contributors
##
## Author: Eugene Yaremenko
## URL: https://github.com/syl20bnr/spacemacs
##
## This file is not part of GNU Emacs.
##
## License: GPLv3
skip_when_non_official_repo
built_in_manifest="~/.emacs.d/.ci/built_in_manifest"
lines=$(cat "${built_in_manifest}")
while read line; do
url=$(echo $line | cut -f1 -d " ")
target=$(echo $line | cut -f2 -d " ")
curl "${url}" --output "~/.emacs.d/${target}"
if [ $? -ne 0 ]; then
echo "Failed to update built in file: ${target} from url: ${url}"
echo "Please update manifest file: .emacs.d/.ci/built_in_manifest"
exit 2
fi
done <"${built_in_manifest}"
git add --all
git commit -m "Built-in files auto-update: $(date -u)"
if [ $? -ne 0 ]; then
echo "Built-in files don't need an update."
exit 0
else
git format-patch -1 HEAD --stdout > /tmp/built_in.patch
if [ $? -ne 0 ]; then
echo "Failed to create built-in patch file."
exit 2
fi
git reset --hard HEAD~1
cat /tmp/built_in.patch
fi

View File

@ -1,42 +0,0 @@
---
# TravisCI YAML file for publishing/updating/formatting Spacemacs documentation.
language: generic
sudo: required
services:
- docker
branches:
only:
- master
- develop
before_install:
- docker load -i /tmp/docker_images/images.tar || true
before_cache:
- docker save -o /tmp/docker_images/images.tar $(docker images -a -q)
cache:
directories:
- /tmp/docker_images
- /tmp/elpa
- !/tmp/elpa/gnupg
env:
global:
- secure: "M8NF1Uw7VGkLdNmWiUF4T+VOJXwN8KCKVQb45/BWVpGm88Rcfom/9bxRTUme8VYuzIavph32QF+P9KyhX8aj2p2FMItNnxiEySzap5UrLrNiwB6ZxbQglMJj0yMQKASynNBai9KKI7mYlsM5jRpFJ9OSgj7Ko00RIFpO3EpJ+kE="
- BOT_NAME=emacspace
- BOT_EMAIL=emacspace@gmail.com
- SPACEMACS_REPO_SLUG="syl20bnr/spacemacs"
before_script:
- docker pull jare/spacetools:latest
script:
- git checkout "${TRAVIS_BRANCH}" && .travisci/pub_prep.sh
deploy:
- provider: script
skip_cleanup: true
script: ".travisci/pub_auto_update.sh"
on:
branch: develop
condition: $TRAVIS_REPO_SLUG = $SPACEMACS_REPO_SLUG
- provider: script
skip_cleanup: true
script: ".travisci/pub_html.sh"
on:
all_branches: true
condition: $TRAVIS_REPO_SLUG = $SPACEMACS_REPO_SLUG

View File

@ -1,20 +0,0 @@
(defun dotspacemacs/layers ()
(setq-default
dotspacemacs-distribution 'spacemacs
dotspacemacs-configuration-layers '(
(org :variables
org-enable-github-support t
org-enable-bootstrap-support t
org-enable-reveal-js-support t
)
bibtex
(latex :variables
latex-enable-auto-fill t
latex-enable-folding t
)
html
)))
(defun dotspacemacs/init ())
(defun dotspacemacs/user-init ())
(defun dotspacemacs/config ())
(defun dotspacemacs/user-config ())

View File

@ -1,110 +0,0 @@
#!/usr/bin/env bash
## Auto-update 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" = "develop" ]; then
PUBLISH="spacemacs"
else
echo "branch is \"${TRAVIS_BRANCH}\". Won't publish."
exit 0
fi
export GITHUB_TOKEN=$BOT_TK
fold_start "CLONING_TARGET_REPOSITORY"
target_URL="https://github.com/${SPACEMACS_REPO_SLUG}.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 "APPLYING_DOCUMENTATION_PATCH"
cd "/tmp/${PUBLISH}"
if [ ! -f /tmp/docfmt.patch ]; then
echo "Documentation doesn't need fixes. Aborting."
else
git am < /tmp/docfmt.patch
if [ $? -ne 0 ]; then
echo "Failed to apply documentation fixes patch"
exit 2
fi
fi
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."
else
git am < /tmp/built_in.patch
if [ $? -ne 0 ]; then
echo "Failed to apply built-in patch."
exit 2
fi
fi
fold_end "APPLYING_BUILT_IN_PATCH"
fold_start "CHECKING_IF_SPACEMACS_HEAD_IS_THE_SAME"
cd ~/.emacs.d
git remote update
base_revision=$(cat /tmp/base_revision)
rem_rev=$(git rev-parse '@{u}')
echo "Base revision: $base_revision"
echo "Remote revision: $rem_rev"
if [ "$base_revision" != "$rem_rev" ]; then
echo "Looks like Spacemacs head has changed since CI started."
echo "Aborting."
exit 0
fi
fold_end "CHECKING_IF_SPACEMACS_HEAD_IS_THE_SAME"
fold_start "PUSHING_CHANGES_TO_${BOT_NAME}/${PUBLISH}"
cd "/tmp/${PUBLISH}"
/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}"
/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_SPACEMACS_REPO"
echo "[bot] Auto-update" > msg
echo >> msg
echo "Merge with care - I'm just a stupid bot. Beep boop." >> msg
/tmp/hub pull-request -b "${TRAVIS_BRANCH}" -F msg
if [ $? -ne 0 ]; then
echo "Seems like PR already exists (not a problem)"
fi
fold_end "OPENING_PR_TO_SPACEMACS_REPO"

View File

@ -1,96 +0,0 @@
#!/usr/bin/env bash
## HTML 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" ]; then
PUBLISH="spacemacs.org"
elif [ "$TRAVIS_BRANCH" = "develop" ]; then
PUBLISH="develop.spacemacs.org"
else
echo "branch is \"${TRAVIS_BRANCH}\". Won't publish."
exit 0
fi
export GITHUB_TOKEN=$BOT_TK
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
fold_end "CLONING_TARGET_REPOSITORY"
fold_start "SELECTING_CHANGED_FILES"
rsync -avh ~/.emacs.d/export/ "/tmp/${PUBLISH}"
cd "/tmp/${PUBLISH}"
/tmp/hub add --all
/tmp/hub commit -m "doc update:$(date -u)"
if [ $? -ne 0 ]; then
echo "Nothing to commit - exiting."
exit 0
fi
fold_end "SELECTING_CHANGED_FILES"
fold_start "CHECKING_IF_SPACEMACS_HEAD_IS_THE_SAME"
cd ~/.emacs.d
git remote update
base_revision=$(cat /tmp/base_revision)
rem_rev=$(git rev-parse '@{u}')
echo "Base revision: $base_revision"
echo "Remote revision: $rem_rev"
if [ "$base_revision" != "$rem_rev" ]; then
echo "Looks like Spacemacs head has changed while we generated files."
echo "Aborting."
exit 0
fi
fold_end "CHECKING_IF_SPACEMACS_HEAD_IS_THE_SAME"
fold_start "PUSHING_CHANGES_TO_${BOT_NAME}/${PUBLISH}"
cd "/tmp/${PUBLISH}"
/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}"
/tmp/hub push -f "${BOT_NAME}" gh-pages > /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}"
echo "Documentation updates (autoexport)" > msg
echo >> 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
fold_end "OPENING_PR_TO_syl20bnr/${PUBLISH}"

View File

@ -1,149 +0,0 @@
#!/usr/bin/env bash
## Documentation publishing preparation 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"
}
mkdir -p ~/.ssh
printf "Host github.com\n" > ~/.ssh/config
printf " StrictHostKeyChecking no\n" >> ~/.ssh/config
printf " UserKnownHostsFile=/dev/null\n" >> ~/.ssh/config
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
git remote update
base_revision=$(git rev-parse '@')
echo $base_revision > /tmp/base_revision
echo "Base revision $base_revision"
fold_start "UPDATING_BUILT_IN_FILES"
built_in_manifest="${TRAVIS_BUILD_DIR}/.ci/built_in_manifest"
lines=$(cat "${built_in_manifest}")
while read line; do
url=$(echo $line | cut -f1 -d " ")
target=$(echo $line | cut -f2 -d " ")
curl "${url}" --output "${TRAVIS_BUILD_DIR}/${target}"
if [ $? -ne 0 ]; then
echo "Failed to update built in file: ${target} from url: ${url}"
echo "Please update manifest file: .emacs.d/.ci/built_in_manifest"
exit 2
fi
done <"${built_in_manifest}"
fold_end "UPDATING_BUILT_IN_FILES"
fold_start "CREATING_BUILT_IN_PATCH_FILE"
git add --all
git commit -m "Built-in files auto-update: $(date -u)"
if [ $? -ne 0 ]; then
echo "Built-in files don't need an update."
else
git format-patch -1 HEAD --stdout > /tmp/built_in.patch
if [ $? -ne 0 ]; then
echo "Failed to create built-in patch file."
exit 2
fi
git reset --hard HEAD~1
cat /tmp/built_in.patch
fi
fold_end "CREATING_BUILT_IN_PATCH_FILE"
fold_start "FORMATTING_DOCUMENTATION"
docker run \
--rm \
-v "/tmp/elpa/:/root/.emacs.d/elpa/" \
-v "${TRAVIS_BUILD_DIR}/.ci/spacedoc-cfg.edn":/opt/spacetools/spacedoc-cfg.edn \
-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"
fold_start "CREATING_DOCUMENTATION_PATCH_FILE"
git add --all
git commit -m "documentation formatting: $(date -u)"
if [ $? -ne 0 ]; then
echo "Documentation doesn't need fixes."
else
git format-patch -1 HEAD --stdout > /tmp/docfmt.patch
if [ $? -ne 0 ]; then
echo "Failed to create documentation patch file."
exit 2
fi
git reset --hard HEAD~1
cat /tmp/docfmt.patch
fi
fold_end "CREATING_DOCUMENTATION_PATCH_FILE"
rm -rf ~/.emacs.d
mv "${TRAVIS_BUILD_DIR}" ~/.emacs.d
cd ~/.emacs.d
cp ./.travisci/.spacemacs ~/
ln -sf ~/.emacs.d "${TRAVIS_BUILD_DIR}"
fold_start "INSTALLING_DEPENDENCIES"
docker run \
--rm \
-v "/tmp/elpa/:/root/.emacs.d/elpa/" \
-v "${TRAVIS_BUILD_DIR}:/root/.emacs.d" \
-v "${TRAVIS_BUILD_DIR}/.travisci/.spacemacs:/root/.spacemacs" \
--entrypoint emacs \
jare/spacetools -batch -l /root/.emacs.d/init.el
if [ $? -ne 0 ]; then
echo "Dependencies installation failed."
exit 2
fi
fold_end "INSTALLING_DEPENDENCIES"
fold_start "EXPORTING_DOCUMENTATION"
docker run \
--rm \
-v "/tmp/elpa/:/root/.emacs.d/elpa/" \
-v "${TRAVIS_BUILD_DIR}:/root/.emacs.d" \
-v "${TRAVIS_BUILD_DIR}/.travisci/.spacemacs:/root/.spacemacs" \
--entrypoint emacs \
jare/spacetools -batch \
-l /root/.emacs.d/init.el \
-l /root/.emacs.d/core/core-documentation.el \
-f spacemacs/publish-doc
if [ $? -ne 0 ]; then
echo "spacemacs/publish-doc failed"
exit 2
fi
fold_end "EXPORTING_DOCUMENTATION"
fold_start "INSTALLING_HUB"
hub_version="2.5.1"
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"