From f2f4604d3ac81a1ac88174e9a45c7a07c6ebc553 Mon Sep 17 00:00:00 2001 From: andy Augustin Date: Sun, 1 Jan 2023 13:14:20 +0100 Subject: [PATCH] fix(): #256 fix issue with existing branch :bug: (#276) * fix(): #256 fix issue with existing branch :bug: * fix(): #256 fix issue with existing branch :bug: --- .editorconfig | 2 +- src/entrypoint.sh | 28 ++++++++++++++-------------- src/sync_common.sh | 4 ++-- src/sync_template.sh | 13 ++++++++++++- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/.editorconfig b/.editorconfig index 0f61ceb..0e4fbfb 100644 --- a/.editorconfig +++ b/.editorconfig @@ -26,4 +26,4 @@ indent_size = 4 [*.sh] indent_size = 2 -indent_style = tab +indent_style = space diff --git a/src/entrypoint.sh b/src/entrypoint.sh index cf174c9..b0bb01d 100755 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -7,8 +7,8 @@ set -x source sync_common.sh [ -z "${GITHUB_TOKEN}" ] && { - err "Missing input 'github_token: \${{ secrets.GITHUB_TOKEN }}'."; - exit 1; + err "Missing input 'github_token: \${{ secrets.GITHUB_TOKEN }}'."; + exit 1; }; if [[ -z "${SOURCE_REPO_PATH}" ]]; then @@ -22,9 +22,9 @@ SOURCE_REPO_HOSTNAME="${HOSTNAME:-github.com}" SOURCE_REPO_PREFIX="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@${SOURCE_REPO_HOSTNAME}/" function ssh_setup() { - echo "::group::ssh setup" + echo "::group::ssh setup" - info "prepare ssh" + info "prepare ssh" SRC_SSH_FILE_DIR="/tmp/.ssh" SRC_SSH_PRIVATEKEY_FILE_NAME="id_rsa_actions_template_sync" export SRC_SSH_PRIVATEKEY_ABS_PATH="${SRC_SSH_FILE_DIR}/${SRC_SSH_PRIVATEKEY_FILE_NAME}" @@ -35,27 +35,27 @@ function ssh_setup() { chmod 600 "${SRC_SSH_PRIVATEKEY_ABS_PATH}" SOURCE_REPO_PREFIX="git@${SOURCE_REPO_HOSTNAME}:" - echo "::endgroup::" + echo "::endgroup::" } # Forward to /dev/null to swallow the output of the private key if [[ -n "${SSH_PRIVATE_KEY_SRC}" ]] &>/dev/null; then - ssh_setup + ssh_setup fi export SOURCE_REPO="${SOURCE_REPO_PREFIX}${SOURCE_REPO_PATH}" function git_init() { - echo "::group::git init" - info "set git global configuration" + echo "::group::git init" + info "set git global configuration" - git config --global user.email "github-action@actions-template-sync.noreply.${SOURCE_REPO_HOSTNAME}" - git config --global user.name "${GITHUB_ACTOR}" - git config --global pull.rebase false - git config --global --add safe.directory /github/workspace - git lfs install + git config --global user.email "github-action@actions-template-sync.noreply.${SOURCE_REPO_HOSTNAME}" + git config --global user.name "${GITHUB_ACTOR}" + git config --global pull.rebase false + git config --global --add safe.directory /github/workspace + git lfs install - echo "::endgroup::" + echo "::endgroup::" } git_init diff --git a/src/sync_common.sh b/src/sync_common.sh index 86313f4..246b56f 100755 --- a/src/sync_common.sh +++ b/src/sync_common.sh @@ -19,7 +19,7 @@ err() { # message to print. ####################################### debug() { - echo "::debug::$*"; + echo "::debug::$*"; } ####################################### @@ -37,5 +37,5 @@ warn() { # message to print. ####################################### info() { - echo "::info::$*"; + echo "::info::$*"; } diff --git a/src/sync_template.sh b/src/sync_template.sh index 8f4aec3..cf49299 100755 --- a/src/sync_template.sh +++ b/src/sync_template.sh @@ -40,10 +40,21 @@ debug "new Git HASH ${NEW_TEMPLATE_GIT_HASH}" echo "::group::Check new changes" +check_branch_remote_existing() { + git ls-remote --exit-code --heads origin "${NEW_BRANCH}" || BRANCH_DOES_NOT_EXIST=true + + if [[ "${BRANCH_DOES_NOT_EXIST}" != true ]]; then + warn "Git branch '${NEW_BRANCH}' exists in the remote repository" + exit 0 + fi +} + +check_branch_remote_existing + git cat-file -e "${TEMPLATE_REMOTE_GIT_HASH}" || COMMIT_NOT_IN_HIST=true if [ "$COMMIT_NOT_IN_HIST" != true ] ; then warn "repository is up to date!" - exit 0 + exit 0 fi echo "::endgroup::"