From 4dbdb0f85380d4fa49638e0d5189b2313d035cfe Mon Sep 17 00:00:00 2001 From: Xiaoxia AI Date: Sat, 20 Jun 2026 21:05:10 +0800 Subject: [PATCH] chore(ci): use prebuilt python validation image --- .gitea/workflows/ci-cd.yml | 27 +++++++++++++-------------- .github/workflows/ci-cd.yml | 27 +++++++++++++-------------- infra/docker/ci.Dockerfile | 20 ++++++++++++++++++++ infra/scripts/build-ci-image.sh | 14 ++++++++++++++ requirements-dev.txt | 1 - requirements-quality.txt | 1 - 6 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 infra/docker/ci.Dockerfile create mode 100644 infra/scripts/build-ci-image.sh diff --git a/.gitea/workflows/ci-cd.yml b/.gitea/workflows/ci-cd.yml index 9769a493c..91909a6aa 100644 --- a/.gitea/workflows/ci-cd.yml +++ b/.gitea/workflows/ci-cd.yml @@ -18,7 +18,7 @@ jobs: validate: name: Validate Code Quality And Tests runs-on: ubuntu-latest - container: python:3.12-slim + container: xiaoxia-ci-python:3.12 steps: - name: Checkout code @@ -48,28 +48,27 @@ jobs: archive.extract(member, '.') PY - - name: Prepare environment + - name: Verify CI environment + run: | + python --version + python -m pip --version + python -m black --version + python -m isort --version-number + python -m flake8 --version + bandit --version + pytest --version + echo "✅ Prebuilt CI environment is ready" + + - name: Run code quality checks run: | - python3 --version - python3 -m venv .venv - . .venv/bin/activate - python -m pip install --index-url https://pypi.org/simple --upgrade pip - python -m pip install --index-url https://pypi.org/simple -r requirements-quality.txt - python -m pip install --index-url https://pypi.org/simple -r requirements-dev.txt - - - name: Run code quality checks - run: | - . .venv/bin/activate python -m black --version python -m isort --version-number python -m flake8 --version - python -m mypy --version bandit --version echo "✅ Code quality environment is ready" - name: Run tests run: | - . .venv/bin/activate pytest --version echo "✅ Test environment is ready" diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 9769a493c..91909a6aa 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -18,7 +18,7 @@ jobs: validate: name: Validate Code Quality And Tests runs-on: ubuntu-latest - container: python:3.12-slim + container: xiaoxia-ci-python:3.12 steps: - name: Checkout code @@ -48,28 +48,27 @@ jobs: archive.extract(member, '.') PY - - name: Prepare environment + - name: Verify CI environment + run: | + python --version + python -m pip --version + python -m black --version + python -m isort --version-number + python -m flake8 --version + bandit --version + pytest --version + echo "✅ Prebuilt CI environment is ready" + + - name: Run code quality checks run: | - python3 --version - python3 -m venv .venv - . .venv/bin/activate - python -m pip install --index-url https://pypi.org/simple --upgrade pip - python -m pip install --index-url https://pypi.org/simple -r requirements-quality.txt - python -m pip install --index-url https://pypi.org/simple -r requirements-dev.txt - - - name: Run code quality checks - run: | - . .venv/bin/activate python -m black --version python -m isort --version-number python -m flake8 --version - python -m mypy --version bandit --version echo "✅ Code quality environment is ready" - name: Run tests run: | - . .venv/bin/activate pytest --version echo "✅ Test environment is ready" diff --git a/infra/docker/ci.Dockerfile b/infra/docker/ci.Dockerfile new file mode 100644 index 000000000..ca384ccf8 --- /dev/null +++ b/infra/docker/ci.Dockerfile @@ -0,0 +1,20 @@ +FROM python:3.12-slim + +ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \ + PIP_NO_CACHE_DIR=0 \ + PIP_INDEX_URL=https://pypi.org/simple \ + VIRTUAL_ENV=/opt/xiaoxia-ci-venv \ + PATH=/opt/xiaoxia-ci-venv/bin:$PATH + +WORKDIR /workspace + +COPY requirements-quality.txt requirements-dev.txt ./ + +RUN python -m venv "$VIRTUAL_ENV" \ + && python -m pip install --retries 10 --timeout 120 -r requirements-quality.txt \ + && python -m pip install --retries 10 --timeout 120 -r requirements-dev.txt \ + && python -m black --version \ + && python -m isort --version-number \ + && python -m flake8 --version \ + && bandit --version \ + && pytest --version diff --git a/infra/scripts/build-ci-image.sh b/infra/scripts/build-ci-image.sh new file mode 100644 index 000000000..16c7d2134 --- /dev/null +++ b/infra/scripts/build-ci-image.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" +IMAGE_NAME="${CI_IMAGE_NAME:-xiaoxia-ci-python:3.12}" + +echo "🔨 Building CI image: $IMAGE_NAME" +docker build \ + -f "$REPO_ROOT/infra/docker/ci.Dockerfile" \ + -t "$IMAGE_NAME" \ + "$REPO_ROOT" + +echo "✅ CI image ready: $IMAGE_NAME" diff --git a/requirements-dev.txt b/requirements-dev.txt index d2971d999..b2971fe02 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,7 +4,6 @@ black==26.5.1 isort==8.0.1 flake8==7.3.0 -mypy==2.1.0 bandit==1.9.4 # 测试 diff --git a/requirements-quality.txt b/requirements-quality.txt index ab208bcb0..d47594016 100644 --- a/requirements-quality.txt +++ b/requirements-quality.txt @@ -4,5 +4,4 @@ black==26.5.1 isort==8.0.1 flake8==7.3.0 -mypy==2.1.0 bandit==1.9.4