[CI] Move documentation formatting to CircleCI

This commit is contained in:
JAremko 2021-07-05 17:58:55 +03:00 committed by Eugene Yaremenko
parent be74dd786f
commit aa4547086d
20 changed files with 391 additions and 215 deletions

View File

@ -11,14 +11,13 @@
##
## License: GPLv3
skip_when_branch_update
fail_when_undefined_pr_number
pr_base=$(curl -s "${pr_data_URL}" | jq '.base.ref')
if [[ "${pr_base}" == "\"${dev_b}\"" ]]; then
if [[ "${pr_base}" == "\"develop\"" ]]; then
echo "You are PRing to the develop branch. This is good."
exit 0
elif [[ "${pr_base}" == "\"${mst_b}\"" ]]; then
elif [[ "${pr_base}" == "\"master\"" ]]; then
printf '=%.0s' {1..80}
printf "\n し(*・∀・) Thanks for the contribution! (・∀・*)\n"
printf '=%.0s' {1..80}

View File

@ -11,7 +11,6 @@
##
## License: GPLv3
skip_when_branch_update
fail_when_undefined_pr_number
upstream_head_sha=$(curl -s "${upstream_data_URL}" | jq '.commit.sha')

33
.circleci/apply_patch Executable file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env bash
## apply_patch Apply patch to the target(official spacemacs) repository
##
## 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
if [ ! -f "/tmp/${PUBLISH}.patch" ]; then
echo "No /tmp/${PUBLISH}.patch file. Aborting."
exit 0
else
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 "Patching"
git am < /tmp/spacemacs.patch
if [ $? -ne 0 ]; then
echo "Failed to apply /tmp/${PUBLISH}.patch."
exit 2
fi
fi

View File

@ -11,8 +11,6 @@
##
## License: GPLv3
skip_when_non_official_repo
echo_headline "Setting up bot account"
mkdir -p ~/.ssh

26
.circleci/built_in/make_patch Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env bash
## make_patch Creates patch file with updates of built-in Spacemacs 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
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/${PUBLISH}.patch"
if [ $? -ne 0 ]; then
echo "Failed to create built-in patch file."
exit 2
fi
git reset --hard HEAD~1
cat "/tmp/${PUBLISH}.patch"
fi

20
.circleci/built_in/maybe_pr Executable file
View File

@ -0,0 +1,20 @@
#!/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
echo_headline "Opening PR to ${UPD_BOT_LOGIN}/${UPD_BOT_REPO} repo"
echo "[bot] Built-in auto-update" > msg
echo >> msg
echo "Merge with care - I'm just a stupid bot. Beep boop." >> msg
hub pull-request -h "${PUBLISH}" -b "${CIRCLE_BRANCH}" -F msg
if [ $? -ne 0 ]; then
echo "Seems like PR already exists (not a problem)"
fi

View File

@ -10,8 +10,6 @@
##
## License: GPLv3
skip_when_non_official_repo
echo_headline "Downloading and replacing files"
built_in_manifest=".ci/built_in_manifest"
lines=$(cat "${built_in_manifest}")
@ -25,18 +23,3 @@ while read line; do
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,70 +1,23 @@
---
# Circle CI YAML file
version: 2.0
#### Config generator for CircleCI.
version: 2.1
setup: true
orbs:
continuation: circleci/continuation@0.1.0
jobs:
"Validate PR":
docker:
- image: jare/spacemacs-circleci:latest
environment:
BASH_ENV: ".circleci/shared"
"Generate config":
executor: continuation/default
steps:
- checkout
- run:
name: Make sure that this PR targets develop branch
command: .circleci/PR_base
- run:
name: Make sure that this PR doesn't need rebase
command: .circleci/PR_rebased
"Validate Documentation":
docker:
- image: jare/spacemacs-circleci:latest
environment:
BASH_ENV: ".circleci/shared"
steps:
- checkout
- run:
name: Select changed files
command: .circleci/select_pr_changed
- run:
name: export changed documentation files for validation
command: .circleci/org/export
- run:
name: validating changed documentation files
command: .circleci/org/validate
"Update built-in files":
docker:
- image: jare/spacemacs-circleci:latest
environment:
- BASH_ENV: ".circleci/shared"
- PUBLISH: "spacemacs_built_in"
- UPD_BOT_LOGIN: "SpacemacsBot"
- UPD_BOT_REPO: "spacemacs"
steps:
- checkout
- run:
name: Initialize bot account
command: .circleci/bot_init
- 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
- run:
name: "Render config_tmpl.yml"
command: |
cd .circleci/
cp config_tmpl.yml circleci.yml
sed -i "s/{{ IS_BRANCH_UDATE }}/${IS_BRANCH_UPDATE}/g" circleci.yml
- continuation/continue:
parameters: '{}'
configuration_path: ".circleci/circleci.yml"
workflows:
version: 2
validate_pr_files:
setup-workflow:
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"
- "Generate config"

141
.circleci/config_tmpl.yml Normal file
View File

@ -0,0 +1,141 @@
#### Circle CI YAML file
version: 2.1
parameters:
prj_owner:
type: string
default: "syl20bnr"
prj_repo:
type: string
default: "spacemacs"
prj_url:
type: string
default: "https://github.com/syl20bnr/spacemacs"
is_branch_update:
type: string
default: "{{ IS_BRANCH_UDATE }}"
jobs:
"Validate PR":
docker:
- image: jare/spacemacs-circleci:latest
environment:
- PRJ_OWNER: << pipeline.parameters.prj_owner >>
- PRJ_REPO: << pipeline.parameters.prj_repo >>
- BASH_ENV: ".circleci/shared"
working_directory: ~/.emacs.d
steps:
- checkout
- run:
name: Make sure that this PR targets develop branch
command: .circleci/PR_base
- run:
name: Make sure that this PR doesn't need rebase
command: .circleci/PR_rebased
"Validate Documentation":
docker:
- image: jare/spacemacs-circleci:latest
environment:
- PRJ_OWNER: << pipeline.parameters.prj_owner >>
- PRJ_REPO: << pipeline.parameters.prj_repo >>
- BASH_ENV: ".circleci/shared"
working_directory: ~/.emacs.d
steps:
- checkout
- run:
name: Select changed files
command: .circleci/select_pr_changed
- run:
name: validate changed documentation files
command: .circleci/org/validate
"Update built-in files":
docker:
- image: jare/spacemacs-circleci:latest
environment:
- PRJ_OWNER: << pipeline.parameters.prj_owner >>
- PRJ_REPO: << pipeline.parameters.prj_repo >>
- BASH_ENV: ".circleci/shared"
- PUBLISH: "spacemacs_built_in"
- UPD_BOT_LOGIN: "SpacemacsBot"
- UPD_BOT_REPO: "spacemacs"
working_directory: ~/.emacs.d
steps:
- checkout
- run:
name: Initialize bot account
command: .circleci/bot_init
- run:
name: Download latest versions
command: .circleci/built_in/upd_built_in
- run:
name: Create patch file with the updates
command: .circleci/built_in/make_patch
- run:
name: Apply the patch file
command: .circleci/apply_patch
- run:
name: Push changes to Spacemacs Bot account
command: .circleci/push
- run:
name: Open PR if built in files must be updated
command: .circleci/built_in/maybe_pr
"Update documentation files":
docker:
- image: jare/spacemacs-circleci:latest
environment:
- PRJ_OWNER: << pipeline.parameters.prj_owner >>
- PRJ_REPO: << pipeline.parameters.prj_repo >>
- BASH_ENV: ".circleci/shared"
- PUBLISH: "spacemacs_fix_org"
- UPD_BOT_LOGIN: "SpacemacsBot"
- UPD_BOT_REPO: "spacemacs"
working_directory: ~/.emacs.d
steps:
- checkout
- run:
name: Initialize bot account
command: .circleci/bot_init
- run:
name: Export documentation files
command: .circleci/org/sdnize
- run:
name: Update documentation files
command: .circleci/org/update_docs
- run:
name: Create patch file with the updates
command: .circleci/org/make_patch
- run:
name: Apply the patch file
command: .circleci/apply_patch
- run:
name: Push changes to Spacemacs Bot account
command: .circleci/push
- run:
name: Open PR if documentation needs fixes
command: .circleci/org/maybe_pr
workflows:
version: 2.1
validate-pr-files:
when:
not:
equal: [ << pipeline.parameters.is_branch_update >>, "yes"]
jobs:
- "Validate PR"
- "Validate Documentation"
update-documentation:
when:
equal: [ << pipeline.parameters.is_branch_update >>, "yes"]
jobs:
- "Update documentation files"
update-built-in:
when:
equal: [ << pipeline.parameters.is_branch_update >>, "yes"]
triggers:
- schedule:
cron: "0 0,6,12,18 * * *"
filters:
branches:
only:
- develop
jobs:
- "Update built-in files"

View File

@ -1,28 +0,0 @@
#!/usr/bin/env bash
## Export script for .org validation.
##
## 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
skip_when_branch_update
fail_when_undefined_pr_number
select_changed_orgs
if [ ${#changed_f_as_args[@]} -ne 0 ]; then
emacs -batch -l /opt/spacetools/spacedoc/sdnize/sdnize.el -no-site-file \
-q ~/.emacs.d/ /tmp/exported/ \
$(printf "%s " "${changed_f_as_args[@]}")
if [ $? -ne 0 ]; then
echo "Documentation needs some fixing ;)"
exit 1
fi
else
echo "This commit doesn't change documentation files."
fi

26
.circleci/org/make_patch Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env bash
## make_patch Generate patch file with Spacemacs documentation 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
git add --all
git commit -m "documentation formatting: $(date -u)"
if [ $? -ne 0 ]; then
echo "Documentation is up to date."
exit 0
else
git format-patch -1 HEAD --stdout > "/tmp/${PUBLISH}.patch"
if [ $? -ne 0 ]; then
echo "Failed to create documentation patch file."
exit 2
fi
git reset --hard HEAD~1
cat "/tmp/${PUBLISH}.patch"
fi

20
.circleci/org/maybe_pr Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
## open_pr Opens PR to Spacemacs repository with documentation 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
echo_headline "Opening PR to ${UPD_BOT_LOGIN}/${UPD_BOT_REPO} repo"
echo "[bot] Documentation fixes" > msg
echo >> msg
echo "Merge with care - I'm just a stupid bot. Beep boop." >> msg
hub pull-request -h "${PUBLISH}" -b "${CIRCLE_BRANCH}" -F msg
if [ $? -ne 0 ]; then
echo "Seems like PR already exists (not a problem)"
fi

21
.circleci/org/sdnize Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
## Export script for documentation files.
##
## Copyright (c) 2012-2014 Sylvain Benner
## Copyright (c) 2014-2022 Sylvain Benner & Contributors
##
## Author: Eugene Yaremenko
## URL: https://github.com/syl20bnr/spacemacs
##
## This file is not part of GNU Emacs.
##
## License: GPLv3
mkdir -p "/tmp/sdn/"
echo_headline "Extract data out of documentation files into .sdn"
emacs -batch \
-l /opt/spacetools/spacedoc/sdnize/sdnize \
-no-site-file \
-q \
~/.emacs.d/ \
/tmp/sdn/

30
.circleci/org/update_docs Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env bash
## fix_docs Fixed(formats) Spacemacs' documentation 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
echo_headline "Generating new layers indext file data"
spacedoc layers \
-c".ci/spacedoc-cfg.edn" \
"/tmp/sdn/"
if [ $? -ne 0 ]; then
echo "Layers index generation failed."
exit 2
fi
echo_headline "Generating new .org files from .sdn representation"
spacedoc orgify \
-c".ci/spacedoc-cfg.edn" \
/tmp/sdn/ \
~/.emacs.d/
if [ $? -ne 0 ]; then
echo "Documentation generation failed."
exit 2
fi

View File

@ -1,8 +1,8 @@
#!/usr/bin/env bash
## Script for validating exported(org->sdn) documentation files.
## Script for validating documentation files.
##
## Copyright (c) 2012-2014 Sylvain Benner
## Copyright (c) 2014-2018 Sylvain Benner & Contributors
## Copyright (c) 2014-2021 Sylvain Benner & Contributors
##
## Author: Eugene Yaremenko
## URL: https://github.com/syl20bnr/spacemacs
@ -11,14 +11,33 @@
##
## License: GPLv3
skip_when_branch_update
fail_when_undefined_pr_number
select_changed_orgs
echo_headline "Exporting changed org fils"
if [ ${#changed_f_as_args[@]} -ne 0 ]; then
emacs -batch \
-l /opt/spacetools/spacedoc/sdnize/sdnize \
-no-site-file \
-q \
~/.emacs.d/ \
/tmp/exported/ \
$(printf "%s " "${changed_f_as_args[@]}")
if [ $? -ne 0 ]; then
echo "Documentation needs some fixing ;)"
exit 1
fi
else
echo "This commit doesn't change documentation files."
exit 0
fi
echo_headline "Validating changed org fils"
if [ ${#changed_f_as_args[@]} -ne 0 ]; then
spacedoc validate -c".ci/spacedoc-cfg.edn" /tmp/exported/
if [ $? -ne 0 ]; then
echo "Documentation validation failed."
echo "Documentation is invalid."
exit 1
fi
else

29
.circleci/push Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env bash
## push Push changes to Spacemacs bot account.
##
## 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
echo_headline "Creating fork under bot account"
export GITHUB_TOKEN=$UPD_BOT_GIT_TK
hub fork
if [ $? -ne 0 ]; then
echo "hub fork failed"
exit 2
fi
fork_url="https://${UPD_BOT_LOGIN}:${UPD_BOT_GIT_TK}"
fork_url+="@github.com/${UPD_BOT_LOGIN}/${UPD_BOT_REPO}.git"
git remote set-url "${UPD_BOT_LOGIN}" "${fork_url}"
echo_headline "Pushing changes"
hub push -f "${UPD_BOT_LOGIN}" "${PUBLISH}" > /dev/null 2>&1
# prevent token leak ^^^^^^^^^^^^^^
if [ $? -ne 0 ]; then
echo "hub push failed"
exit 2
fi

View File

@ -11,7 +11,6 @@
##
## License: GPLv3
skip_when_branch_update
fail_when_undefined_pr_number
files_json=$(curl "${pr_file_list_URL}" --silent)

View File

@ -12,10 +12,8 @@
## License: GPLv3
# Vars
dev_b="develop"
mst_b="master"
prj_owner="syl20bnr"
prj_repo="spacemacs"
prj_owner="${PRJ_OWNER}"
prj_repo="${PRJ_REPO}"
api_URL_root="https://api.github.com"
upstream_data_URL_root="${api_URL_root}/"
@ -63,22 +61,3 @@ fail_when_undefined_pr_number () {
exit 1
fi
}
skip_when_branch_update () {
if [[ "${IS_BRANCH_UPDATE}" == "yes" ]]; then
echo "Skipping for branch update."
exit 0
fi
}
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
}

View File

@ -1,70 +0,0 @@
#!/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 "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 "Forking target repository"
export GITHUB_TOKEN=$UPD_BOT_GIT_TK
hub fork
if [ $? -ne 0 ]; then
echo "hub fork failed"
exit 2
fi
fork_url="https://${UPD_BOT_LOGIN}:${UPD_BOT_GIT_TK}"
fork_url+="@github.com/${UPD_BOT_LOGIN}/${UPD_BOT_REPO}.git"
git remote set-url "${UPD_BOT_LOGIN}" "${fork_url}"
echo_headline "Pushing changes"
hub push -f "${UPD_BOT_LOGIN}" "${PUBLISH}" > /dev/null 2>&1
# prevent token leak ^^^^^^^^^^^^^^
if [ $? -ne 0 ]; then
echo "hub push failed"
exit 2
fi
echo_headline "Opening PR to ${UPD_BOT_LOGIN}/${UPD_BOT_REPO} repo"
echo "[bot] Built-in auto-update" > msg
echo >> msg
echo "Merge with care - I'm just a stupid bot. Beep boop." >> msg
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!"

View File

@ -23,7 +23,6 @@
<p align="center">
<a href="https://gitter.im/syl20bnr/spacemacs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"><img src="https://badges.gitter.im/Join Chat.svg" alt="Gitter"></a>
<a href="https://github.com/syl20bnr/spacemacs/actions/workflows/elisp_test.yml"><img src="https://github.com/syl20bnr/spacemacs/actions/workflows/elisp_test.yml/badge.svg?branch=develop"></a>
<a href="https://travis-ci.org/syl20bnr/spacemacs"><img src="https://travis-ci.org/syl20bnr/spacemacs.svg?branch=develop"></a>
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ESFVNPKP4Y742"><img src="https://img.shields.io/badge/Paypal-Donate-blue.svg" alt="Donate"></a>
<a href="https://shop.spreadshirt.com/spacemacs-shop"><img src="https://img.shields.io/badge/Shop-T--Shirts-blue.svg" alt="Donate"></a>
<a href="https://www.slant.co/topics/12/~what-are-the-best-programming-text-editors"><img src="https://img.shields.io/badge/Slant-Recommend-ff69b4.svg" alt="Recommend it"></a>