Skip to content

Commit 41dd23b

Browse files
authored
Restore coverage CI workflow job but using grcov (#1259)
Adds 'coverage' makefile rule to generate coverage reports using grcov. Adds coverage and editor temp file patterns to .gitingore. --------- Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
1 parent d714ac1 commit 41dd23b

File tree

5 files changed

+114
-5
lines changed

5 files changed

+114
-5
lines changed

.github/workflows/coverage.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
on:
2+
pull_request:
3+
paths:
4+
# Only run coverage report if the sources have changed
5+
- "src/**.rs"
6+
- "crates/**.rs"
7+
push:
8+
branches:
9+
- main
10+
paths:
11+
# Only run coverage report if the sources have changed
12+
- "src/**.rs"
13+
- "crates/**.rs"
14+
15+
name: Code Coverage
16+
jobs:
17+
codecov:
18+
runs-on: ubuntu-latest
19+
container:
20+
image: rust:slim-bookworm
21+
options: --security-opt seccomp=unconfined --privileged
22+
env:
23+
SPFS_SUPPRESS_OVERLAYFS_PARAMS_WARNING: "1"
24+
steps:
25+
- name: Cancel Previous Runs
26+
uses: styfle/cancel-workflow-action@0.11.0
27+
- name: Setup spfs repos
28+
run: |
29+
mkdir /spfs
30+
mkdir -p /tmp/spfs-repos/local
31+
mkdir -p /tmp/spfs-repos/origin
32+
cat >/etc/spfs.conf << EOF
33+
[storage]
34+
root = /tmp/spfs-repos/local
35+
36+
[remote.origin]
37+
address = file:///tmp/spfs-repos/origin?create=true
38+
EOF
39+
- name: Install prerequisites
40+
run: |
41+
apt-get update
42+
apt-get install --yes build-essential libcap2-bin sudo cmake tcsh rsync protobuf-compiler fuse libfuse-dev curl unzip pkg-config libssl-dev git
43+
# spfs-fuse requires this option enabled
44+
echo user_allow_other >> /etc/fuse.conf
45+
FB_REL=https://github.com/google/flatbuffers/releases/
46+
curl --proto '=https' --tlsv1.2 -sSfL ${FB_REL}/download/v23.5.26/Linux.flatc.binary.g++-10.zip | funzip > /usr/bin/flatc
47+
chmod +x /usr/bin/flatc
48+
- uses: actions/checkout@v3
49+
- name: Install ast-grep
50+
run: cargo install --locked --force ast-grep
51+
- name: Install llvm-tools and grcov
52+
run: |
53+
# set up the profiling requirements
54+
rustup component add llvm-tools
55+
cargo install grcov
56+
- name: Configure cargo
57+
run: |
58+
mkdir -p .cargo
59+
cat << EOF > .cargo/config.toml
60+
[build]
61+
# Disable incremental compilation to lower disk usage, and sccache
62+
# can't cache incremental compiles.
63+
incremental = false
64+
65+
[profile.dev]
66+
# Disable debug information to lower disk usage.
67+
debug = false
68+
EOF
69+
- name: Install spfs
70+
run: |
71+
make install-debug-spfs FEATURES=server,spfs/server
72+
cargo clean
73+
- name: Generate code coverage
74+
run: |
75+
# Originally used tarpaulin but it used too much space to generate
76+
make coverage FEATURES=server,spfs/server,spfs/protobuf-src,spk/migration-to-components,sentry,statsd,fuse-backend,spfs-vfs/protobuf-src
77+
- name: Upload to codecov.io
78+
uses: codecov/codecov-action@v3
79+
- name: Code coverage summary report in logs
80+
uses: irongut/CodeCoverageSummary@v1.3.0
81+
with:
82+
output: both
83+
format: markdown
84+
filename: target/debug/coverage/cobertura.xml

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ coverage.xml
33
.benchmarks
44
.coverage
55
.coverage.*
6+
profraw
67

78
# spdev
89
/build/
@@ -16,6 +17,7 @@ dist/
1617
# editors
1718
.idea/
1819
.vscode/
20+
*~
1921
.nfs*
2022
.secrets
2123
# GENERATED FOR spdev:Shell

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,20 @@ rpm-buildenv:
126126
--cache-from build_env \
127127
-f rpmbuild.Dockerfile \
128128
--tag build_env
129+
130+
.PHONY: coverage
131+
coverage: FEATURES?=server,spfs/server,spfs/protobuf-src,spk/migration-to-components,sentry,statsd,fuse-backend,spfs-vfs/protobuf-src
132+
coverage:
133+
# Generate a coverage reports (html, lcov) using grcov, requires:
134+
# - cargo install grcov
135+
# - rustup component add llvm-tools
136+
# The html report can be viewed from: target/debug/coverage/index.html
137+
echo "coverage started, about to make dir 1"
138+
mkdir -p profraw
139+
echo "coverage made dir 1, about to make dir 2"
140+
mkdir -p target/debug/coverage
141+
echo "coverage made dir 2, about to run cargo test"
142+
RUSTFLAGS='-C instrument-coverage' LLVM_PROFILE_FILE='profraw/spk-%p-%m.profraw' spfs run - -- cargo test --workspace --features ${FEATURES} 2>&1
143+
echo "coverage cargo test run, about to run grcov"
144+
grcov . -s . --binary-path ./target/debug/ --branch --ignore-not-existing --keep-only 'crates/*' -t lcov,cobertura -o ./target/debug/coverage/
145+
echo "coverage finished"

crates/spk-cli/common/src/flags.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,13 @@ impl Runtime {
9696
self.edit
9797
}
9898

99-
/// Unless `--no-runtime` is present, relaunch the current process inside
100-
/// a new spfs runtime.
99+
/// Unless `--no-runtime` is present, relaunch the current process
100+
/// inside a new spfs runtime.
101101
///
102-
/// The caller is expected to pass in a list of subcommand aliases that can
103-
/// be used to find an appropriate place on the command line to insert a
104-
/// `--no-runtime` argument, to avoid recursively creating a runtime.
102+
/// The caller is expected to pass in a list of subcommand aliases
103+
/// that can be used to find an appropriate place on the command
104+
/// line to insert a `--no-runtime` argument, to avoid recursively
105+
/// creating a runtime.
105106
pub async fn ensure_active_runtime(
106107
&self,
107108
sub_command_aliases: &[&str],

cspell.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"cmpt",
9292
"cmpts",
9393
"cnproc",
94+
"cobertura",
9495
"codegen",
9596
"colour",
9697
"compat",
@@ -139,6 +140,7 @@
139140
"derserializer",
140141
"deserializing",
141142
"DESTDIR",
143+
"devcontainer",
142144
"devel",
143145
"DEVNULL",
144146
"devs",
@@ -283,6 +285,7 @@
283285
"gnupress",
284286
"goldmark",
285287
"gperf",
288+
"grcov",
286289
"Grav",
287290
"Gritz",
288291
"GVTA",
@@ -530,6 +533,7 @@
530533
"perror",
531534
"persistable",
532535
"pids",
536+
"Pipenv",
533537
"Pinnable",
534538
"pixbuf",
535539
"PJDUUENJYFFDKZWRKHDUXK4FGGZ7FHDYMZ7P4CXORUG6TUMDJ7A",
@@ -554,6 +558,7 @@
554558
"printenv",
555559
"privs",
556560
"PROCESSENTRY",
561+
"profraw",
557562
"projecs",
558563
"proptest",
559564
"prost",

0 commit comments

Comments
 (0)