From 56148039388921a0f6916d9c582999d27d26c3bc Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sat, 6 Jan 2024 17:48:55 +0100 Subject: [PATCH 1/5] Update README --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index acf805b..d9674e0 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ env CARGO_TARGET_DIR=codecov \ env RUSTFLAGS="-C instrument-coverage" \ LLVM_PROFILE_FILE="codecov/debug/profraw/musichoard-%p-%m.profraw" \ CARGO_TARGET_DIR=codecov \ + BEETSDIR=./ \ cargo test --all-features --all-targets grcov codecov/debug/profraw \ --binary-path ./codecov/debug/ \ @@ -31,7 +32,7 @@ grcov codecov/debug/profraw \ --ignore-not-existing \ --ignore "tests/*" \ --ignore "src/main.rs" \ - --excl-start "mod tests \{|GRCOV_EXCL_START" \ + --excl-start "GRCOV_EXCL_START|mod tests \{" \ --excl-stop "GRCOV_EXCL_STOP" \ --output-path ./codecov/debug/coverage/ xdg-open codecov/debug/coverage/index.html -- 2.45.2 From 12dbe5f23cbf7a63cac8702e51f67d0e8dc41f4b Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sat, 6 Jan 2024 18:26:59 +0100 Subject: [PATCH 2/5] Add code coverage to ci --- .gitea/images/Dockerfile | 8 +++++++- .gitea/scripts/coverage.py | 23 +++++++++++++++++++++++ .gitea/workflows/gitea-ci.yaml | 19 ++++++++++++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 .gitea/scripts/coverage.py diff --git a/.gitea/images/Dockerfile b/.gitea/images/Dockerfile index 027c47d..069c3de 100644 --- a/.gitea/images/Dockerfile +++ b/.gitea/images/Dockerfile @@ -1,6 +1,12 @@ FROM docker.io/library/rust:1.75 -RUN rustup component add clippy rustfmt +RUN rustup component add \ + clippy \ + llvm-tools-preview \ + rustfmt + +RUN cargo install \ + grcov RUN apt-get update && apt-get install -y \ beets \ diff --git a/.gitea/scripts/coverage.py b/.gitea/scripts/coverage.py new file mode 100644 index 0000000..944be8c --- /dev/null +++ b/.gitea/scripts/coverage.py @@ -0,0 +1,23 @@ +import argparse +import json + + +def main(coverage_file, fail_under): + with open(coverage_file, encoding="utf-8") as f: + coverage_json = json.load(f) + coverage = float(coverage_json["message"][:-1]) + return coverage >= fail_under + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Check coverage output by grcov") + + parser.add_argument("--coverage-file", type=str, required=True, + help="Path to the coverage.json file output by grcov") + parser.add_argument("--fail-under", type=float, default=100., + help="Threshold under which coverage is insufficient") + + args = parser.parse_args() + + if not main(args.coverage_file, args.fail_under): + exit(2) diff --git a/.gitea/workflows/gitea-ci.yaml b/.gitea/workflows/gitea-ci.yaml index 3c6a021..a7a9390 100644 --- a/.gitea/workflows/gitea-ci.yaml +++ b/.gitea/workflows/gitea-ci.yaml @@ -7,8 +7,10 @@ on: branches: [ main ] env: - CARGO_TERM_COLOR: always BEETSDIR: ./ + CARGO_TERM_COLOR: always + LLVM_PROFILE_FILE: target/debug/profraw/musichoard-%p-%m.profraw + RUSTFLAGS: -C instrument-coverage jobs: build_and_test: @@ -18,6 +20,21 @@ jobs: - uses: actions/checkout@v3 - run: cargo build --verbose --all-features --all-targets - run: cargo test --verbose --all-features --all-targets --no-fail-fast + - run: >- + grcov codecov/debug/profraw + --binary-path ./target/debug/ + --output-types html + --source-dir . + --ignore-not-existing + --ignore "tests/*" + --ignore "src/main.rs" + --excl-start "GRCOV_EXCL_START|mod tests \{" + --excl-stop "GRCOV_EXCL_STOP" + --output-path ./target/debug/coverage/ + - run: >- + python3 .gitea/scripts/coverage.py + --coverage-file ./target/debug/coverage/coverage.json + --fail-under 100.00 lint: name: Lint -- 2.45.2 From 842ed8abf7606359b7829946327e346722761f27 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sat, 6 Jan 2024 18:30:12 +0100 Subject: [PATCH 3/5] Fix grcov path --- .gitea/workflows/gitea-ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/gitea-ci.yaml b/.gitea/workflows/gitea-ci.yaml index a7a9390..66fd338 100644 --- a/.gitea/workflows/gitea-ci.yaml +++ b/.gitea/workflows/gitea-ci.yaml @@ -21,7 +21,7 @@ jobs: - run: cargo build --verbose --all-features --all-targets - run: cargo test --verbose --all-features --all-targets --no-fail-fast - run: >- - grcov codecov/debug/profraw + grcov target/debug/profraw --binary-path ./target/debug/ --output-types html --source-dir . -- 2.45.2 From d1eb08c7833856ff9af59ba5f556533cd103f94b Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sat, 6 Jan 2024 18:32:58 +0100 Subject: [PATCH 4/5] Clean up workflow file --- .gitea/workflows/gitea-ci.yaml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/gitea-ci.yaml b/.gitea/workflows/gitea-ci.yaml index 66fd338..1b5f26e 100644 --- a/.gitea/workflows/gitea-ci.yaml +++ b/.gitea/workflows/gitea-ci.yaml @@ -7,19 +7,21 @@ on: branches: [ main ] env: - BEETSDIR: ./ CARGO_TERM_COLOR: always - LLVM_PROFILE_FILE: target/debug/profraw/musichoard-%p-%m.profraw - RUSTFLAGS: -C instrument-coverage + CARGO_TERM_VERBOSE: true jobs: build_and_test: name: Build and Test container: docker.io/drrobot/musichoard-ci:rust-1.75 + env: + BEETSDIR: ./ + LLVM_PROFILE_FILE: target/debug/profraw/musichoard-%p-%m.profraw + RUSTFLAGS: -C instrument-coverage steps: - uses: actions/checkout@v3 - - run: cargo build --verbose --all-features --all-targets - - run: cargo test --verbose --all-features --all-targets --no-fail-fast + - run: cargo build --all-features --all-targets + - run: cargo test --all-features --all-targets --no-fail-fast - run: >- grcov target/debug/profraw --binary-path ./target/debug/ @@ -41,5 +43,5 @@ jobs: container: docker.io/drrobot/musichoard-ci:rust-1.75 steps: - uses: actions/checkout@v3 - - run: cargo clippy --verbose --all-features --all-targets -- -D warnings - - run: cargo fmt --verbose -- --check + - run: cargo clippy --all-features --all-targets -- -D warnings + - run: cargo fmt -- --check -- 2.45.2 From cbec032fbcf0ed0ca99eafff8a7dcd018e5bc093 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sat, 6 Jan 2024 19:04:11 +0100 Subject: [PATCH 5/5] Fix multiline commands --- .gitea/workflows/gitea-ci.yaml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.gitea/workflows/gitea-ci.yaml b/.gitea/workflows/gitea-ci.yaml index 1b5f26e..72c9002 100644 --- a/.gitea/workflows/gitea-ci.yaml +++ b/.gitea/workflows/gitea-ci.yaml @@ -24,19 +24,19 @@ jobs: - run: cargo test --all-features --all-targets --no-fail-fast - run: >- grcov target/debug/profraw - --binary-path ./target/debug/ - --output-types html - --source-dir . - --ignore-not-existing - --ignore "tests/*" - --ignore "src/main.rs" - --excl-start "GRCOV_EXCL_START|mod tests \{" - --excl-stop "GRCOV_EXCL_STOP" - --output-path ./target/debug/coverage/ + --binary-path target/debug/ + --output-types html + --source-dir . + --ignore-not-existing + --ignore "tests/*" + --ignore "src/main.rs" + --excl-start "GRCOV_EXCL_START|mod tests \{" + --excl-stop "GRCOV_EXCL_STOP" + --output-path ./target/debug/coverage/ - run: >- python3 .gitea/scripts/coverage.py - --coverage-file ./target/debug/coverage/coverage.json - --fail-under 100.00 + --coverage-file ./target/debug/coverage/coverage.json + --fail-under 100.00 lint: name: Lint -- 2.45.2