kata-containers/tests/git-helper.sh
Dan Mihai 7b63f256e5 gha: fix git-helper issues reported by shellcheck
./tests/git-helper.sh:20:5: note: Prefer [[ ]] over [ ] for tests in Bash/Ksh. [SC2292]
./tests/git-helper.sh:22:26: note: Double quote to prevent globbing and word splitting. [SC2086]
./tests/git-helper.sh:23:7: note: Prefer [[ ]] over [ ] for tests in Bash/Ksh. [SC2292]

Signed-off-by: Dan Mihai <dmihai@microsoft.com>
2025-03-06 20:28:41 +00:00

47 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Copyright (c) 2023 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
set -o errexit
set -o nounset
set -o pipefail
function add_kata_bot_info() {
echo "Adding user name and email to the local git repo"
git config user.email "katacontainersbot@gmail.com"
git config user.name "Kata Containers Bot"
}
function rebase_atop_of_the_latest_target_branch() {
if [[ -n "${TARGET_BRANCH}" ]]; then
echo "Rebasing atop of the latest ${TARGET_BRANCH}"
if ! git rebase "origin/${TARGET_BRANCH}"; then
if [[ -n "${GITHUB_WORKSPACE}" ]] ; then
echo "Rebase failed, cleaning up the local repository and exiting"
cd "${GITHUB_WORKSPACE}"/..
sudo rm -rf "${GITHUB_WORKSPACE}"
else
echo "Rebase failed, exiting"
fi
exit 1
fi
fi
}
function main() {
action="${1:-}"
add_kata_bot_info
case "${action}" in
rebase-atop-of-the-latest-target-branch) rebase_atop_of_the_latest_target_branch;;
*) >&2 echo "Invalid argument"; exit 2 ;;
esac
}
main "$@"