Skip to content

Commit

Permalink
group updates to public branch
Browse files Browse the repository at this point in the history
  • Loading branch information
lj020326 committed Apr 1, 2024
1 parent ef1ab0b commit f97372d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 20 deletions.
85 changes: 69 additions & 16 deletions files/scripts/git/sync-public-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ PROJECT_DIR="$(cd "${SCRIPT_DIR}" && git rev-parse --show-toplevel)"

source "${PROJECT_DIR}/files/scripts/logger.sh"


MIRROR_DIR_LIST="
.github
.jenkins
Expand Down Expand Up @@ -81,10 +80,6 @@ EXCLUDES_ARRAY+=('*.log')

printf -v EXCLUDES '%s,' "${EXCLUDES_ARRAY[@]}"
EXCLUDES="${EXCLUDES%,}"
logDebug "EXCLUDES=${EXCLUDES}"

logDebug "PROJECT_DIR=${PROJECT_DIR}"
logDebug "TMP_DIR=${TMP_DIR}"

## https://serverfault.com/questions/219013/showing-total-progress-in-rsync-is-it-possible
## https://www.studytonight.com/linux-guide/how-to-exclude-files-and-directory-using-rsync
Expand All @@ -100,6 +95,22 @@ RSYNC_OPTS_GIT_UPDATE=(
--links
)

function isInstalled() {
command -v "${1}" >/dev/null 2>&1 || return 1
}

function checkRequiredCommands() {
missingCommands=""
for currentCommand in "$@"
do
isInstalled "${currentCommand}" || missingCommands="${missingCommands} ${currentCommand}"
done

if [[ ! -z "${missingCommands}" ]]; then
fail "checkRequiredCommands(): Please install the following commands required by this script:${missingCommands}"
fi
}

function search_repo_keywords () {
local LOG_PREFIX="==> search_repo_keywords():"

Expand Down Expand Up @@ -160,17 +171,7 @@ function search_repo_keywords () {
return "${EXCEPTION_COUNT}"
}

function main() {

# search_repo_keywords
eval search_repo_keywords
local RETURN_STATUS=$?
if [[ $RETURN_STATUS -eq 0 ]]; then
logInfo "${LOG_PREFIX} search_repo_keywords: SUCCESS"
else
logError "${LOG_PREFIX} search_repo_keywords: FAILED"
exit ${RETURN_STATUS}
fi
function sync_public_branch() {

git fetch --all
git checkout ${GIT_DEFAULT_BRANCH}
Expand Down Expand Up @@ -266,4 +267,56 @@ function main() {
ln -sf ./inventory/*.sh ./
}


function usage() {
echo "Usage: ${0} [options]"
echo ""
echo " Options:"
echo " -L [ERROR|WARN|INFO|TRACE|DEBUG] : run with specified log level (default INFO)"
echo " -v : show script version"
echo " -h : help"
echo " [TEST_CASES]"
echo ""
echo " Examples:"
echo " ${0} "
echo " ${0} -L DEBUG"
echo " ${0} -v"
[ -z "$1" ] || exit "$1"
}


function main() {

checkRequiredCommands rsync

while getopts "L:vh" opt; do
case "${opt}" in
L) setLogLevel "${OPTARG}" ;;
v) echo "${VERSION}" && exit ;;
h) usage 1 ;;
\?) usage 2 ;;
*) usage ;;
esac
done
shift $((OPTIND-1))

logDebug "EXCLUDES=${EXCLUDES}"

logDebug "PROJECT_DIR=${PROJECT_DIR}"
logDebug "TMP_DIR=${TMP_DIR}"

# search_repo_keywords
eval search_repo_keywords
local RETURN_STATUS=$?
if [[ $RETURN_STATUS -eq 0 ]]; then
logInfo "${LOG_PREFIX} search_repo_keywords: SUCCESS"
else
logError "${LOG_PREFIX} search_repo_keywords: FAILED"
exit ${RETURN_STATUS}
fi

sync_public_branch

}

main "$@"
9 changes: 5 additions & 4 deletions inventory/run-inventory-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,11 @@ function run_tests() {
return ${ERROR_COUNT}
}


function isInstalled() {
command -v "${1}" >/dev/null 2>&1 || return 1
}

function checkRequiredCommands() {
missingCommands=""
for currentCommand in "$@"
Expand All @@ -538,10 +543,6 @@ function checkRequiredCommands() {
fi
}

function isInstalled() {
command -v "${1}" >/dev/null 2>&1 || return 1
}


function install_jq() {
local LOG_PREFIX="==> install_jq():"
Expand Down

0 comments on commit f97372d

Please sign in to comment.