From 615831fa485552c0d9588ae8484117d366482ae8 Mon Sep 17 00:00:00 2001 From: cytxnyu <3612408338@qq.com> Date: Wed, 15 Apr 2026 09:04:52 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E4=BC=98=E5=8C=96CI=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E6=B5=81=E5=B9=B6=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 合并pr.yml到ci.yml,简化工作流配置 - 添加lint和测试步骤到CI流程 - 更新README.md添加验证步骤说明 - 移除pre-commit的ci.skip配置 - 锁定uv版本为0.10.3 --- .github/workflows/ci.yml | 56 ++++++++++++++++++++++++++++-- .github/workflows/pr.yml | 51 ---------------------------- .pre-commit-config.yaml | 3 -- README.md | 73 ++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 2 +- 5 files changed, 127 insertions(+), 58 deletions(-) delete mode 100644 .github/workflows/pr.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7034c68..a0b590e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,46 +4,96 @@ on: push: branches: - main + pull_request: + branches: + - "**" concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true jobs: - build: + lint-and-test: env: UV_CACHE_DIR: /tmp/.uv-cache runs-on: ubuntu-24.04 steps: - name: Checkout source code uses: actions/checkout@v6 + - name: Set up python id: setup-python uses: actions/setup-python@v6 with: python-version-file: ".python-version" + - name: Set up uv uses: astral-sh/setup-uv@v7 with: enable-cache: true version-file: "pyproject.toml" + - name: Install dependencies run: uv sync --all-extras --dev --frozen - - name: Test with pytest + + - name: Run ruff lint + run: uv run ruff check src tests + + - name: Run ruff format check + run: uv run ruff format --check src tests + + - name: Run mypy type check + run: uv run mypy src tests + + - name: Run bandit security check + run: uv run bandit -r src + + - name: Run pytest with coverage run: uv run pytest tests --cov=src + + - name: Minimize uv cache + run: uv cache prune --ci + + build: + needs: lint-and-test + env: + UV_CACHE_DIR: /tmp/.uv-cache + runs-on: ubuntu-24.04 + steps: + - name: Checkout source code + uses: actions/checkout@v6 + + - name: Set up python + id: setup-python + uses: actions/setup-python@v6 + with: + python-version-file: ".python-version" + + - name: Set up uv + uses: astral-sh/setup-uv@v7 + with: + enable-cache: true + version-file: "pyproject.toml" + + - name: Install dependencies + run: uv sync --all-extras --dev --frozen + - name: Build a wheel run: uv build + - name: Minimize uv cache run: uv cache prune --ci build-image: + needs: lint-and-test runs-on: ubuntu-24.04 - steps: - name: Checkout source code uses: actions/checkout@v6 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Build docker image uses: docker/build-push-action@v6 with: diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml deleted file mode 100644 index c6f939b..0000000 --- a/.github/workflows/pr.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: pr - -on: - pull_request: - branches: - - "**" - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -jobs: - build: - env: - UV_CACHE_DIR: /tmp/.uv-cache - runs-on: ubuntu-24.04 - steps: - - name: Checkout source code - uses: actions/checkout@v6 - - name: Set up python - id: setup-python - uses: actions/setup-python@v6 - with: - python-version-file: ".python-version" - - name: Set up uv - uses: astral-sh/setup-uv@v7 - with: - enable-cache: true - version-file: "pyproject.toml" - - name: Install dependencies - run: uv sync --all-extras --dev --frozen - - name: Test with pytest - run: uv run pytest tests --cov=src - - name: Build a wheel - run: uv build - - name: Minimize uv cache - run: uv cache prune --ci - - build-image: - runs-on: ubuntu-24.04 - - steps: - - name: Checkout source code - uses: actions/checkout@v6 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Build docker image - uses: docker/build-push-action@v6 - with: - context: . - push: false diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1e663d8..55a8782 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,3 @@ -ci: - skip: [pytest] - default_language_version: python: python3.14 diff --git a/README.md b/README.md index 5dc24b0..a1056fe 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,79 @@ TOTAL 7 2 71% --- +## Validation + +To ensure all configurations are working correctly, you can run the following checks: + +### Linting and Formatting + +**Run ruff lint check:** +```bash +uv run ruff check src tests +``` + +**Run ruff format check:** +```bash +uv run ruff format --check src tests +``` + +**Run ruff format (to fix formatting issues):** +```bash +uv run ruff format src tests +``` + +### Type Checking + +**Run mypy type check:** +```bash +uv run mypy src tests +``` + +### Security Checking + +**Run bandit security check:** +```bash +uv run bandit -r src +``` + +### Testing + +**Run pytest:** +```bash +uv run pytest tests +``` + +**Run pytest with coverage:** +```bash +uv run pytest tests --cov=src +``` + +### Pre-commit Hooks + +**Run all pre-commit hooks:** +```bash +pre-commit run --all-files +``` + +### Docker + +**Build production image:** +```bash +docker build . -t my-python-application:latest +``` + +**Build development image:** +```bash +docker build . --target development -t my-python-application:dev +``` + +**Run the application:** +```bash +docker run -it --rm my-python-application:latest +``` + +--- + ## Docker ### Build diff --git a/pyproject.toml b/pyproject.toml index 21e08e0..0f0c7aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,7 @@ dev = [ ] [tool.uv] -required-version = ">=0.9.30" +required-version = "==0.10.3" [tool.pytest.ini_options] addopts = "-vvv"