diff --git a/.githooks/pre-commit b/.githooks/pre-commit index b645eee39..681e2e229 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -202,7 +202,7 @@ wait_for_all_background_jobs() { for failure in "${failures[@]}"; do echo -e "$failure" done - echo -e "${RED}To see the details look for the job's logs by it's prefixed name (e.g. \"shellcheck:\").${NO_COLOR}" + echo -e "${RED}To see the details look/filter for the job's logs by it's prefixed name (e.g. \"start_shellcheck:\", \"lint_code:\", \"shellcheck failed\").${NO_COLOR}" return 1 fi @@ -229,10 +229,17 @@ pre_commit() { # Function to run shellcheck on a single file run_shellcheck() { local file="$1" - echo "Running shellcheck on $file" - if ! shellcheck --color=always -x "$file" -e SC2154 -e SC1091 -e SC1090 -e SC2148 -o require-variable-braces -P "scripts"; then + + local diff_output + diff_output=$(shellcheck -f diff "$file" -e SC2154 -e SC1091 -e SC1090 -e SC2148 -o require-variable-braces -P "scripts" 2>&1) + + if [[ -n "$diff_output" && "$diff_output" != *"Issues were detected, but none were auto-fixable"* ]]; then + echo "$diff_output" | git apply + echo "Applied auto-fixes for $file" + elif [[ "$diff_output" == *"Issues were detected, but none were auto-fixable"* ]]; then echo -e "${RED}shellcheck failed on $file${NO_COLOR}" - exit 1 + shellcheck --color=always -x "$file" -e SC2154 -e SC1091 -e SC1090 -e SC2148 -o require-variable-braces -P "scripts" + return 1 fi } diff --git a/scripts/dev/recreate_python_venv.sh b/scripts/dev/recreate_python_venv.sh index 5ccff918e..c2b94a8d9 100755 --- a/scripts/dev/recreate_python_venv.sh +++ b/scripts/dev/recreate_python_venv.sh @@ -77,7 +77,8 @@ ensure_required_python() { # Install python3-venv package for Debian/Ubuntu systems if needed if command -v apt-get &> /dev/null; then echo "Installing python3-venv package for venv support..." >&2 - sudo apt-get update -qq && sudo apt-get install -y python3-venv || true + sudo apt-get update -qq || true + sudo apt-get install -y python3-venv || true fi return 0 fi diff --git a/scripts/dev/switch_context.sh b/scripts/dev/switch_context.sh index e5b25c4e4..ef2705451 100755 --- a/scripts/dev/switch_context.sh +++ b/scripts/dev/switch_context.sh @@ -105,17 +105,17 @@ if [[ -n "${PROJECT_DIR:-}" && -x "${PROJECT_DIR}/bin/kubectl" ]]; then KUBECTL_CMD="${PROJECT_DIR}/bin/kubectl" fi -if [[ "$KUBECTL_CMD" != "kubectl" ]] || which kubectl > /dev/null; then +if [[ "${KUBECTL_CMD}" != "kubectl" ]] || which kubectl > /dev/null; then if [ "${CLUSTER_NAME-}" ]; then # The convention: the cluster name must match the name of kubectl context # We expect this not to be true if kubernetes cluster is still to be created (minikube/kops) - if ! "$KUBECTL_CMD" config use-context "${CLUSTER_NAME}"; then + if ! "${KUBECTL_CMD}" config use-context "${CLUSTER_NAME}"; then echo "Warning: failed to switch kubectl context to: ${CLUSTER_NAME}" echo "Does a matching Kubernetes context exist?" fi # Setting the default namespace for current context - "$KUBECTL_CMD" config set-context "$("$KUBECTL_CMD" config current-context)" "--namespace=${NAMESPACE}" &>/dev/null || true + "${KUBECTL_CMD}" config set-context "$("${KUBECTL_CMD}" config current-context)" "--namespace=${NAMESPACE}" &>/dev/null || true # shellcheck disable=SC2153 echo "Current context: ${context} (kubectl context: ${CLUSTER_NAME}), namespace=${NAMESPACE}" diff --git a/scripts/evergreen/build_multi_cluster_kubeconfig_creator.sh b/scripts/evergreen/build_multi_cluster_kubeconfig_creator.sh index 26da60e28..fcf70f884 100755 --- a/scripts/evergreen/build_multi_cluster_kubeconfig_creator.sh +++ b/scripts/evergreen/build_multi_cluster_kubeconfig_creator.sh @@ -33,7 +33,7 @@ chmod +x docker/mongodb-kubernetes-tests/multi-cluster-kube-config-creator_s390x chmod +x docker/mongodb-kubernetes-tests/multi-cluster-kube-config-creator_ppc64le chmod +x docker/mongodb-kubernetes-tests/multi-cluster-kube-config-creator_arm64 -cp docker/mongodb-kubernetes-tests/multi-cluster-kube-config-creator_${ARCH} docker/mongodb-kubernetes-tests/multi-cluster-kube-config-creator || true +cp docker/mongodb-kubernetes-tests/multi-cluster-kube-config-creator_"${ARCH}" docker/mongodb-kubernetes-tests/multi-cluster-kube-config-creator || true mkdir -p bin || true cp docker/mongodb-kubernetes-tests/multi-cluster-kube-config-creator bin/kubectl-mongodb || true diff --git a/scripts/evergreen/e2e/build_tests_image_ibm.sh b/scripts/evergreen/e2e/build_tests_image_ibm.sh index 7f5f22090..6acb880e4 100755 --- a/scripts/evergreen/e2e/build_tests_image_ibm.sh +++ b/scripts/evergreen/e2e/build_tests_image_ibm.sh @@ -9,6 +9,6 @@ cp requirements.txt docker/mongodb-kubernetes-tests/requirements.txt cp -rf helm_chart docker/mongodb-kubernetes-tests/helm_chart echo "Building mongodb-kubernetes-tests image with tag: ${BASE_REPO_URL}/mongodb-kubernetes-tests:${version_id}-$(arch)" -cd docker/mongodb-kubernetes-tests +cd docker/mongodb-kubernetes-tests || exit sudo podman buildx build --progress plain . -f Dockerfile -t "${BASE_REPO_URL}/mongodb-kubernetes-tests:${version_id}-$(arch)" --build-arg PYTHON_VERSION="${PYTHON_VERSION}" sudo podman push --authfile="/root/.config/containers/auth.json" "${BASE_REPO_URL}/mongodb-kubernetes-tests:${version_id}-$(arch)" diff --git a/scripts/evergreen/setup_aws.sh b/scripts/evergreen/setup_aws.sh index 4900de4fd..cf26783af 100755 --- a/scripts/evergreen/setup_aws.sh +++ b/scripts/evergreen/setup_aws.sh @@ -58,8 +58,8 @@ install_aws_cli_pip() { ${pip_cmd} install --user awscli # Add ~/.local/bin to PATH if not already there (where pip --user installs) - if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then - export PATH="$HOME/.local/bin:$PATH" + if [[ ":${PATH}:" != *":${HOME}/.local/bin:"* ]]; then + export PATH="${HOME}/.local/bin:${PATH}" echo "Added ~/.local/bin to PATH" fi diff --git a/scripts/evergreen/setup_kind.sh b/scripts/evergreen/setup_kind.sh index 855e50530..d6aa824b9 100755 --- a/scripts/evergreen/setup_kind.sh +++ b/scripts/evergreen/setup_kind.sh @@ -12,7 +12,7 @@ arch_suffix=$(detect_architecture) latest_version="v0.27.0" # Only proceed with installation if architecture is supported (amd64 or arm64) -if [[ "$arch_suffix" == "amd64" || "$arch_suffix" == "arm64" ]]; then +if [[ "${arch_suffix}" == "amd64" || "${arch_suffix}" == "arm64" ]]; then mkdir -p "${PROJECT_DIR}/bin/" echo "Saving kind to ${PROJECT_DIR}/bin" curl --retry 3 --silent -L "https://github.com/kubernetes-sigs/kind/releases/download/${latest_version}/kind-${os}-${arch_suffix}" -o kind diff --git a/scripts/evergreen/setup_kubectl.sh b/scripts/evergreen/setup_kubectl.sh index 46e86279f..0673e7a4c 100755 --- a/scripts/evergreen/setup_kubectl.sh +++ b/scripts/evergreen/setup_kubectl.sh @@ -22,7 +22,7 @@ mv kubectl "${bindir}" echo "Downloading helm for ${ARCH}" helm_archive="${tmpdir}/helm.tgz" helm_version="v3.17.1" -curl -s https://get.helm.sh/helm-${helm_version}-linux-${ARCH}.tar.gz --output "${helm_archive}" +curl -s https://get.helm.sh/helm-${helm_version}-linux-"${ARCH}".tar.gz --output "${helm_archive}" tar xfz "${helm_archive}" -C "${tmpdir}" &> /dev/null mv "${tmpdir}/linux-${ARCH}/helm" "${bindir}" diff --git a/scripts/minikube/setup_minikube.sh b/scripts/minikube/setup_minikube.sh index c7a274abd..e2a004b6f 100755 --- a/scripts/minikube/setup_minikube.sh +++ b/scripts/minikube/setup_minikube.sh @@ -29,7 +29,7 @@ EOF } # retrieve arch variable off the shell command line -ARCH=${1-"$(detect_architecture)"} +ARCH="$(detect_architecture)" echo "Setting up minikube host for architecture: ${ARCH}" @@ -50,7 +50,7 @@ setup_local_registry_and_custom_image() { registry_running=true fi - if ! $registry_running; then + if ! ${registry_running}; then echo "Starting local container registry on port 5000..." # Clean up any existing registry first @@ -63,7 +63,7 @@ setup_local_registry_and_custom_image() { # Wait for registry to be ready echo "Waiting for registry to be ready..." - for i in {1..30}; do + for _ in {1..30}; do if curl -s http://localhost:5000/v2/_catalog >/dev/null 2>&1; then break fi