From a9cf9ea05c1582ab963db44a0f4c84baf50ffebf Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Mon, 13 Jul 2026 17:21:10 +0800 Subject: [PATCH] fix(ci): use pip compat check instead of hardcoded --break-system-packages - Old runner (Python 3.10 / pip 22.0) doesn't support --break-system-packages - Use runtime check to determine if the flag is needed - Fix pytest-rerunfailures install too --- .gitea/workflows/ci-cd.yml | 43 +++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/.gitea/workflows/ci-cd.yml b/.gitea/workflows/ci-cd.yml index 69868e967..da0b22150 100755 --- a/.gitea/workflows/ci-cd.yml +++ b/.gitea/workflows/ci-cd.yml @@ -92,9 +92,15 @@ jobs: shell: sh run: | set -eu - python3 -m pip install --break-system-packages -q -r requirements-base.txt - python3 -m pip install --break-system-packages -q -r requirements.txt - python3 -m pip install --break-system-packages -q -r requirements-dev.txt + + # 兼容Python 3.11+ PEP 668 (externally-managed-environment) + PIP_INSTALL="python3 -m pip install -q" + if python3 -m pip install --help 2>&1 | grep -q break-system-packages; then + PIP_INSTALL="$PIP_INSTALL --break-system-packages" + fi + eval $PIP_INSTALL -r requirements-base.txt + eval $PIP_INSTALL -r requirements.txt + eval $PIP_INSTALL -r requirements-dev.txt python3 -m black --version python3 -m isort --version-number python3 -m flake8 --version @@ -221,9 +227,15 @@ jobs: shell: sh run: | set -eu - python3 -m pip install --break-system-packages -q -r requirements-base.txt - python3 -m pip install --break-system-packages -q -r requirements.txt - python3 -m pip install --break-system-packages -q -r requirements-dev.txt + + # 兼容Python 3.11+ PEP 668 (externally-managed-environment) + PIP_INSTALL="python3 -m pip install -q" + if python3 -m pip install --help 2>&1 | grep -q break-system-packages; then + PIP_INSTALL="$PIP_INSTALL --break-system-packages" + fi + eval $PIP_INSTALL -r requirements-base.txt + eval $PIP_INSTALL -r requirements.txt + eval $PIP_INSTALL -r requirements-dev.txt pytest --version - name: Run unit tests with coverage @@ -320,9 +332,15 @@ jobs: shell: sh run: | set -eu - python3 -m pip install --break-system-packages -q -r requirements-base.txt - python3 -m pip install --break-system-packages -q -r requirements.txt - python3 -m pip install --break-system-packages -q -r requirements-dev.txt + + # 兼容Python 3.11+ PEP 668 (externally-managed-environment) + PIP_INSTALL="python3 -m pip install -q" + if python3 -m pip install --help 2>&1 | grep -q break-system-packages; then + PIP_INSTALL="$PIP_INSTALL --break-system-packages" + fi + eval $PIP_INSTALL -r requirements-base.txt + eval $PIP_INSTALL -r requirements.txt + eval $PIP_INSTALL -r requirements-dev.txt pytest --version - name: Start Redis @@ -394,7 +412,12 @@ jobs: shell: sh run: | set -eu - pip install --break-system-packages -q pytest-rerunfailures + # 兼容Python 3.11+ PEP 668 + PIP_INSTALL="python3 -m pip install -q" + if python3 -m pip install --help 2>&1 | grep -q break-system-packages; then + PIP_INSTALL="$PIP_INSTALL --break-system-packages" + fi + eval $PIP_INSTALL pytest-rerunfailures PYTHONPATH="$PWD/apps/api:$PWD" python3 -m coverage run --append \ --source=apps/api/app,packages \ --omit="*/migrations/*,*/tests/*,*/test_*.py,*/site-packages/*" \