From ac1087ea4e3479980ffa0531f25fafb77868b53e Mon Sep 17 00:00:00 2001 From: JAremko Date: Sun, 1 Aug 2021 23:34:01 +0300 Subject: [PATCH] [ci] refactoring --- .circleci/config_tmpl.yml | 26 ++++++++++++++------------ .circleci/shared | 2 +- .circleci/{ => update}/apply_patch | 19 +++++++++++++------ .circleci/{ => update}/make_patch | 0 .circleci/{ => update}/maybe_pr | 2 +- .circleci/{ => update}/push | 2 +- doc/CI_PLUMBING.org | 18 ++++++++++-------- 7 files changed, 40 insertions(+), 29 deletions(-) rename .circleci/{ => update}/apply_patch (70%) rename .circleci/{ => update}/make_patch (100%) rename .circleci/{ => update}/maybe_pr (96%) rename .circleci/{ => update}/push (98%) diff --git a/.circleci/config_tmpl.yml b/.circleci/config_tmpl.yml index 13efd2652..e9c01b093 100644 --- a/.circleci/config_tmpl.yml +++ b/.circleci/config_tmpl.yml @@ -78,16 +78,16 @@ jobs: command: .circleci/built_in/upd_built_in - run: name: Create patch file with the updates - command: .circleci/make_patch + command: .circleci/update/make_patch - run: name: Apply the patch file - command: .circleci/apply_patch + command: .circleci/update/apply_patch - run: name: Push changes to Spacemacs Bot account - command: .circleci/push + command: .circleci/update/push - run: name: Open PR if built in files must be updated - command: .circleci/maybe_pr + command: .circleci/update/maybe_pr "Update documentation files": executor: spacetools environment: @@ -110,16 +110,16 @@ jobs: command: .circleci/org/update_docs - run: name: Create patch file with the updates - command: .circleci/make_patch + command: .circleci/update/make_patch - run: name: Apply the patch file - command: .circleci/apply_patch + command: .circleci/update/apply_patch - run: name: Push changes to Spacemacs Bot account - command: .circleci/push + command: .circleci/update/push - run: name: Open PR if documentation needs fixes - command: .circleci/maybe_pr + command: .circleci/update/maybe_pr "Update website documentation": executor: spacetools environment: @@ -158,16 +158,18 @@ jobs: command: rsync -avh ~/.emacs.d/export/ "/tmp/${PUBLISH}_old" - run: name: Create patch file with the updates - command: cd "/tmp/${PUBLISH}_old" && ~/.emacs.d/.circleci/make_patch + command: | + cd "/tmp/${PUBLISH}_old" && \ + ~/.emacs.d/.circleci/update/make_patch - run: name: Apply the patch file - command: .circleci/apply_patch + command: .circleci/update/apply_patch - run: name: Push changes to Spacemacs Bot account - command: .circleci/push + command: .circleci/update/push - run: name: Open PR if web documentation needs fixes - command: .circleci/maybe_pr + command: .circleci/update/maybe_pr workflows: version: 2.1 diff --git a/.circleci/shared b/.circleci/shared index 626ec0966..09d1aafc5 100755 --- a/.circleci/shared +++ b/.circleci/shared @@ -41,7 +41,7 @@ echo_headline () { echo } -exit_if_no_changes () { +exit_if_no_patchfile () { if [ ! -f "/tmp/${PUBLISH}.patch" ]; then echo "\"/tmp/${PUBLISH}.patch\" file doesn't exists. Exiting." exit 0 diff --git a/.circleci/apply_patch b/.circleci/update/apply_patch similarity index 70% rename from .circleci/apply_patch rename to .circleci/update/apply_patch index cb2198c18..72a8026ac 100755 --- a/.circleci/apply_patch +++ b/.circleci/update/apply_patch @@ -10,7 +10,7 @@ ## ## License: GPLv3 -exit_if_no_changes +exit_if_no_patchfile echo_headline "Cloning target repository" target_URL="https://github.com/${prj_owner}/${prj_repo}.git" @@ -29,10 +29,17 @@ if [ $? -ne 0 ]; then exit 2 fi -echo_headline "Creating commit" git add --all -git commit -m "[bot] \"${PUBLISH}\" $(date -u)" -if [ $? -ne 0 ]; then - echo "Faild to create commit." - exit 2 + +if [[ $(git diff --stat) != '' ]]; then + echo_headline "Creating commit" + git commit -m "[bot] \"${PUBLISH}\" $(date -u)" + if [ $? -ne 0 ]; then + echo "Failed to create commit." + exit 2 + fi +else + echo "Nothing to commit." + rm "/tmp/${PUBLISH}.patch" + exit 0 fi diff --git a/.circleci/make_patch b/.circleci/update/make_patch similarity index 100% rename from .circleci/make_patch rename to .circleci/update/make_patch diff --git a/.circleci/maybe_pr b/.circleci/update/maybe_pr similarity index 96% rename from .circleci/maybe_pr rename to .circleci/update/maybe_pr index 8359a3cdf..55486a13d 100755 --- a/.circleci/maybe_pr +++ b/.circleci/update/maybe_pr @@ -10,7 +10,7 @@ ## ## License: GPLv3 -exit_if_no_changes +exit_if_no_patchfile cd "/tmp/${PUBLISH}" diff --git a/.circleci/push b/.circleci/update/push similarity index 98% rename from .circleci/push rename to .circleci/update/push index f77664117..ea6b8944f 100755 --- a/.circleci/push +++ b/.circleci/update/push @@ -10,7 +10,7 @@ ## ## License: GPLv3 -exit_if_no_changes +exit_if_no_patchfile cd "/tmp/${PUBLISH}" diff --git a/doc/CI_PLUMBING.org b/doc/CI_PLUMBING.org index 9aa7b760f..63bb3f818 100644 --- a/doc/CI_PLUMBING.org +++ b/doc/CI_PLUMBING.org @@ -102,12 +102,13 @@ the JVM drawbacks are mitigated, for the particular use case anyway. it doesn't always work and requires personal token to run automatically. - =stale.yml= manages stale issues and PRs. - [[https://github.com/syl20bnr/spacemacs/tree/develop/.circleci][.circleci]] everything specific for CircleCI. Documentation related files - stored in the =org= sub folder, =web= is where HTML export stuff hides and - =built_in= is all about updating built-in files. The rest is a bunch of + stored in the =org= sub folder, =web= is where HTML export stuff hides, + =built_in= is all about updating built-in files and =update= contains helpers + related to making patches and pushing changes. The rest is a bunch of shared script files. The specific cases are =shared= file that loads before each script run for every job, =config.yml= - CircleCI bootstrap script that - generates the config that CircleCI will run by populating =config_tmpl.yml= - file - actual config. + generates the config that CircleCI runs for actual jobs. It does so by + rendering =config_tmpl.yml= template file. * Workflows (groups of CI jobs) ** Pull request jobs @@ -176,8 +177,8 @@ environment variable) uses GitHub token (stored in CircleCI project settings) to push updated version of Spacemacs develop branch into its fork (=UPD_BOT_REPO=) then it opens pull request to =PRJ_REPO= owned by =PRJ_OWNER= (the fork is based on it). =PUBLISH= variable also used as a name for the fork repo branch while -=PR_BRANCH= is the branch against which PR will be opened. See [[https://github.com/syl20bnr/spacemacs/blob/develop/.circleci/push][.circleci/push]] -and [[https://github.com/syl20bnr/spacemacs/blob/develop/.circleci/maybe_pr][.circleci/maybe_pr]] files for inner-works. Most of bash variables are +=PR_BRANCH= is the branch against which PR will be opened. See [[https://github.com/syl20bnr/spacemacs/blob/develop/.circleci/update/push][.circleci/update/push]] +and [[https://github.com/syl20bnr/spacemacs/blob/develop/.circleci/update/maybe_pr][.circleci/update/maybe_pr]] files for inner-works. Most of bash variables are configured in the [[https://github.com/syl20bnr/spacemacs/blob/develop/.circleci/shared][.circleci/shared]] file. The PRs are merged manually. **** Built-in updates @@ -235,8 +236,9 @@ develop branch is pushed. failures since they vastly outnumber failed ones. - See if we actually properly clean all they side effects between running EmacsLisp tests. -- CircleCI script files can have better names. Also =.circleci= directory gets - a bit crowded. +- CircleCI script files can have better names. +- Better error reporting in scripts. It is hard to debug CI so knowing what + exactly went wrong would help a lot. * Side notes ** We used to have TravisCI (3 CI providers at the same time)