chore: Standardize CI/CD and release workflows to run on `ubuntu-late… #3
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: Python SDK CI/CD | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| env: | |
| CARGO_TERM_COLOR: always | |
| RUST_BACKTRACE: 1 | |
| jobs: | |
| # ============================================ | |
| # Job 1: Code Quality & Unit Tests | |
| # ============================================ | |
| quality: | |
| name: Code Quality (Rust) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust Toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| components: rustfmt, clippy | |
| - name: Cache Cargo Dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.cargo/bin/ | |
| ~/.cargo/registry/index/ | |
| ~/.cargo/registry/cache/ | |
| ~/.cargo/git/db/ | |
| target/ | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }} | |
| - name: Run rustfmt | |
| run: cargo fmt --all -- --check | |
| - name: Run clippy | |
| run: cargo clippy --all-targets --all-features -- -D warnings | |
| - name: Run Rust tests | |
| run: cargo test --verbose | |
| # ============================================ | |
| # Job 2: Python Tests (Multi-version) | |
| # ============================================ | |
| test: | |
| name: Python Tests (${{ matrix.python-version }}) | |
| runs-on: ubuntu-latest | |
| needs: quality | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ['3.9', '3.10', '3.11', '3.12'] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install Rust Toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Cache Cargo Dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.cargo/bin/ | |
| ~/.cargo/registry/index/ | |
| ~/.cargo/registry/cache/ | |
| ~/.cargo/git/db/ | |
| sdk/python/target/ | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('sdk/python/Cargo.lock') }} | |
| - name: Install Python Dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install maturin pytest pytest-cov | |
| - name: Build Extension | |
| run: maturin develop --release | |
| - name: Run Python Tests | |
| run: | | |
| export PYTHONPATH=$PWD:$PYTHONPATH | |
| pytest tests/ -v --cov=lnmp --cov-report=xml | |
| - name: Upload Coverage | |
| if: matrix.python-version == '3.11' | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./coverage.xml | |
| flags: python-sdk | |
| # ============================================ | |
| # Job 3: Build Wheels (Multi-platform) | |
| # ============================================ | |
| build: | |
| name: Build Wheels (${{ matrix.target }}) | |
| runs-on: ${{ matrix.os }} | |
| needs: test | |
| if: github.event_name == 'workflow_dispatch' | |
| strategy: | |
| matrix: | |
| include: | |
| # Linux | |
| - os: ubuntu-latest | |
| target: x86_64-unknown-linux-gnu | |
| name: linux-x86_64 | |
| - os: ubuntu-latest | |
| target: aarch64-unknown-linux-gnu | |
| name: linux-aarch64 | |
| # macOS | |
| - os: macos-latest | |
| target: x86_64-apple-darwin | |
| name: macos-x86_64 | |
| - os: macos-latest | |
| target: aarch64-apple-darwin | |
| name: macos-arm64 | |
| # Windows | |
| - os: windows-latest | |
| target: x86_64-pc-windows-msvc | |
| name: windows-x86_64 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install Rust Toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install Maturin | |
| run: pip install maturin | |
| - name: Build Wheels | |
| run: maturin build --release --target ${{ matrix.target }} --out dist | |
| - name: Upload Wheels | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: wheels-${{ matrix.name }} | |
| path: dist/*.whl | |
| # ============================================ | |
| # Job 4: Publish to PyPI | |
| # ============================================ | |
| publish: | |
| name: Publish to PyPI | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: github.event_name == 'workflow_dispatch' | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/lnmp | |
| permissions: | |
| id-token: write | |
| steps: | |
| - name: Download All Wheels | |
| uses: actions/download-artifact@v3 | |
| with: | |
| path: dist | |
| - name: Flatten Dist Directory | |
| run: | | |
| mkdir -p final-dist | |
| find dist -name '*.whl' -exec cp {} final-dist/ \; | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| packages-dir: final-dist/ | |
| skip-existing: true | |
| # ============================================ | |
| # Job 5: Benchmarks (Optional) | |
| # ============================================ | |
| benchmark: | |
| name: Performance Benchmarks | |
| runs-on: ubuntu-latest | |
| needs: quality | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install Rust Toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install Dependencies | |
| run: | | |
| pip install maturin | |
| maturin develop --release | |
| - name: Run Benchmarks | |
| run: python benchmarks/run_benchmarks.py | |
| - name: Upload Benchmark Results | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: benchmarks | |
| path: BENCHMARKS.md |