From 73bd7c1514e4a14730fd8c823d7637497db3d338 Mon Sep 17 00:00:00 2001 From: epi Date: Sun, 4 Oct 2020 06:14:25 -0500 Subject: [PATCH] added codecov to CI pipeline --- .github/actions-rs/grcov.yml | 7 +++ .github/workflows/{rust-ci.yml => build.yml} | 66 -------------------- .github/workflows/check.yml | 64 +++++++++++++++++++ .github/workflows/coverage.yml | 36 +++++++++++ src/lib.rs | 7 ++- tests/test_banner.rs | 6 +- tests/test_main.rs | 18 +++--- 7 files changed, 124 insertions(+), 80 deletions(-) create mode 100644 .github/actions-rs/grcov.yml rename .github/workflows/{rust-ci.yml => build.yml} (68%) create mode 100644 .github/workflows/check.yml create mode 100644 .github/workflows/coverage.yml diff --git a/.github/actions-rs/grcov.yml b/.github/actions-rs/grcov.yml new file mode 100644 index 0000000..e28a884 --- /dev/null +++ b/.github/actions-rs/grcov.yml @@ -0,0 +1,7 @@ +branch: true +ignore-not-existing: true +llvm: true +output-type: lcov +output-path: ./lcov.info +ignore: + - "../*" diff --git a/.github/workflows/rust-ci.yml b/.github/workflows/build.yml similarity index 68% rename from .github/workflows/rust-ci.yml rename to .github/workflows/build.yml index 6ee18be..50b837c 100644 --- a/.github/workflows/rust-ci.yml +++ b/.github/workflows/build.yml @@ -1,69 +1,3 @@ -name: CI Pipeline - -on: [push] - -jobs: - check: - name: Check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - uses: actions-rs/cargo@v1 - with: - command: check - - test: - name: Test Suite - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - uses: actions-rs/cargo@v1 - with: - command: test - - fmt: - name: Rust fmt - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - run: rustup component add rustfmt - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check - - clippy: - name: Clippy - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - run: rustup component add clippy - - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --all-targets --all-features -- -D warnings -A clippy::unnecessary_unwrap - - build-nix: runs-on: ${{ matrix.os }} if: github.ref == 'refs/heads/master' diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..021a739 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,64 @@ +name: CI Pipeline + +on: [push] + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: actions-rs/cargo@v1 + with: + command: check + + test: + name: Test Suite + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: actions-rs/cargo@v1 + with: + command: test + + fmt: + name: Rust fmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - run: rustup component add rustfmt + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - run: rustup component add clippy + - uses: actions-rs/cargo@v1 + with: + command: clippy + args: --all-targets --all-features -- -D warnings -A clippy::unnecessary_unwrap diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..d6d77c7 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,36 @@ +on: [push] + +name: Code Coverage + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + - uses: actions-rs/cargo@v1 + with: + command: clean + - uses: actions-rs/cargo@v1 + with: + command: test + args: --all-features --no-fail-fast + env: + CARGO_INCREMENTAL: '0' + RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' + RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' + - uses: actions-rs/grcov@v0.1 + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + run: | + curl -O https://raw.githubusercontent.com/eriwen/lcov-to-cobertura-xml/master/lcov_cobertura/lcov_cobertura.py + chmod +x lcov_cobertura.py + ./lcov_cobertura.py ./lcov.info + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.xml + name: codecov-umbrella + fail_ci_if_error: true diff --git a/src/lib.rs b/src/lib.rs index 3d728ff..c7138f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,7 +66,10 @@ mod tests { #[test] /// asserts default wordlist is correct fn default_wordlist() { - assert_eq!(DEFAULT_WORDLIST, "/usr/share/seclists/Discovery/Web-Content/raft-medium-directories.txt"); + assert_eq!( + DEFAULT_WORDLIST, + "/usr/share/seclists/Discovery/Web-Content/raft-medium-directories.txt" + ); } #[test] @@ -74,4 +77,4 @@ mod tests { fn default_version() { assert_eq!(VERSION, env!("CARGO_PKG_VERSION")); } -} \ No newline at end of file +} diff --git a/tests/test_banner.rs b/tests/test_banner.rs index 998f53b..6cf56ad 100644 --- a/tests/test_banner.rs +++ b/tests/test_banner.rs @@ -531,8 +531,8 @@ fn banner_doesnt_print() -> Result<(), Box> { .arg("-q") .assert() .failure() - .stderr( - predicate::str::contains("ERROR heuristics::connectivity_test Could not connect to any target provided") - ); + .stderr(predicate::str::contains( + "ERROR heuristics::connectivity_test Could not connect to any target provided", + )); Ok(()) } diff --git a/tests/test_main.rs b/tests/test_main.rs index ebb39dd..55982e9 100644 --- a/tests/test_main.rs +++ b/tests/test_main.rs @@ -1,12 +1,12 @@ -mod utils; -use httpmock::Method::GET; -use httpmock::{MockServer, Mock}; +pub mod utils; use assert_cmd::Command; +use httpmock::Method::GET; +use httpmock::{Mock, MockServer}; use predicates::prelude::*; #[test] -/// send the function a directory to execute error branch -fn main_use_directory_as_wordlist() -> Result<(), Box> { +/// send the function a file to which we dont have permission in order to execute error branch +fn main_use_root_owned_file_as_wordlist() -> Result<(), Box> { let srv = MockServer::start(); let mock = Mock::new() @@ -25,11 +25,11 @@ fn main_use_directory_as_wordlist() -> Result<(), Box> { .arg("-vvvv") .assert() .success() - .stderr( - predicate::str::contains("ERROR main::get_unique_words_from_wordlist Permission denied (os error 13)") - ); + .stderr(predicate::str::contains( + "ERROR main::get_unique_words_from_wordlist Permission denied (os error 13)", + )); // connectivity test hits it once assert_eq!(mock.times_called(), 1); Ok(()) -} \ No newline at end of file +}