Add a code coverage check to the CI pipeline (#84)
Closes #83 Reviewed-on: #84
This commit is contained in:
parent
26f0ccd842
commit
d7384476d4
@ -1,6 +1,12 @@
|
|||||||
FROM docker.io/library/rust:1.75
|
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 \
|
RUN apt-get update && apt-get install -y \
|
||||||
beets \
|
beets \
|
||||||
|
23
.gitea/scripts/coverage.py
Normal file
23
.gitea/scripts/coverage.py
Normal file
@ -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)
|
@ -8,21 +8,40 @@ on:
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
BEETSDIR: ./
|
CARGO_TERM_VERBOSE: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build_and_test:
|
build_and_test:
|
||||||
name: Build and Test
|
name: Build and Test
|
||||||
container: docker.io/drrobot/musichoard-ci:rust-1.75
|
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:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- run: cargo build --verbose --all-features --all-targets
|
- run: cargo build --all-features --all-targets
|
||||||
- run: cargo test --verbose --all-features --all-targets --no-fail-fast
|
- 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/
|
||||||
|
- run: >-
|
||||||
|
python3 .gitea/scripts/coverage.py
|
||||||
|
--coverage-file ./target/debug/coverage/coverage.json
|
||||||
|
--fail-under 100.00
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
name: Lint
|
name: Lint
|
||||||
container: docker.io/drrobot/musichoard-ci:rust-1.75
|
container: docker.io/drrobot/musichoard-ci:rust-1.75
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- run: cargo clippy --verbose --all-features --all-targets -- -D warnings
|
- run: cargo clippy --all-features --all-targets -- -D warnings
|
||||||
- run: cargo fmt --verbose -- --check
|
- run: cargo fmt -- --check
|
||||||
|
@ -23,6 +23,7 @@ env CARGO_TARGET_DIR=codecov \
|
|||||||
env RUSTFLAGS="-C instrument-coverage" \
|
env RUSTFLAGS="-C instrument-coverage" \
|
||||||
LLVM_PROFILE_FILE="codecov/debug/profraw/musichoard-%p-%m.profraw" \
|
LLVM_PROFILE_FILE="codecov/debug/profraw/musichoard-%p-%m.profraw" \
|
||||||
CARGO_TARGET_DIR=codecov \
|
CARGO_TARGET_DIR=codecov \
|
||||||
|
BEETSDIR=./ \
|
||||||
cargo test --all-features --all-targets
|
cargo test --all-features --all-targets
|
||||||
grcov codecov/debug/profraw \
|
grcov codecov/debug/profraw \
|
||||||
--binary-path ./codecov/debug/ \
|
--binary-path ./codecov/debug/ \
|
||||||
@ -31,7 +32,7 @@ grcov codecov/debug/profraw \
|
|||||||
--ignore-not-existing \
|
--ignore-not-existing \
|
||||||
--ignore "tests/*" \
|
--ignore "tests/*" \
|
||||||
--ignore "src/main.rs" \
|
--ignore "src/main.rs" \
|
||||||
--excl-start "mod tests \{|GRCOV_EXCL_START" \
|
--excl-start "GRCOV_EXCL_START|mod tests \{" \
|
||||||
--excl-stop "GRCOV_EXCL_STOP" \
|
--excl-stop "GRCOV_EXCL_STOP" \
|
||||||
--output-path ./codecov/debug/coverage/
|
--output-path ./codecov/debug/coverage/
|
||||||
xdg-open codecov/debug/coverage/index.html
|
xdg-open codecov/debug/coverage/index.html
|
||||||
|
Loading…
Reference in New Issue
Block a user