Update Justfile to enhance testing command and dependency installation #118
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| env: | |
| CARGO_TERM_COLOR: always | |
| RUST_BACKTRACE: 1 | |
| jobs: | |
| # ============================================ | |
| # 代码规范检查(快速反馈) | |
| # ============================================ | |
| lint: | |
| name: Lint & Format | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Build Environment | |
| uses: ./.github/actions/setup-build-env | |
| with: | |
| rust-toolchain: stable | |
| python-version: '3.12' | |
| install-cargo-tools: 'false' | |
| install-python-deps: 'true' | |
| - name: Rust formatting | |
| run: cargo fmt --all -- --check | |
| - name: Rust clippy | |
| run: cargo clippy --workspace --exclude pulsing-py --exclude pulsing-bench-py --all-targets -- -D warnings | |
| - name: Python lint (ruff) | |
| run: ruff check python/ | |
| # ============================================ | |
| # Rust 构建和测试(多平台) | |
| # ============================================ | |
| rust-test: | |
| name: Rust Test (${{ matrix.os }}) | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Build Environment | |
| uses: ./.github/actions/setup-build-env | |
| with: | |
| rust-toolchain: stable | |
| install-cargo-tools: 'false' | |
| - name: Cache Rust build | |
| uses: Swatinem/rust-cache@v2 | |
| - name: Build | |
| run: cargo build --workspace --exclude pulsing-py --exclude pulsing-bench-py --all-targets | |
| - name: Test | |
| run: cargo test --workspace --exclude pulsing-py --exclude pulsing-bench-py --all-targets | |
| # ============================================ | |
| # Rust 覆盖率收集 | |
| # ============================================ | |
| rust-coverage: | |
| name: Rust Coverage | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Build Environment | |
| uses: ./.github/actions/setup-build-env | |
| with: | |
| rust-toolchain: stable | |
| install-cargo-tools: 'true' | |
| - name: Cache Rust build | |
| uses: Swatinem/rust-cache@v2 | |
| - name: Run tests and collect coverage | |
| shell: bash | |
| run: | | |
| source <(cargo llvm-cov show-env --export-prefix) | |
| export CARGO_TARGET_DIR=$CARGO_LLVM_COV_TARGET_DIR | |
| export CARGO_INCREMENTAL=1 | |
| cargo llvm-cov clean --workspace | |
| cargo test --workspace --exclude pulsing-py --exclude pulsing-bench-py | |
| cargo llvm-cov --no-run --lcov --output-path coverage.lcov | |
| - name: Upload coverage report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: rust-coverage | |
| path: coverage.lcov | |
| retention-days: 30 | |
| # ============================================ | |
| # 构建 macOS Wheel | |
| # ============================================ | |
| build-macos: | |
| name: Build Wheel (macOS) | |
| runs-on: macos-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Build Environment | |
| uses: ./.github/actions/setup-build-env | |
| with: | |
| python-version: '3.10' | |
| - name: Cache Rust build | |
| uses: Swatinem/rust-cache@v2 | |
| - name: Build wheel | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| args: --release --out dist | |
| sccache: 'true' | |
| - name: Upload wheels | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-macos | |
| path: dist/*.whl | |
| # ============================================ | |
| # 构建 Linux x86-64 Wheel (使用 just 命令) | |
| # ============================================ | |
| build-linux-x86-64: | |
| name: Build Wheel (Linux x86-64) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Build wheel in manylinux container | |
| run: | | |
| docker run --rm \ | |
| -v ${{ github.workspace }}:/workspace -w /workspace \ | |
| quay.io/pypa/manylinux2014_x86_64 \ | |
| bash -c " | |
| curl -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin && \ | |
| just ci-setup-manylinux && \ | |
| just ci-build manylinux=true | |
| " | |
| - name: Upload wheels | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-linux-x86-64 | |
| path: dist/*.whl | |
| # ============================================ | |
| # 构建 Linux aarch64 Wheel(使用 QEMU 仿真原生构建) | |
| # ============================================ | |
| build-linux-aarch64: | |
| name: Build Wheel (Linux aarch64) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| platforms: arm64 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build wheel in QEMU | |
| run: | | |
| docker run --rm --platform linux/arm64 \ | |
| -v ${{ github.workspace }}:/workspace -w /workspace \ | |
| quay.io/pypa/manylinux2014_aarch64 \ | |
| bash -c " | |
| curl -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin && \ | |
| just ci-setup-manylinux && \ | |
| just ci-build manylinux=true | |
| " | |
| - name: Upload wheels | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-linux-aarch64 | |
| path: dist/*.whl | |
| # ============================================ | |
| # macOS Python 测试(多 Python 版本) | |
| # ============================================ | |
| test-macos: | |
| name: Test macOS (Python ${{ matrix.python-version }}) | |
| needs: build-macos | |
| runs-on: macos-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.10", "3.11", "3.12"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Download wheel | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: wheels-macos | |
| path: dist/ | |
| - name: Install wheel and test dependencies | |
| run: | | |
| pip install dist/*.whl | |
| pip install pytest pytest-asyncio pytest-cov | |
| - name: Test with pytest | |
| run: pytest tests/python -v | |
| # ============================================ | |
| # Ubuntu x86-64 Python 测试(多版本 × 多 Python 版本) | |
| # ============================================ | |
| test-ubuntu-x86-64: | |
| name: Test Ubuntu ${{ matrix.ubuntu }} x86-64 (Python ${{ matrix.python-version }}) | |
| needs: build-linux-x86-64 | |
| runs-on: ${{ matrix.runner }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| ubuntu: ["20.04", "22.04", "24.04"] | |
| python-version: ["3.10", "3.11", "3.12"] | |
| include: | |
| - ubuntu: "20.04" | |
| runner: ubuntu-20.04 | |
| - ubuntu: "22.04" | |
| runner: ubuntu-22.04 | |
| - ubuntu: "24.04" | |
| runner: ubuntu-24.04 | |
| exclude: | |
| # Ubuntu 20.04 不支持 Python 3.12 | |
| - ubuntu: "20.04" | |
| python-version: "3.12" | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download wheel | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: wheels-linux-x86-64 | |
| path: dist/ | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install wheel and test dependencies | |
| run: | | |
| pip install dist/*.whl | |
| pip install pytest pytest-asyncio pytest-cov | |
| - name: Test with pytest | |
| run: pytest tests/python -v | |
| # ============================================ | |
| # Ubuntu aarch64 Python 测试(使用 QEMU 仿真) | |
| # ============================================ | |
| test-ubuntu-aarch64: | |
| name: Test Ubuntu aarch64 (Python ${{ matrix.python-version }}) | |
| needs: build-linux-aarch64 | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.10", "3.11", "3.12"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| platforms: arm64 | |
| - name: Download wheel | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: wheels-linux-aarch64 | |
| path: dist/ | |
| - name: Test on Ubuntu aarch64 (QEMU) | |
| run: | | |
| docker run --rm --platform linux/arm64 \ | |
| -v ${{ github.workspace }}:/workspace -w /workspace \ | |
| python:${{ matrix.python-version }}-slim \ | |
| bash -c " | |
| curl -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin && \ | |
| just ci-setup-debian && \ | |
| just ci-test | |
| " | |
| # ============================================ | |
| # Fedora Python 测试(x86-64) | |
| # ============================================ | |
| test-fedora: | |
| name: Test Fedora x86-64 (Python ${{ matrix.python-version }}) | |
| needs: build-linux-x86-64 | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.10", "3.11", "3.12"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download wheel | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: wheels-linux-x86-64 | |
| path: dist/ | |
| - name: Test on Fedora | |
| run: | | |
| docker run --rm -v ${{ github.workspace }}:/workspace -w /workspace \ | |
| fedora:latest \ | |
| bash -c " | |
| curl -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin && \ | |
| just ci-setup-fedora ${{ matrix.python-version }} && \ | |
| just ci-test | |
| " | |
| # ============================================ | |
| # Python 覆盖率收集 | |
| # ============================================ | |
| python-coverage: | |
| name: Python Coverage | |
| needs: build-linux-x86-64 | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Download wheel | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: wheels-linux-x86-64 | |
| path: dist/ | |
| - name: Install wheel and test dependencies | |
| run: | | |
| pip install dist/*.whl | |
| pip install pytest pytest-asyncio pytest-cov | |
| - name: Run tests and collect coverage | |
| run: pytest tests/python --cov=pulsing --cov-report=xml:coverage.xml -v | |
| - name: Upload coverage report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: python-coverage | |
| path: coverage.xml | |
| retention-days: 30 | |
| # ============================================ | |
| # 上传覆盖率到 Codecov | |
| # ============================================ | |
| codecov: | |
| name: Upload Coverage | |
| needs: [rust-coverage, python-coverage] | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download Rust coverage | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: rust-coverage | |
| path: . | |
| continue-on-error: true | |
| - name: Download Python coverage | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: python-coverage | |
| path: . | |
| continue-on-error: true | |
| - name: Check coverage files | |
| run: | | |
| echo "=== Coverage files check ===" | |
| [ -f coverage.lcov ] && echo "✓ coverage.lcov exists" || echo "✗ coverage.lcov not found" | |
| [ -f coverage.xml ] && echo "✓ coverage.xml exists" || echo "✗ coverage.xml not found" | |
| - name: Upload to Codecov | |
| uses: codecov/codecov-action@v4 | |
| with: | |
| files: coverage.lcov,coverage.xml | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| fail_ci_if_error: false | |
| verbose: true |