From 8832c3a39936de3f351a68846176c352a5a4d9cc Mon Sep 17 00:00:00 2001 From: Sylwester Fraczek Date: Wed, 6 Mar 2024 16:07:53 +0100 Subject: [PATCH 1/7] create coverage.yaml --- .github/workflows/building.yaml | 2 +- .github/workflows/coverage.yaml | 63 +++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/coverage.yaml diff --git a/.github/workflows/building.yaml b/.github/workflows/building.yaml index e197659..750a71e 100644 --- a/.github/workflows/building.yaml +++ b/.github/workflows/building.yaml @@ -14,7 +14,7 @@ jobs: profile: minimal toolchain: stable override: true - - run: rustup component add rustfmt + components: rustfmt - uses: actions-rs/cargo@v1 with: command: fmt diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml new file mode 100644 index 0000000..0443ae7 --- /dev/null +++ b/.github/workflows/coverage.yaml @@ -0,0 +1,63 @@ +on: [pull_request] + +name: Code Coverage + +jobs: + coverage: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + components: llvm-tools-preview + + - name: Install grcov + uses: actions-rs/cargo@v1 + with: + command: install + args: grcov + + - name: Build project + - uses: actions-rs/cargo@v1 + with: + command: build + env: + RUSTFLAGS: "-C instrument-coverage" + + - name: Run tests for coverage + uses: actions-rs/cargo@v1 + with: + command: test + env: + LLVM_PROFILE_FILE: profile-%p-%m.profraw + + - name: Generate coverage html report + run: grcov . -s . --binary-path ./target/debug -t html --branch --ignore-not-existing -o ./coverage/ + + - name: Upload coverage html report + uses: actions/upload-artifact@v2 + with: + name: coverage-html-report + path: coverage/ + + + - name: Generate coverage lcov report + run: grcov . -s . --binary-path ./target/debug -t md --branch --ignore-not-existing -o coverage.md + + - name: Check coverage percentage + run: | + COVERAGE_PERCENTAGE=$(tail -n 1 coverage.md | grep -oP '(\d+(\.\d+)?)(?=%)') + echo "Coverage percentage is $COVERAGE_PERCENTAGE%" + if (( $(echo "$COVERAGE_PERCENTAGE < $COVERAGE_THRESHOLD" | bc -l) )); then + echo "Code coverage is below $COVERAGE_THRESHOLD%. Failing the workflow." + exit 1 + fi + env: + COVERAGE_THRESHOLD: 90 From b7797fe24ea919e55cd7f637083f411ccd51f076 Mon Sep 17 00:00:00 2001 From: Sylwester Fraczek Date: Wed, 6 Mar 2024 16:43:44 +0100 Subject: [PATCH 2/7] fix --- .github/workflows/coverage.yaml | 120 ++++++++++++++++---------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 0443ae7..c8df94f 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -1,63 +1,63 @@ -on: [pull_request] - name: Code Coverage +on: [pull_request] + jobs: - coverage: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - components: llvm-tools-preview - - - name: Install grcov - uses: actions-rs/cargo@v1 - with: - command: install - args: grcov - - - name: Build project - - uses: actions-rs/cargo@v1 - with: - command: build - env: - RUSTFLAGS: "-C instrument-coverage" - - - name: Run tests for coverage - uses: actions-rs/cargo@v1 - with: - command: test - env: - LLVM_PROFILE_FILE: profile-%p-%m.profraw - - - name: Generate coverage html report - run: grcov . -s . --binary-path ./target/debug -t html --branch --ignore-not-existing -o ./coverage/ - - - name: Upload coverage html report - uses: actions/upload-artifact@v2 - with: - name: coverage-html-report - path: coverage/ - - - - name: Generate coverage lcov report - run: grcov . -s . --binary-path ./target/debug -t md --branch --ignore-not-existing -o coverage.md - - - name: Check coverage percentage - run: | - COVERAGE_PERCENTAGE=$(tail -n 1 coverage.md | grep -oP '(\d+(\.\d+)?)(?=%)') - echo "Coverage percentage is $COVERAGE_PERCENTAGE%" - if (( $(echo "$COVERAGE_PERCENTAGE < $COVERAGE_THRESHOLD" | bc -l) )); then - echo "Code coverage is below $COVERAGE_THRESHOLD%. Failing the workflow." - exit 1 - fi - env: - COVERAGE_THRESHOLD: 90 + coverage: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + components: llvm-tools-preview + + - name: Install grcov + uses: actions-rs/cargo@v1 + with: + command: install + args: grcov + + - name: Build project + - uses: actions-rs/cargo@v1 + with: + command: build + env: + RUSTFLAGS: "-C instrument-coverage" + + - name: Run tests for coverage + uses: actions-rs/cargo@v1 + with: + command: test + env: + LLVM_PROFILE_FILE: profile-%p-%m.profraw + + - name: Generate coverage html report + run: grcov . -s . --binary-path ./target/debug -t html --branch --ignore-not-existing --ignore "/*" -o ./coverage/ + + - name: Upload coverage html report + uses: actions/upload-artifact@v4 + with: + name: coverage-html-report + path: coverage/ + + + - name: Generate coverage lcov report + run: grcov . -s . --binary-path ./target/debug -t md --branch --ignore-not-existing --ignore "/*" -o coverage.md + + - name: Check coverage percentage + run: | + COVERAGE_PERCENTAGE=$(tail -n 1 coverage.md | grep -oP '(\d+(\.\d+)?)(?=%)') + echo "Coverage percentage is $COVERAGE_PERCENTAGE%" + if (( $(echo "$COVERAGE_PERCENTAGE < $COVERAGE_THRESHOLD" | bc -l) )); then + echo "Code coverage is below $COVERAGE_THRESHOLD%. Failing the workflow." + exit 1 + fi + env: + COVERAGE_THRESHOLD: 90 From c243fc23715111f2d771ea99215666df64af2c55 Mon Sep 17 00:00:00 2001 From: Sylwester Fraczek Date: Wed, 6 Mar 2024 16:48:04 +0100 Subject: [PATCH 3/7] fixup --- .github/workflows/coverage.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index c8df94f..89b80fd 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -25,7 +25,7 @@ jobs: args: grcov - name: Build project - - uses: actions-rs/cargo@v1 + uses: actions-rs/cargo@v1 with: command: build env: From 1139f0c04ac2cd9d7c77aedf5f1799df3f4ce371 Mon Sep 17 00:00:00 2001 From: Sylwester Fraczek Date: Wed, 6 Mar 2024 16:57:10 +0100 Subject: [PATCH 4/7] add installing dependencies --- .github/workflows/coverage.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 89b80fd..7f799c1 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -7,6 +7,11 @@ jobs: runs-on: ubuntu-latest steps: + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y libx11-dev libxext-dev libxft-dev libxinerama-dev libxcursor-dev libxrender-dev libxfixes-dev libpango1.0-dev + - name: Checkout repository uses: actions/checkout@v4 From 5ff430a91d27dc956a550d32e6d2cffd4b7a47f1 Mon Sep 17 00:00:00 2001 From: Sylwester Fraczek Date: Wed, 6 Mar 2024 17:05:07 +0100 Subject: [PATCH 5/7] speedup by removing build step and fix md->markdown --- .github/workflows/coverage.yaml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 7f799c1..66fea40 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -27,14 +27,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: install - args: grcov - - - name: Build project - uses: actions-rs/cargo@v1 - with: - command: build - env: - RUSTFLAGS: "-C instrument-coverage" + args: grcov - name: Run tests for coverage uses: actions-rs/cargo@v1 @@ -42,6 +35,7 @@ jobs: command: test env: LLVM_PROFILE_FILE: profile-%p-%m.profraw + RUSTFLAGS: "-C instrument-coverage" - name: Generate coverage html report run: grcov . -s . --binary-path ./target/debug -t html --branch --ignore-not-existing --ignore "/*" -o ./coverage/ @@ -54,7 +48,7 @@ jobs: - name: Generate coverage lcov report - run: grcov . -s . --binary-path ./target/debug -t md --branch --ignore-not-existing --ignore "/*" -o coverage.md + run: grcov . -s . --binary-path ./target/debug -t markdown --branch --ignore-not-existing --ignore "/*" -o coverage.md - name: Check coverage percentage run: | From 4f707eeee78cf1651abb1a6cd5f7b90bf0d27225 Mon Sep 17 00:00:00 2001 From: Sylwester Fraczek Date: Wed, 6 Mar 2024 17:06:06 +0100 Subject: [PATCH 6/7] remove empty line --- .github/workflows/coverage.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 66fea40..1a99fc2 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -46,7 +46,6 @@ jobs: name: coverage-html-report path: coverage/ - - name: Generate coverage lcov report run: grcov . -s . --binary-path ./target/debug -t markdown --branch --ignore-not-existing --ignore "/*" -o coverage.md From 6e9d63edff33d9638b564f760541f4db4b83b201 Mon Sep 17 00:00:00 2001 From: Sylwester Fraczek Date: Wed, 6 Mar 2024 17:12:22 +0100 Subject: [PATCH 7/7] set coverage threshold to 65 --- .github/workflows/coverage.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 1a99fc2..dc913d5 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -58,4 +58,4 @@ jobs: exit 1 fi env: - COVERAGE_THRESHOLD: 90 + COVERAGE_THRESHOLD: 65