name: memscope-rs CI
on:
push:
branches: [master, develop]
tags: ["v*"]
pull_request:
branches: [master, develop]
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUSTFLAGS: "-D warnings"
jobs:
quality:
name: Code Quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: rustfmt, clippy
- name: Verify toolchain
run: |
rustc --version
cargo --version
rustfmt --version
- name: Handle Cargo.lock compatibility
shell: bash
run: |
# Always regenerate Cargo.lock for CI to ensure compatibility
echo "Regenerating Cargo.lock for CI compatibility..."
rm -f Cargo.lock
cargo generate-lockfile
echo "Generated compatible Cargo.lock version: $(head -n1 Cargo.lock)"
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
with:
key: quality-${{ hashFiles('**/Cargo.lock') }}
- name: Check formatting
run: cargo fmt --all -- --check
- name: Clippy analysis
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
- name: Check compilation
run: cargo check --workspace --all-targets --all-features
test:
name: Tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
rust: [stable]
include:
- os: ubuntu-latest
rust: nightly
experimental: true
steps:
- uses: actions/checkout@v4
- name: Install Rust ${{ matrix.rust }}
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- name: Handle Cargo.lock compatibility
shell: bash
run: |
# Always regenerate Cargo.lock for CI to ensure compatibility
echo "Regenerating Cargo.lock for CI compatibility..."
rm -f Cargo.lock
cargo generate-lockfile
echo "Generated compatible Cargo.lock version: $(head -n1 Cargo.lock)"
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
with:
key: test-${{ matrix.os }}-${{ matrix.rust }}-${{ hashFiles('**/Cargo.lock') }}
- name: Run library tests
run: cargo test --lib --workspace -- --test-threads=1
continue-on-error: ${{ matrix.experimental == true }}
- name: Run integration tests
run: cargo test --test '*' --workspace -- --test-threads=1
continue-on-error: ${{ matrix.experimental == true }}
- name: Test examples
run: |
cargo run --example basic_usage
cargo run --example unsafe_ffi_demo
continue-on-error: ${{ matrix.experimental == true }}
benchmarks:
name: Benchmarks
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Handle Cargo.lock compatibility
shell: bash
run: |
# Always regenerate Cargo.lock for CI to ensure compatibility
echo "Regenerating Cargo.lock for CI compatibility..."
rm -f Cargo.lock
cargo generate-lockfile
echo "Generated compatible Cargo.lock version: $(head -n1 Cargo.lock)"
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
with:
key: bench-${{ hashFiles('**/Cargo.lock') }}
- name: Run benchmarks
run: cargo bench --bench minimal_performance
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: target/criterion/
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Handle Cargo.lock compatibility
shell: bash
run: |
# Always regenerate Cargo.lock for CI to ensure compatibility
echo "Regenerating Cargo.lock for CI compatibility..."
rm -f Cargo.lock
cargo generate-lockfile
echo "Generated compatible Cargo.lock version: $(head -n1 Cargo.lock)"
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
with:
key: docs-${{ hashFiles('**/Cargo.lock') }}
- name: Build documentation
run: cargo doc --workspace --all-features --no-deps
security:
name: Security Audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Handle Cargo.lock compatibility
shell: bash
run: |
# Always regenerate Cargo.lock for CI to ensure compatibility
echo "Regenerating Cargo.lock for CI compatibility..."
rm -f Cargo.lock
cargo generate-lockfile
echo "Generated compatible Cargo.lock version: $(head -n1 Cargo.lock)"
- name: Install cargo-audit
run: cargo install cargo-audit --locked
- name: Run security audit
run: cargo audit || echo "Audit check completed (some warnings may be acceptable)"
- name: Check licenses
run: |
cargo install cargo-license
cargo license --json | jq -r '.[] | select(.license != "MIT" and .license != "Apache-2.0" and .license != "BSD-3-Clause" and .license != "BSD-2-Clause") | .name + ": " + .license'
coverage:
name: Code Coverage
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
with:
key: coverage-${{ matrix.os }}-${{ hashFiles('**/Cargo.lock') }}
- name: Install cargo-llvm-cov
run: cargo install cargo-llvm-cov
- name: Generate coverage
run: cargo llvm-cov --workspace --lcov --output-path lcov.info
- name: Upload to codecov
uses: codecov/codecov-action@v3
with:
files: lcov.info
fail_ci_if_error: false
publish:
name: Publish to crates.io
if: startsWith(github.ref, 'refs/tags/v')
needs: [quality, test, docs, security]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Verify version consistency
run: |
VERSION=${GITHUB_REF#refs/tags/v}
CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
if [ "$VERSION" != "$CARGO_VERSION" ]; then
echo "Version mismatch: tag=$VERSION, Cargo.toml=$CARGO_VERSION"
exit 1
fi
- name: Publish memscope-derive
working-directory: memscope-derive
run: cargo publish --token ${{ secrets.CRATES_IO_TOKEN }}
continue-on-error: true
- name: Wait for derive package
run: sleep 30
- name: Publish memscope-rs
run: cargo publish --token ${{ secrets.CRATES_IO_TOKEN }}
continue-on-error: true