3
3
mirror of https://github.com/octoleo/octosync.git synced 2024-12-22 08:28:53 +00:00

Add function to not clone repo if folder exist during test. Improved the error/exit number.

This commit is contained in:
Llewellyn van der Merwe 2021-07-14 10:08:38 +02:00
parent de0d474614
commit a8e6ce0d73
Signed by: Llewellyn
GPG Key ID: EFC0C720A240551C
4 changed files with 39 additions and 27 deletions

View File

@ -59,7 +59,7 @@ target.repo.folders=folder/path_a;folder/path_b
# To merge or just make a PR (0 = PR; 1 = Merge) # To merge or just make a PR (0 = PR; 1 = Merge)
target.repo.merge=1 target.repo.merge=1
# Target fork is rebased (if out of sync with upstream target) # Target fork is rebased (HARD RESET TO UPSTREAM TARGET)
# Then updated and used to make a PR or Merge # Then updated and used to make a PR or Merge
target.repo.fork=org2/repo2 target.repo.fork=org2/repo2

View File

@ -36,6 +36,10 @@ target.repo.branch=main
# source[dot]repo[dot]folders=folder/path_a;folder/path_b # source[dot]repo[dot]folders=folder/path_a;folder/path_b
target.repo.folders=joomla_v4/source/language/en-GB;joomla_v4/source/administrator/language/en-GB;joomla_v4/source/api/language/en-GB target.repo.folders=joomla_v4/source/language/en-GB;joomla_v4/source/administrator/language/en-GB;joomla_v4/source/api/language/en-GB
# Target fork is rebased (HARD RESET TO UPSTREAM TARGET)
# Then updated and used to make a PR or Merge
target.repo.fork=Llewellynvdm/core-translations
# To merge or just make a PR (0 = PR; 1 = Merge) # To merge or just make a PR (0 = PR; 1 = Merge)
target.repo.merge=1 target.repo.merge=1

View File

@ -39,7 +39,7 @@ target.repo.folders=installation/language/en-GB;build/media_source/system/js/fie
# To merge or just make a PR (0 = PR; 1 = Merge) # To merge or just make a PR (0 = PR; 1 = Merge)
target.repo.merge=0 target.repo.merge=0
# Target fork is rebased (if out of sync with upstream target) # Target fork is rebased (HARD RESET TO UPSTREAM TARGET)
# Then updated and used to make a PR or Merge # Then updated and used to make a PR or Merge
target.repo.fork=llewellynvdm/joomla-cms target.repo.fork=llewellynvdm/joomla-cms

View File

@ -57,14 +57,14 @@ function checkConfValues () {
# make sure TARGET_REPO is set # make sure TARGET_REPO is set
[[ ! "${TARGET_REPO}" == *"/"* ]] && echo "TARGET_REPO:${TARGET_REPO} is not a repo path!" && ERROR=1 [[ ! "${TARGET_REPO}" == *"/"* ]] && echo "TARGET_REPO:${TARGET_REPO} is not a repo path!" && ERROR=1
[[ ! `wget -S --spider "https://github.com/${TARGET_REPO}" 2>&1 | grep 'HTTP/1.1 200 OK'` ]] && \ [[ ! `wget -S --spider "https://github.com/${TARGET_REPO}" 2>&1 | grep 'HTTP/1.1 200 OK'` ]] && \
echo "TARGET_REPO:https://github.com/${TARGET_REPO} is not set correctly, or the guthub user does not have access!" \ echo "TARGET_REPO:https://github.com/${TARGET_REPO} is not set correctly, or the guthub user does not have access!" && \
&& ERROR=1 ERROR=1
# make sure TARGET_REPO_BRANCH is set # make sure TARGET_REPO_BRANCH is set
[ ${#TARGET_REPO_BRANCH} -le 1 ] && echo "TARGET_REPO_BRANCH:${TARGET_REPO_BRANCH} is not set correctly!" && ERROR=1 [ ${#TARGET_REPO_BRANCH} -le 1 ] && echo "TARGET_REPO_BRANCH:${TARGET_REPO_BRANCH} is not set correctly!" && ERROR=1
# make sure TARGET_REPO_FOLDERS is set # make sure TARGET_REPO_FOLDERS is set
[ ${#TARGET_REPO_FOLDERS} -le 1 ] && echo "TARGET_REPO_FOLDERS:${TARGET_REPO_FOLDERS} is not set correctly!" && ERROR=1 [ ${#TARGET_REPO_FOLDERS} -le 1 ] && echo "TARGET_REPO_FOLDERS:${TARGET_REPO_FOLDERS} is not set correctly!" && ERROR=1
# check that the correct action is set # check that the correct action is set
! (("$TARGET_REPO_ACTION" == 1)) && ! (("$TARGET_REPO_ACTION" == 0)) && echo "TARGET_REPO_ACTION:${TARGET_REPO_ACTION} is not set correctly!" && ERROR=1 ! (("$TARGET_REPO_ACTION" == 1)) && ! (("$TARGET_REPO_ACTION" == 0)) && echo "TARGET_REPO_ACTION:${TARGET_REPO_ACTION} is not set correctly!" && ERROR=1
@ -72,19 +72,19 @@ function checkConfValues () {
# make sure TARGET_REPO_FORK is set correctly if set # make sure TARGET_REPO_FORK is set correctly if set
if [ ${#TARGET_REPO_FORK} -ge 1 ]; then if [ ${#TARGET_REPO_FORK} -ge 1 ]; then
[[ ! "${TARGET_REPO_FORK}" == *"/"* ]] && echo "TARGET_REPO_FORK:${TARGET_REPO_FORK} is not a repo path!" && ERROR=1 [[ ! "${TARGET_REPO_FORK}" == *"/"* ]] && echo "TARGET_REPO_FORK:${TARGET_REPO_FORK} is not a repo path!" && ERROR=1
! wget --spider "https://github.com/${TARGET_REPO_FORK}" 2>/dev/null \ [[ ! `wget -S --spider "https://github.com/${TARGET_REPO_FORK}" 2>&1 | grep 'HTTP/1.1 200 OK'` ]] && \
&& echo "TARGET_REPO_FORK:https://github.com/${TARGET_REPO_FORK} is not set correctly, or the guthub user does not have access!" \ echo "TARGET_REPO_FORK:https://github.com/${TARGET_REPO_FORK} is not set correctly, or the guthub user does not have access!" && \
&& ERROR=1 ERROR=1
fi fi
# if error found exit # if error found exit
(("$ERROR" == 1)) && exit 1 (("$ERROR" == 1)) && exit 19
} }
# clone the repo # clone the repo
function cloneRepos () { function cloneRepos () {
# clone the source repo (we don't need access on this one) # clone the source repo (we don't need access on this one)
[[ ! "${SOURCE_REPO}" == *"/"* ]] && cloneRepo "https://github.com/${SOURCE_REPO}.git" "${SOURCE_REPO_BRANCH}" "source_repo" [[ "${SOURCE_REPO}" == *"/"* ]] && cloneRepo "https://github.com/${SOURCE_REPO}.git" "${SOURCE_REPO_BRANCH}" "source_repo"
# clone the forked target repo if set # clone the forked target repo if set
if [[ "${TARGET_REPO_FORK}" == *"/"* ]]; then if [[ "${TARGET_REPO_FORK}" == *"/"* ]]; then
# we need access on this one, so we use git@github.com: # we need access on this one, so we use git@github.com:
@ -97,7 +97,7 @@ function cloneRepos () {
cloneRepo "${TARGET_REPO}" "git@github.com:${TARGET_REPO_BRANCH}.git" "target_repo" cloneRepo "${TARGET_REPO}" "git@github.com:${TARGET_REPO_BRANCH}.git" "target_repo"
else else
echo "You must set TARGET_REPO:${TARGET_REPO} to target.repo.merge=1 if no target.repo.fork is given!" echo "You must set TARGET_REPO:${TARGET_REPO} to target.repo.merge=1 if no target.repo.fork is given!"
exit 1 exit 20
fi fi
} }
@ -107,13 +107,21 @@ function cloneRepo () {
local git_repo="$1" local git_repo="$1"
local git_branch="$2" local git_branch="$2"
local git_folder="$3" local git_folder="$3"
# clone the repo (but only a single branch) # with test we don't clone again
git clone -b "$git_branch" --single-branch "$git_repo" "$git_folder" --quiet # if folder already exist
if [ $? -eq 0 ];then if (("$TEST" == 1)) && [ -d "${git_folder}" ]; then
echo "${git_repo} was cloned successfully." echo "folder:${git_folder} already exist, repo:${git_repo} was not cloned again. (test mode)"
else else
echo "${git_repo} failed to cloned successfully, check that the GitHub user has access to this repo!" # make sure the folder does not exist
exit 1 [ -d "${git_folder}" ] && rm -fr "${git_folder}"
# clone the repo (but only a single branch)
git clone -b "$git_branch" --single-branch "$git_repo" "$git_folder" --quiet
if [ $? -eq 0 ];then
echo "${git_repo} was cloned successfully."
else
echo "${git_repo} failed to cloned successfully, check that the GitHub user has access to this repo!"
exit 21
fi
fi fi
} }
@ -135,7 +143,7 @@ function rebaseWithUpstream () {
echo "upstream:${git_repo_upstream} was added successfully." echo "upstream:${git_repo_upstream} was added successfully."
else else
echo "Failed to add upstream:${git_repo_upstream} successfully, check that the GitHub user has access to this repo!" echo "Failed to add upstream:${git_repo_upstream} successfully, check that the GitHub user has access to this repo!"
exit 1 exit 10
fi fi
# now fetch this upstream repo # now fetch this upstream repo
git fetch "$git_upstream/${git_branch}" --quiet git fetch "$git_upstream/${git_branch}" --quiet
@ -143,7 +151,7 @@ function rebaseWithUpstream () {
echo "upstream/${git_branch} was fetched successfully." echo "upstream/${git_branch} was fetched successfully."
else else
echo "Failed to fetch upstream/${git_branch} successfully, check that the GitHub user has access to this repo!" echo "Failed to fetch upstream/${git_branch} successfully, check that the GitHub user has access to this repo!"
exit 1 exit 11
fi fi
# make sure we are on the targeted branch # make sure we are on the targeted branch
git checkout "$git_branch" git checkout "$git_branch"
@ -153,7 +161,7 @@ function rebaseWithUpstream () {
echo "upstream:${git_repo_upstream} was rebased into the forked repo successfully." echo "upstream:${git_repo_upstream} was rebased into the forked repo successfully."
else else
echo "Failed to rebase upstream:${git_repo_upstream} successfully, check that the GitHub user has access to this repo!" echo "Failed to rebase upstream:${git_repo_upstream} successfully, check that the GitHub user has access to this repo!"
exit 1 exit 12
fi fi
# make sure this is not a test # make sure this is not a test
if (("$TEST" == 1)); then if (("$TEST" == 1)); then
@ -165,7 +173,7 @@ function rebaseWithUpstream () {
echo "The forked repo of upstream:${git_repo_upstream} successfully updated." echo "The forked repo of upstream:${git_repo_upstream} successfully updated."
else else
echo "Failed to update the forked repo, check that the GitHub user has access to this repo!" echo "Failed to update the forked repo, check that the GitHub user has access to this repo!"
exit 1 exit 13
fi fi
fi fi
# return to original folder # return to original folder
@ -195,7 +203,7 @@ function moveFoldersFiles () {
moveFolderFiles "${source_folders[key]}" "${target_folders[key]}" "${source_files[key]}" moveFolderFiles "${source_folders[key]}" "${target_folders[key]}" "${source_files[key]}"
else else
echo "Source folder:${source_folders[key]} file mismatched!" echo "Source folder:${source_folders[key]} file mismatched!"
exit 1 exit 14
fi fi
# just move all the content of the folder # just move all the content of the folder
else else
@ -203,7 +211,7 @@ function moveFoldersFiles () {
fi fi
else else
echo "Source folder:${source_folders[key]} mismatched!" echo "Source folder:${source_folders[key]} mismatched!"
exit 1 exit 15
fi fi
done done
# move just one folder (so it has no semicolons) # move just one folder (so it has no semicolons)
@ -216,7 +224,7 @@ function moveFoldersFiles () {
fi fi
else else
echo "Source folder:${SOURCE_REPO_FOLDERS} -> Target folder:${TARGET_REPO_FOLDERS} mismatched!" echo "Source folder:${SOURCE_REPO_FOLDERS} -> Target folder:${TARGET_REPO_FOLDERS} mismatched!"
exit 1 exit 16
fi fi
} }
@ -459,7 +467,7 @@ while :; do
shift shift
else else
echo 'ERROR: "--conf" requires a non-empty option argument.' echo 'ERROR: "--conf" requires a non-empty option argument.'
exit 1 exit 17
fi fi
;; ;;
--conf=?* | --config=?*) --conf=?* | --config=?*)
@ -467,7 +475,7 @@ while :; do
;; ;;
--conf= | --config) # Handle the case of an empty --conf= --conf= | --config) # Handle the case of an empty --conf=
echo 'ERROR: "--conf" requires a non-empty option argument.' echo 'ERROR: "--conf" requires a non-empty option argument.'
exit 1 exit 17
;; ;;
*) # Default case: No more options, so break out of the loop. *) # Default case: No more options, so break out of the loop.
break ;; break ;;
@ -476,7 +484,7 @@ while :; do
done done
# We must have a config file # We must have a config file
[ ! -f "${CONFIG_FILE}" ] && echo >&2 "The config:${CONFIG_FILE} is not set or found. Aborting." && exit 1 [ ! -f "${CONFIG_FILE}" ] && echo >&2 "The config:${CONFIG_FILE} is not set or found. Aborting." && exit 18
# set the configuration values # set the configuration values
setConfValues setConfValues