Improve CI workflow for backend tests by enhancing virtual environment setup
- Added a function to install the python3-venv package if the virtual environment creation fails due to missing ensurepip. - Improved error handling and messaging for the installation process, ensuring compatibility with both root and non-root users. - Streamlined the activation of the virtual environment for better clarity in the CI pipeline.
This commit is contained in:
@@ -27,6 +27,8 @@ jobs:
|
||||
|
||||
# No usamos actions/setup-python: en runners self-hosted (Debian) suele fallar
|
||||
# al descargar versiones desde el manifest. Se usa python3 del sistema + venv.
|
||||
# En Debian/Ubuntu hace falta el paquete python3-venv (ensurepip); si falla el venv,
|
||||
# se intenta instalar con apt (root en act/containers, sudo en servidor típico).
|
||||
- name: Instalar dependencias y ejecutar tests del backend
|
||||
env:
|
||||
TEST_DATABASE_URL: ${{ secrets.TEST_DATABASE_URL }}
|
||||
@@ -38,11 +40,27 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
python3 --version
|
||||
if ! python3 -m venv "$GITHUB_WORKSPACE/.pytest-venv" 2>/dev/null; then
|
||||
echo "python3 -m venv falló. En Debian/Ubuntu instala: sudo apt-get install -y python3-venv"
|
||||
exit 1
|
||||
VENV="$GITHUB_WORKSPACE/.pytest-venv"
|
||||
install_python3_venv() {
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
if ! command -v apt-get >/dev/null 2>&1; then
|
||||
echo "::error::No hay apt-get. Instala manualmente el paquete equivalente a python3-venv."
|
||||
return 1
|
||||
fi
|
||||
if [ "$(id -u)" -eq 0 ]; then
|
||||
apt-get update -qq
|
||||
apt-get install -y python3-venv
|
||||
else
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -y python3-venv
|
||||
fi
|
||||
}
|
||||
if ! python3 -m venv "$VENV" 2>/dev/null; then
|
||||
echo "venv falló (ensurepip no disponible). Instalando python3-venv..."
|
||||
install_python3_venv
|
||||
python3 -m venv "$VENV"
|
||||
fi
|
||||
. "$GITHUB_WORKSPACE/.pytest-venv/bin/activate"
|
||||
. "$VENV/bin/activate"
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r "$GITHUB_WORKSPACE/backend/requirements.txt"
|
||||
cd "$GITHUB_WORKSPACE/backend"
|
||||
|
||||
Reference in New Issue
Block a user