From d78d8282f553965d1c6f799179dac13828ca3bc5 Mon Sep 17 00:00:00 2001 From: JAremko Date: Tue, 6 Jul 2021 02:45:49 +0300 Subject: [PATCH] [ci] Handle the case when everything is up to date --- .circleci/apply_patch | 5 +---- .circleci/config_tmpl.yml | 8 +++++--- .circleci/{built_in => }/maybe_pr | 6 ++++-- .circleci/org/maybe_pr | 23 ----------------------- .circleci/push | 2 ++ .circleci/shared | 11 +++++++++++ 6 files changed, 23 insertions(+), 32 deletions(-) rename .circleci/{built_in => }/maybe_pr (82%) delete mode 100755 .circleci/org/maybe_pr diff --git a/.circleci/apply_patch b/.circleci/apply_patch index 7ad74c389..748799b6a 100755 --- a/.circleci/apply_patch +++ b/.circleci/apply_patch @@ -10,10 +10,7 @@ ## ## License: GPLv3 -if [ ! -f "/tmp/${PUBLISH}.patch" ]; then - echo "No \"/tmp/${PUBLISH}.patch\" file. Aborting." - exit 0 -fi +exit_if_no_changes echo_headline "Cloning target repository" target_URL="https://github.com/${prj_owner}/${prj_repo}.git" diff --git a/.circleci/config_tmpl.yml b/.circleci/config_tmpl.yml index 1fa1ea3b7..6da9fd6c9 100644 --- a/.circleci/config_tmpl.yml +++ b/.circleci/config_tmpl.yml @@ -77,7 +77,7 @@ jobs: command: .circleci/push - run: name: Open PR if built in files must be updated - command: .circleci/built_in/maybe_pr + command: .circleci/maybe_pr "Update documentation files": docker: - image: jare/spacemacs-circleci:latest @@ -111,7 +111,7 @@ jobs: command: .circleci/push - run: name: Open PR if documentation needs fixes - command: .circleci/org/maybe_pr + command: .circleci/maybe_pr workflows: version: 2.1 @@ -124,7 +124,9 @@ workflows: - "Validate Documentation" update-documentation: when: - equal: [ << pipeline.parameters.is_branch_update >>, "yes"] + and: + - equal: [ << pipeline.parameters.is_branch_update >>, "yes"] + - equal: [ << pipeline.git.branch >>, "develop"] jobs: - "Update documentation files" update-built-in: diff --git a/.circleci/built_in/maybe_pr b/.circleci/maybe_pr similarity index 82% rename from .circleci/built_in/maybe_pr rename to .circleci/maybe_pr index 05c658ee9..b739b42cf 100755 --- a/.circleci/built_in/maybe_pr +++ b/.circleci/maybe_pr @@ -1,5 +1,5 @@ #!/usr/bin/env bash -## open_pr Opens PR to Spacemacs repository with built-in updates +## open_pr Opens PR to Spacemacs repository with updates (if any) ## ## Copyright (c) 2014-2021 Sylvain Benner & Contributors ## @@ -10,11 +10,13 @@ ## ## License: GPLv3 +exit_if_no_changes + cd "/tmp/${PUBLISH}" export GITHUB_TOKEN=$UPD_BOT_GIT_TK echo_headline "Opening PR to ${UPD_BOT_LOGIN}/${UPD_BOT_REPO} repo" -echo "[bot] Built-in auto-update" > msg +echo "[bot] ${PUBLISH} updates" > 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 diff --git a/.circleci/org/maybe_pr b/.circleci/org/maybe_pr deleted file mode 100755 index 673f90624..000000000 --- a/.circleci/org/maybe_pr +++ /dev/null @@ -1,23 +0,0 @@ -#!/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 - -cd "/tmp/${PUBLISH}" - -export GITHUB_TOKEN=$UPD_BOT_GIT_TK -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 diff --git a/.circleci/push b/.circleci/push index 719297239..89f3f82bd 100755 --- a/.circleci/push +++ b/.circleci/push @@ -10,6 +10,8 @@ ## ## License: GPLv3 +exit_if_no_changes + cd "/tmp/${PUBLISH}" echo_headline "Creating fork under bot account" diff --git a/.circleci/shared b/.circleci/shared index 523fd07e6..0013b6578 100755 --- a/.circleci/shared +++ b/.circleci/shared @@ -41,6 +41,17 @@ echo_headline () { echo } +exit_if_no_changes () { + if [ ! -f "/tmp/${PUBLISH}.patch" ]; then + echo "\"/tmp/${PUBLISH}.patch\" file doesn't exists. Exiting." + exit 0 + fi + if [[ -z $(grep '[^[:space:]]' "/tmp/${PUBLISH}.patch") ]]; then + echo "\"/tmp/${PUBLISH}.patch\" patch file is empty. Exiting." + exit 0 + fi +} + select_changed_orgs () { changed_f_as_args=() while read p