Refactor CI workflow for backend tests

- Consolidated the installation of backend dependencies and test execution into a single job in the CI workflow.
- Removed the use of actions/setup-python in favor of system Python and virtual environments to avoid issues on self-hosted runners.
- Added checks for the TEST_DATABASE_URL secret and improved error handling for virtual environment creation.
- Enhanced the overall reliability and clarity of the testing process in the CI pipeline.
This commit is contained in:
2026-03-24 12:35:50 -05:00
parent b750c35522
commit c8e6cb568a

View File

@@ -25,33 +25,28 @@ jobs:
- name: Checkout código
uses: actions/checkout@v4
- name: Configurar Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
cache-dependency-path: backend/requirements.txt
- name: Instalar dependencias del backend
run: |
python -m pip install --upgrade pip
pip install -r backend/requirements.txt
- name: Comprobar TEST_DATABASE_URL
# No usamos actions/setup-python: en runners self-hosted (Debian) suele fallar
# al descargar versiones desde el manifest. Se usa python3 del sistema + venv.
- name: Instalar dependencias y ejecutar tests del backend
env:
TEST_DATABASE_URL: ${{ secrets.TEST_DATABASE_URL }}
run: |
set -e
if [ -z "$TEST_DATABASE_URL" ]; then
echo "::error::Define el secret TEST_DATABASE_URL en el repo (Gitea → Ajustes → Secretos)."
echo "Ejemplo: postgresql://usuario:clave@host:5432/nombre_bd"
exit 1
fi
- name: Ejecutar tests del backend
env:
TEST_DATABASE_URL: ${{ secrets.TEST_DATABASE_URL }}
working-directory: backend
run: pytest -q tests
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
fi
. "$GITHUB_WORKSPACE/.pytest-venv/bin/activate"
python -m pip install --upgrade pip
pip install -r "$GITHUB_WORKSPACE/backend/requirements.txt"
cd "$GITHUB_WORKSPACE/backend"
pytest -q tests
build:
runs-on: self-hosted