diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..ce633bae --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,5 @@ +{ + "tasks": { + "build": "cargo build --release" + } +} \ No newline at end of file diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index f75228c7..51c79ee2 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -2,82 +2,72 @@ name: Benchmarks on: push: - branches: [ main ] + branches: + - main pull_request: - branches: [ main ] - schedule: - - cron: '0 0 * * 0' # Run weekly on Sundays - -env: - CARGO_TERM_COLOR: always - RUST_BACKTRACE: 1 + branches: + - main jobs: - benchmarks: - name: Run Benchmarks + benchmark: runs-on: ubuntu-latest + steps: - - uses: actions/checkout@v3 - - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Cache dependencies - uses: actions/cache@v3 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - target - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - - name: Install cargo-criterion - uses: actions-rs/install@v0.1 - with: - crate: cargo-criterion - version: latest - use-tool-cache: true - - - name: Run benchmarks - uses: actions-rs/cargo@v1 - with: - command: criterion + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Install dependencies + run: sudo apt-get update && sudo apt-get install -y libudev-dev + + - name: Set environment variables + run: | + export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig + export LD_LIBRARY_PATH=/usr/local/lib + + - name: Run benchmarks + run: | + export RUST_BACKTRACE=full + cargo bench - - name: Create benchmark results directory - run: mkdir -p target/criterion + - name: Create benchmark results directory + run: mkdir -p target/criterion - - name: Upload benchmark results - uses: actions/upload-artifact@v3 - with: - name: benchmark-results - path: target/criterion - if-no-files-found: warn + - name: Upload benchmark results + uses: actions/upload-artifact@v4 + with: + name: benchmark-results + path: target/criterion + if-no-files-found: warn - - name: Generate benchmark report - run: | - mkdir -p benchmark-report + - name: Generate benchmark report + run: | + mkdir -p benchmark-report + if [ -d "target/criterion" ]; then cp -r target/criterion/* benchmark-report/ || true - echo "# Benchmark Results" > benchmark-report/README.md - echo "Generated on $(date)" >> benchmark-report/README.md - echo "## Summary" >> benchmark-report/README.md - find target/criterion -name "*/new/estimates.json" -exec cat {} \; | jq -r '.mean | { command: .point_estimate, lower_bound: .confidence_interval.lower_bound, upper_bound: .confidence_interval.upper_bound }' >> benchmark-report/README.md || echo "No benchmark results found" >> benchmark-report/README.md + fi + echo "# Benchmark Results" > benchmark-report/README.md + echo "Generated on $(date)" >> benchmark-report/README.md + echo "## Summary" >> benchmark-report/README.md + find target/criterion -name "*/new/estimates.json" -exec cat {} \; | jq -r '.mean | { command: .point_estimate, lower_bound: .confidence_interval.lower_bound, upper_bound: .confidence_interval.upper_bound}' >> benchmark-report/README.md - - name: Upload benchmark report - uses: actions/upload-artifact@v3 - with: - name: benchmark-report - path: benchmark-report - if-no-files-found: warn + - name: Upload benchmark report + uses: actions/upload-artifact@v4 + with: + name: benchmark-report + path: benchmark-report + if-no-files-found: warn - - name: Compare with previous benchmarks - if: github.event_name == 'pull_request' - run: | - git fetch origin ${{ github.base_ref }} - git checkout FETCH_HEAD - cargo criterion --baseline main - git checkout ${{ github.sha }} - cargo criterion --baseline main + - name: Compare with previous benchmarks + if: github.event_name == 'pull_request' + run: | + git fetch origin ${{ github.base_ref }} + git checkout FETCH_HEAD + cargo criterion --baseline main + git checkout ${{ github.sha }} + cargo criterion --baseline main diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b2e4e310..c957a3d6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,10 +15,12 @@ jobs: name: Sanity Checks runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - + - uses: actions/checkout@v4 + - name: Install dependencies + run: sudo apt-get update && sudo apt-get install -y libudev-dev + - name: Install Rust - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: profile: minimal toolchain: stable @@ -26,7 +28,7 @@ jobs: components: rustfmt, clippy - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.cargo/registry @@ -35,33 +37,32 @@ jobs: key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Check formatting - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check + run: cargo fmt --all -- --check + working-directory: . - name: Run clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: -- -D warnings + run: cargo clippy -- -D warnings + working-directory: . unit-tests: name: Unit Tests needs: sanity-check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + + - name: Install dependencies + run: sudo apt-get update && sudo apt-get install -y libudev-dev - name: Install Rust - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: profile: minimal toolchain: stable override: true - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.cargo/registry @@ -70,27 +71,28 @@ jobs: key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Run unit tests - uses: actions-rs/cargo@v1 - with: - command: test - args: --lib --bins + run: cargo test --lib --bins + working-directory: . e2e-tests: name: End-to-End Tests needs: unit-tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + + - name: Install dependencies + run: sudo apt-get update && sudo apt-get install -y libudev-dev - name: Install Rust - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: profile: minimal toolchain: stable override: true - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.cargo/registry @@ -99,46 +101,40 @@ jobs: key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Build binary - uses: actions-rs/cargo@v1 - with: - command: build - args: --release + run: cargo build --release + working-directory: . - name: Run e2e tests - uses: actions-rs/cargo@v1 - with: - command: test - args: --test main + run: cargo test --test main + working-directory: . code-coverage: name: Code Coverage needs: [unit-tests, e2e-tests] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - + - uses: actions/checkout@v4 + + - name: Install dependencies + run: sudo apt-get update && sudo apt-get install -y libudev-dev + - name: Install Rust - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: profile: minimal toolchain: stable override: true - name: Install cargo-tarpaulin - uses: actions-rs/install@v0.1 - with: - crate: cargo-tarpaulin - version: latest - use-tool-cache: true + run: cargo install cargo-tarpaulin + working-directory: . - name: Generate coverage report - uses: actions-rs/cargo@v1 - with: - command: tarpaulin - args: --out Xml --output-dir coverage + run: cargo tarpaulin --out Xml --output-dir coverage + working-directory: . - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: directory: ./coverage/ - fail_ci_if_error: true \ No newline at end of file + fail_ci_if_error: true diff --git a/.github/workflows/cross-platform.yml b/.github/workflows/cross-platform.yml index ac7a3be0..6d2d77e1 100644 --- a/.github/workflows/cross-platform.yml +++ b/.github/workflows/cross-platform.yml @@ -18,17 +18,23 @@ jobs: os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + + - name: Install dependencies + if: runner.os == 'linux' + run: | + sudo apt-get update + sudo apt-get install -y libudev-dev - name: Install Rust - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: profile: minimal toolchain: stable override: true - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.cargo/registry @@ -37,19 +43,38 @@ jobs: key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Build - uses: actions-rs/cargo@v1 - with: - command: build + run: cargo build + working-directory: . - name: Run unit tests - uses: actions-rs/cargo@v1 - with: - command: test - args: --lib --bins + run: cargo test --lib --bins + working-directory: . - name: Run e2e tests - uses: actions-rs/cargo@v1 - with: - command: test - args: --test "*" + run: cargo test --test "*" + working-directory: . continue-on-error: true + + release: + name: release ${{ matrix.target }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - target: x86_64-pc-windows-gnu + archive: zip + - target: x86_64-unknown-linux-musl + archive: tar.gz tar.xz tar.zst + - target: x86_64-apple-darwin + archive: zip + steps: + - uses: actions/checkout@master + - name: Compile and release + uses: rust-build/rust-build.action@v1.4.5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + RUSTTARGET: ${{ matrix.target }} + ARCHIVE_TYPES: ${{ matrix.archive }} + diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 42808083..26debbb7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,23 +14,21 @@ jobs: name: Build Release Binaries runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install Rust - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: profile: minimal toolchain: stable override: true - name: Build release binary - uses: actions-rs/cargo@v1 - with: - command: build - args: --release + run: cargo build --release + working-directory: . - name: Upload binary - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: osvm-binary path: target/release/osvm @@ -40,10 +38,10 @@ jobs: needs: build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Download binary - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: osvm-binary path: ./ @@ -67,10 +65,10 @@ jobs: needs: create-github-release runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Download binary - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: osvm-binary path: ./ @@ -94,7 +92,7 @@ jobs: dpkg-buildpackage -us -uc - name: Upload Debian package - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: osvm-deb-package path: ../osvm_*.deb @@ -112,7 +110,7 @@ jobs: needs: create-github-release runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Homebrew uses: Homebrew/actions/setup-homebrew@master @@ -144,7 +142,7 @@ jobs: EOF - name: Upload Homebrew formula - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: osvm-homebrew-formula path: ./osvm.rb @@ -161,28 +159,26 @@ jobs: needs: create-github-release runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install Rust - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: profile: minimal toolchain: stable override: true - name: Generate documentation - uses: actions-rs/cargo@v1 - with: - command: doc - args: --no-deps --document-private-items + run: cargo doc --no-deps --document-private-items + working-directory: . - name: Create index.html run: | echo '' > target/doc/index.html - name: Deploy to GitHub Pages - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./target/doc - force_orphan: true \ No newline at end of file + force_orphan: true diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 8c0ad0ae..c98ef09a 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -13,31 +13,31 @@ jobs: name: Security Audit runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - name: Install Dependencies + run: | + sudo apt-get update + sudo apt-get install libudev-dev + - name: Install Rust - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: profile: minimal toolchain: stable override: true - name: Install cargo-audit - uses: actions-rs/install@v0.1 - with: - crate: cargo-audit - version: latest - use-tool-cache: true + run: cargo install cargo-audit + working-directory: . - name: Run cargo-audit - uses: actions-rs/cargo@v1 - with: - command: audit + run: cargo audit + working-directory: . - name: Run cargo-deny - uses: EmbarkStudios/cargo-deny-action@v1 - with: - command: check advisories + run: cargo deny check advisories + working-directory: . dependency-review: name: Dependency Review @@ -45,10 +45,10 @@ jobs: if: github.event_name == 'pull_request' steps: - name: Checkout Repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Dependency Review - uses: actions/dependency-review-action@v3 + uses: actions/dependency-review-action@v4 with: fail-on-severity: high @@ -61,17 +61,23 @@ jobs: contents: read steps: - name: Checkout repository - uses: actions/checkout@v3 - + uses: actions/checkout@v4 + + - name: Install Dependencies + run: | + sudo apt-get update + sudo apt-get install libudev-dev + - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: rust + env: + CODEQL_ENABLE_EXPERIMENTAL_FEATURES: true - name: Build - uses: actions-rs/cargo@v1 - with: - command: build + run: cargo build + working-directory: . - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 \ No newline at end of file + uses: github/codeql-action/analyze@v3 diff --git a/Cargo.toml b/Cargo.toml index 84769970..8b53ed53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,7 @@ predicates = "3.1.3" tempfile = "3.18.0" serial_test = "3.2.0" mockito = "1.7.0" +criterion = "0.3" [features] default = []