Skip to content

Commit

Permalink
fix(): #256 fix issue with existing branch 🐛 (#276)
Browse files Browse the repository at this point in the history
* fix(): #256 fix issue with existing branch 🐛

* fix(): #256 fix issue with existing branch 🐛
  • Loading branch information
AndreasAugustin authored Jan 1, 2023
1 parent 6c85d4d commit f2f4604
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ indent_size = 4

[*.sh]
indent_size = 2
indent_style = tab
indent_style = space
28 changes: 14 additions & 14 deletions src/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"
Expand All @@ -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 "[email protected].${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 "[email protected].${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
Expand Down
4 changes: 2 additions & 2 deletions src/sync_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ err() {
# message to print.
#######################################
debug() {
echo "::debug::$*";
echo "::debug::$*";
}

#######################################
Expand All @@ -37,5 +37,5 @@ warn() {
# message to print.
#######################################
info() {
echo "::info::$*";
echo "::info::$*";
}
13 changes: 12 additions & 1 deletion src/sync_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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::"
Expand Down

0 comments on commit f2f4604

Please sign in to comment.