diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5282b54e..a02d9f3c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,4 +20,21 @@ jobs: - name: Build Project run: sudo make -e install - name: Run Project - run: sr -h \ No newline at end of file + run: sr -h + rust-build: + runs-on: ubuntu-latest + env: + working-directory: "role-manager" + steps: + - uses: actions/checkout@v2 + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: Build Project + run: cargo build --release + working-directory: ${{ env.working-directory }} + - name: Run Project + run: cargo run --release -- -h + working-directory: ${{ env.working-directory }} \ No newline at end of file diff --git a/.github/workflows/criterion-test.yml b/.github/workflows/criterion-test.yml deleted file mode 100644 index 428d1411..00000000 --- a/.github/workflows/criterion-test.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Criterion Unit Tests - -on: - push: - branches: - - '**' - pull_request: - branches: [ main ] - -jobs: - build: - runs-on: ubuntu-latest - - env: - TEST: 1 - DEBUG: 1 - COV: 1 - - steps: - - uses: actions/checkout@v2 - - - name: Update version - run: sudo apt-get update - - name: Install Dependencies - run: sudo -E ./configure.sh - - name: Build Unit Tests - run: make -e build_unit_test - - name: Run Unit Tests - run: ./bin/unit_test - - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - with: - gcov: true \ No newline at end of file diff --git a/.github/workflows/codacy.yml b/.github/workflows/quality.yml similarity index 58% rename from .github/workflows/codacy.yml rename to .github/workflows/quality.yml index 2260a3c1..c54faf4a 100644 --- a/.github/workflows/codacy.yml +++ b/.github/workflows/quality.yml @@ -60,3 +60,64 @@ jobs: uses: github/codeql-action/upload-sarif@v2 with: sarif_file: results.sarif + rust-quality-gate: + name: Rust Quality Gate + env: + working-directory: "role-manager" + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Build code + run: cargo build --all --release + working-directory: ${{ env.working-directory }} + + - name: Format code with Rustfmt + run: cargo fmt --all -- --check + working-directory: ${{ env.working-directory }} + continue-on-error: true + id: rustfmt + + - name: Run Clippy + run: cargo clippy --all -- -D warnings + working-directory: ${{ env.working-directory }} + continue-on-error: true + id: clippy + + - name: Check errors and set workflow status + run: | + if [[ ${{ steps.rustfmt.outcome }} == 'failure' ]]; then + echo "Error: Rustfmt failed." + exit 1 + fi + if [[ ${{ steps.clippy.outcome }} == 'failure' ]]; then + echo "Error: Clippy failed." + exit 1 + fi + if: ${{ always() }} + rust-security: + name: Rust Security Gate + env: + working-directory: "role-manager" + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Cargo audit + run: cargo audit --json | tee cargo-audit.json + working-directory: ${{ env.working-directory }} + id: cargo-audit \ No newline at end of file diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index c4bdef3a..00000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,67 +0,0 @@ -name: Rust Code Quality - -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - - name: Build code - run: cargo build --all --release - working-directory: role-manager - continue-on-error: true - id: rsbuild - - - name: Format code with Rustfmt - run: cargo fmt --all -- --check - working-directory: role-manager - continue-on-error: true - id: rustfmt - - - name: Run Clippy - run: cargo clippy --all -- -D warnings - working-directory: role-manager - continue-on-error: true - id: clippy - - - name: Build and run tests - run: cargo test --all - working-directory: role-manager - continue-on-error: true - id: tests - - - name: Check errors and set workflow status - run: | - if [[ ${{ steps.rsbuild.outcome }} == 'failure' ]]; then - echo "Error: Rustfmt failed." - exit 1 - fi - if [[ ${{ steps.rustfmt.outcome }} == 'failure' ]]; then - echo "Error: Rustfmt failed." - exit 1 - fi - if [[ ${{ steps.clippy.outcome }} == 'failure' ]]; then - echo "Error: Clippy failed." - exit 1 - fi - if [[ ${{ steps.tests.outcome }} == 'failure' ]]; then - echo "Error: Tests failed." - exit 1 - fi - if: ${{ always() }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..ffcf59fa --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,80 @@ +name: Criterion Unit Tests + +on: + push: + branches: + - '**' + pull_request: + branches: [ main ] + +jobs: + criterion: + runs-on: ubuntu-latest + + env: + TEST: 1 + DEBUG: 1 + COV: 1 + + steps: + - uses: actions/checkout@v2 + + - name: Update version + run: sudo apt-get update + - name: Install Dependencies + run: sudo -E ./configure.sh + - name: Build Unit Tests + run: make -e build_unit_test + - name: Run Unit Tests + run: ./bin/unit_test + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + with: + gcov: true + rust-coverage: + runs-on: ubuntu-latest + env: + working-directory: role-manager + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Install grcov + working-directory: ${{ env.working-directory }} + run: cargo install grcov + + - name: Install llvm-tools-preview + working-directory: ${{ env.working-directory }} + run: rustup component add llvm-tools-preview + + - name: Build project + working-directory: ${{ env.working-directory }} + run: cargo build + + - name: run tests with coverage + working-directory: ${{ env.working-directory }} + run: cargo test + env: + CARGO_INCREMENTAL: 0 + RUSTFLAGS: '-Cinstrument-coverage' + LLVM_PROFILE_FILE: 'cargo-test-%p-%m.profraw' + + - name: generate report + working-directory: ${{ env.working-directory }} + run: grcov . --binary-path ./target/debug/deps/ -s . -t lcov --branch --ignore-not-existing --ignore '../*' --ignore "/*" -o target/debug/role-manager.lcov + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + with: + file: role-manager/target/debug/role-manager.lcov + flags: unittests