From 1834f988033bcaee1538172fd0ad0e9f868ef3b0 Mon Sep 17 00:00:00 2001 From: Brad Edwards Date: Thu, 2 Jan 2025 07:36:13 +0000 Subject: [PATCH 1/3] Add CI/CD workflow for unit tests and coverage check --- .github/workflows/ci.yml | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..20212de --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,43 @@ + +name: CI/CD + +on: + push: + branches: + - chore/basic-ci-cd + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: Install dependencies + run: sudo apt-get install lcov + - name: Run tests + run: | + cargo test --manifest-path crates/cs/Cargo.toml + - name: Generate coverage report + run: | + cargo install cargo-tarpaulin + cargo tarpaulin --out Xml --manifest-path crates/cs/Cargo.toml + - name: Check coverage + run: | + bash <(curl -s https://codecov.io/bash) -f lcov.info + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + - name: Fail if coverage is below 90% + run: | + bash <(curl -s https://codecov.io/bash) -f lcov.info + if [ $(lcov --summary lcov.info | grep -Eo '[0-9]+\.[0-9]+' | head -1) -lt 90 ]; then + echo "Coverage is below 90%"; + exit 1; + fi From ea9c38019c7012f1b3f404c12e821c188a265449 Mon Sep 17 00:00:00 2001 From: Brad Edwards Date: Thu, 2 Jan 2025 07:49:51 +0000 Subject: [PATCH 2/3] Switch to cargo-llvm-cov for coverage reporting --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 20212de..5d9aeee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,8 +27,8 @@ jobs: cargo test --manifest-path crates/cs/Cargo.toml - name: Generate coverage report run: | - cargo install cargo-tarpaulin - cargo tarpaulin --out Xml --manifest-path crates/cs/Cargo.toml + cargo install cargo-llvm-cov + cargo llvm-cov --manifest-path crates/cs/blocks-cs-core/Cargo.toml --lcov --output-path lcov.info - name: Check coverage run: | bash <(curl -s https://codecov.io/bash) -f lcov.info From 05e0d65db2a5c1dbdff78e09a9b3ab5b2e98a085 Mon Sep 17 00:00:00 2001 From: Brad Edwards Date: Thu, 2 Jan 2025 08:41:26 +0000 Subject: [PATCH 3/3] Update workflow to test all crates in crates/cs --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d9aeee..03cdcdd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,10 @@ jobs: - name: Generate coverage report run: | cargo install cargo-llvm-cov - cargo llvm-cov --manifest-path crates/cs/blocks-cs-core/Cargo.toml --lcov --output-path lcov.info + for toml in $(find crates/cs -name "Cargo.toml"); do + echo "Running tests for $toml" + cargo llvm-cov --manifest-path $toml --lcov --output-path lcov.info + done - name: Check coverage run: | bash <(curl -s https://codecov.io/bash) -f lcov.info