Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -230,24 +230,54 @@ pre_commit() {
run_shellcheck() {
local file="$1"
echo "Running shellcheck on $file"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no useful information printing that we are checking that file. Let's only echo on failure or when we fixed something

if ! shellcheck --color=always -x "$file" -e SC2154 -e SC1091 -e SC1090 -e SC2148 -o require-variable-braces -P "scripts"; then

# Try to auto-fix issues
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 [[ "$diff_output" == *"Issues were detected, but none were auto-fixable"* ]]; then
echo -e "${RED}shellcheck failed on $file${NO_COLOR}"
exit 1
echo "$file" >> "${SHELLCHECK_FAILED_FILE}"
return 1
elif echo "$diff_output" | git apply --allow-empty; then
echo "Applied auto-fixes for $file"
else
echo -e "${RED}shellcheck failed on $file${NO_COLOR}"
echo "$file" >> "${SHELLCHECK_FAILED_FILE}"
return 1
fi
}

# Export function so it's available in subshells (for xargs)
export -f run_shellcheck

start_shellcheck() {
# Create temporary file to track failed files
local failed_file
failed_file=$(mktemp)
export SHELLCHECK_FAILED_FILE="$failed_file"

# shellcheck disable=SC2016
{
find scripts -type f -name "*.sh"
find scripts/dev/contexts -type f | grep -v private-context
find scripts/funcs -type f
find public/architectures -type f -name "*.sh"
find docs/ -type f -name "*.sh"
} | xargs -I {} -P 20 bash -c 'run_shellcheck "$1"' _ {}
} | xargs -I {} -P 20 bash -c 'run_shellcheck "$1" || true' _ {}

# Show summary of failed files
if [[ -s "$failed_file" ]]; then
echo -e "\n${RED}Shellcheck failed on the following files:${NO_COLOR}"
while read -r file; do
echo -e " ${RED}✗${NO_COLOR} $file"
done < "$failed_file"
echo -e "\n${RED}Total: $(wc -l < "$failed_file") file(s) failed shellcheck${NO_COLOR}"
rm -f "$failed_file"
exit 1
fi

rm -f "$failed_file"
}

cmd=${1:-"pre-commit"}
Expand Down
6 changes: 3 additions & 3 deletions scripts/dev/switch_context.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/evergreen/e2e/build_tests_image_ibm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
4 changes: 2 additions & 2 deletions scripts/evergreen/setup_aws.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion scripts/evergreen/setup_kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/evergreen/setup_kubectl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion scripts/minikube/setup_minikube.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading