Fix exit issue with failed commands, some cleanup
This commit is contained in:
@@ -7,7 +7,6 @@ ACTION_PARENT_DIR=$(dirname "$(dirname "$0")")
|
|||||||
# source script to handle message output
|
# source script to handle message output
|
||||||
. "${ACTION_PARENT_DIR}"/util/output.sh
|
. "${ACTION_PARENT_DIR}"/util/output.sh
|
||||||
|
|
||||||
# TODO: SPIKE on 'live' tests through the action runner
|
|
||||||
if [ -z "${GITHUB_ACTIONS}" ] || [ "${GITHUB_ACTIONS}" = false ]; then
|
if [ -z "${GITHUB_ACTIONS}" ] || [ "${GITHUB_ACTIONS}" = false ]; then
|
||||||
write_out "b" "\nRunning in LOCAL MODE..."
|
write_out "b" "\nRunning in LOCAL MODE..."
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,14 @@
|
|||||||
# checkout target branch for updates
|
# checkout target branch for updates
|
||||||
checkout() {
|
checkout() {
|
||||||
write_out -1 "Checking out target branch '${INPUT_SOURCE_SYNC_BRANCH}' for sync."
|
write_out -1 "Checking out target branch '${INPUT_SOURCE_SYNC_BRANCH}' for sync."
|
||||||
|
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
if ! git checkout ${INPUT_SOURCE_BRANCH_CHECKOUT_ARGS} "${INPUT_SOURCE_SYNC_BRANCH}"; then
|
git checkout ${INPUT_SOURCE_BRANCH_CHECKOUT_ARGS} "${INPUT_SOURCE_SYNC_BRANCH}"
|
||||||
|
COMMAND_STATUS=$?
|
||||||
|
|
||||||
|
if [ "${COMMAND_STATUS}" != 0 ]; then
|
||||||
# exit on branch checkout fail
|
# exit on branch checkout fail
|
||||||
write_out "$?" "Target branch could not be checked out."
|
write_out "${COMMAND_STATUS}" "Target branch could not be checked out."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
write_out -1 "Target branch checked out"
|
write_out -1 "Target branch checked out"
|
||||||
|
|||||||
+6
-3
@@ -15,7 +15,7 @@ check_for_updates() {
|
|||||||
HAS_NEW_COMMITS="error"
|
HAS_NEW_COMMITS="error"
|
||||||
elif [ "${LOCAL_COMMIT_HASH}" = "${UPSTREAM_COMMIT_HASH}" ]; then
|
elif [ "${LOCAL_COMMIT_HASH}" = "${UPSTREAM_COMMIT_HASH}" ]; then
|
||||||
HAS_NEW_COMMITS=false
|
HAS_NEW_COMMITS=false
|
||||||
else # assumes that remote will never be behind local when using this action...
|
else # TODO: make this more robust, currently assumes that the syncing branch is never commited to :/
|
||||||
HAS_NEW_COMMITS=true
|
HAS_NEW_COMMITS=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -47,9 +47,12 @@ sync_new_commits() {
|
|||||||
|
|
||||||
# pull_args examples: "--ff-only", "--tags", "--ff-only --tags"
|
# pull_args examples: "--ff-only", "--tags", "--ff-only --tags"
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
if ! git pull --no-edit ${INPUT_UPSTREAM_PULL_ARGS} upstream "${INPUT_UPSTREAM_SYNC_BRANCH}"; then
|
git pull --no-edit ${INPUT_UPSTREAM_PULL_ARGS} upstream "${INPUT_UPSTREAM_SYNC_BRANCH}"
|
||||||
|
COMMAND_STATUS=$?
|
||||||
|
|
||||||
|
if [ "${COMMAND_STATUS}" != 0 ]; then
|
||||||
# exit on commit pull fail
|
# exit on commit pull fail
|
||||||
write_out "$?" "New commits could not be pulled."
|
write_out "${COMMAND_STATUS}" "New commits could not be pulled."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
write_out "g" 'SUCCESS\n'
|
write_out "g" 'SUCCESS\n'
|
||||||
|
|||||||
+5
-2
@@ -5,9 +5,12 @@ push_new_commits() {
|
|||||||
write_out -1 'Pushing synced data to target branch.'
|
write_out -1 'Pushing synced data to target branch.'
|
||||||
|
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
if ! git push ${INPUT_SOURCE_PUSH_ARGS} origin "${INPUT_SOURCE_SYNC_BRANCH}"; then
|
git push ${INPUT_SOURCE_PUSH_ARGS} origin "${INPUT_SOURCE_SYNC_BRANCH}"
|
||||||
|
COMMAND_STATUS=$?
|
||||||
|
|
||||||
|
if [ "${COMMAND_STATUS}" != 0 ]; then
|
||||||
# exit on push to source repo fail
|
# exit on push to source repo fail
|
||||||
write_out "$?" "Could not push changes to source repo."
|
write_out "${COMMAND_STATUS}" "Could not push changes to source repo."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
write_out "g" 'SUCCESS\n'
|
write_out "g" 'SUCCESS\n'
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
set_upstream() {
|
set_upstream() {
|
||||||
write_out -1 "Setting upstream repo."
|
write_out -1 "Setting upstream repo to '${INPUT_UPSTREAM_SYNC_REPO}'."
|
||||||
git remote add upstream "${UPSTREAM_REPO_URL}"
|
git remote add upstream "${UPSTREAM_REPO_URL}"
|
||||||
|
|
||||||
# # exit if upstream can't be accessed
|
# # exit if upstream can't be accessed
|
||||||
|
|||||||
@@ -30,11 +30,14 @@ cleanup_test_dir() {
|
|||||||
if [ "${SKIP_CLEANUP}" = true ]; then
|
if [ "${SKIP_CLEANUP}" = true ]; then
|
||||||
true # no-op skip
|
true # no-op skip
|
||||||
else
|
else
|
||||||
# warn if cloned test directory can't be removed
|
rm -rf "${TEST_CLONE_DIR}"
|
||||||
if ! rm -rf "${TEST_CLONE_DIR}"; then
|
COMMAND_STATUS=$?
|
||||||
write_out "r" "(Clone cleanup failed - please find and remove directory '${TEST_CLONE_DIR}')\n"
|
|
||||||
fi
|
|
||||||
|
|
||||||
write_out -1 "(Clone directory cleanup successful.)\n"
|
# warn if cloned test directory can't be removed
|
||||||
|
if [ "${COMMAND_STATUS}" != 0 ] ; then
|
||||||
|
write_out "r" "(Clone cleanup failed - please find and remove directory '${TEST_CLONE_DIR}')\n"
|
||||||
|
else
|
||||||
|
write_out -1 "(Clone directory cleanup successful.)\n"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -40,8 +40,8 @@ write_out() {
|
|||||||
|
|
||||||
# safe exit, green output
|
# safe exit, green output
|
||||||
0)
|
0)
|
||||||
|
printf '\n%s\n' "$2" 1>&1
|
||||||
echo "${BOLD}${GREEN}SAFE EXIT${NORMAL}" 1>&1
|
echo "${BOLD}${GREEN}SAFE EXIT${NORMAL}" 1>&1
|
||||||
printf '%s\n' "$2" 1>&1
|
|
||||||
|
|
||||||
early_exit_cleanup
|
early_exit_cleanup
|
||||||
exit 0
|
exit 0
|
||||||
@@ -50,7 +50,7 @@ write_out() {
|
|||||||
# exit on error, red output
|
# exit on error, red output
|
||||||
*)
|
*)
|
||||||
echo "${BOLD}${RED}ERROR: ${NORMAL} exit $1" 1>&2
|
echo "${BOLD}${RED}ERROR: ${NORMAL} exit $1" 1>&2
|
||||||
printf '%s\n' "$2" 1>&2
|
printf '\n%s\n' "$2" 1>&2
|
||||||
echo "Try running in test mode to verify your action input. If that does not help, please open an issue." 1>&2
|
echo "Try running in test mode to verify your action input. If that does not help, please open an issue." 1>&2
|
||||||
|
|
||||||
early_exit_cleanup
|
early_exit_cleanup
|
||||||
|
|||||||
Reference in New Issue
Block a user