forked from phoenix-oss/llama-stack-mirror
# What does this PR do? Add several new pre-commit hooks to improve code quality and security: - no-commit-to-branch: prevent direct commits to protected branches like `main` - check-yaml: validate YAML files - detect-private-key: prevent accidental commit of private keys - requirements-txt-fixer: maintain consistent requirements.txt format and sorting - mixed-line-ending: enforce LF line endings to avoid mixed line endings - check-executables-have-shebangs: ensure executable scripts have shebangs - check-json: validate JSON files - check-shebang-scripts-are-executable: verify shebang scripts are executable - check-symlinks: validate symlinks and report broken ones - check-toml: validate TOML files mainly for pyproject.toml The respective fixes have been included. Signed-off-by: Sébastien Han <seb@redhat.com>
51 lines
952 B
Bash
Executable file
51 lines
952 B
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the terms described in the LICENSE file in
|
|
# the root directory of this source tree.
|
|
|
|
cleanup() {
|
|
envname="$1"
|
|
|
|
set +x
|
|
echo "Cleaning up..."
|
|
conda deactivate
|
|
conda env remove --name "$envname" -y
|
|
}
|
|
|
|
handle_int() {
|
|
if [ -n "$ENVNAME" ]; then
|
|
cleanup "$ENVNAME"
|
|
fi
|
|
exit 1
|
|
}
|
|
|
|
handle_exit() {
|
|
if [ $? -ne 0 ]; then
|
|
echo -e "\033[1;31mABORTING.\033[0m"
|
|
if [ -n "$ENVNAME" ]; then
|
|
cleanup "$ENVNAME"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
setup_cleanup_handlers() {
|
|
trap handle_int INT
|
|
trap handle_exit EXIT
|
|
|
|
if is_command_available conda; then
|
|
__conda_setup="$('conda' 'shell.bash' 'hook' 2>/dev/null)"
|
|
eval "$__conda_setup"
|
|
conda deactivate
|
|
else
|
|
echo "conda is not available"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# check if a command is present
|
|
is_command_available() {
|
|
command -v "$1" &>/dev/null
|
|
}
|