From c8e6cb568ab2871f400a826061dd8fd124ab74bf Mon Sep 17 00:00:00 2001 From: AlexeerCT Date: Tue, 24 Mar 2026 12:35:50 -0500 Subject: [PATCH] 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. --- .gitea/workflows/build.yml | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index bd0bc66e..4b2850d1 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -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