Skip to content

Commit 6e26d50

Browse files
authored
CI starter (#5)
Added CI
1 parent 39ef37d commit 6e26d50

File tree

4 files changed

+132
-2
lines changed

4 files changed

+132
-2
lines changed

.github/workflows/ci.yml

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: CI
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
RUST_LOG: info
10+
RUST_BACKTRACE: 1
11+
12+
jobs:
13+
test-versions:
14+
name: Test Rust ${{ matrix.rust }}
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
rust: [stable, beta, nightly]
20+
steps:
21+
- uses: actions/checkout@v2
22+
- uses: hecrj/setup-rust-action@v1
23+
with:
24+
rust-version: ${{ matrix.rust }}
25+
- run: cargo test --verbose --workspace
26+
cargo-check:
27+
name: Check for warnings
28+
runs-on: ubuntu-latest
29+
env:
30+
RUSTFLAGS: -Dwarnings
31+
steps:
32+
- uses: actions/checkout@v2
33+
- uses: hecrj/setup-rust-action@v1
34+
- run: cargo check --workspace --all-targets --verbose
35+
clippy:
36+
name: Lint with Clippy
37+
runs-on: ubuntu-latest
38+
env:
39+
RUSTFLAGS: -Dwarnings
40+
steps:
41+
- uses: actions/checkout@v2
42+
- uses: hecrj/setup-rust-action@v1
43+
with:
44+
components: clippy
45+
- run: cargo clippy --workspace --all-targets --verbose
46+
rustfmt:
47+
name: Verify code formatting
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v2
51+
- uses: hecrj/setup-rust-action@v1
52+
with:
53+
components: rustfmt
54+
- run: cargo fmt --all -- --check
55+
check-rustdoc-links:
56+
name: Check intra-doc links
57+
runs-on: ubuntu-latest
58+
steps:
59+
- uses: actions/checkout@v2
60+
- uses: hecrj/setup-rust-action@v1
61+
with:
62+
rust-version: nightly
63+
- run: cargo rustdoc -- -D warnings
64+
# code-coverage:
65+
# name: Run code coverage
66+
# runs-on: ubuntu-latest
67+
# env:
68+
# RUSTFLAGS: -Zinstrument-coverage
69+
# steps:
70+
# - uses: actions/checkout@v2
71+
# - uses: hecrj/setup-rust-action@v1
72+
# with:
73+
# rust-version: nightly
74+
# - name: Cache LLVM and Clang
75+
# id: cache-llvm
76+
# uses: actions/cache@v2
77+
# with:
78+
# path: ${{ runner.temp }}/llvm
79+
# key: llvm-10.0
80+
# - name: Install LLVM and Clang
81+
# uses: KyleMayes/install-llvm-action@v1
82+
# with:
83+
# version: "10.0"
84+
# directory: ${{ runner.temp }}/llvm
85+
# cached: ${{ steps.cache-llvm.outputs.cache-hit }}
86+
# - run: sudo apt-get install -y libtinfo-dev libtinfo5 build-essential
87+
# - run: wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
88+
# - run: cargo install rustfilt
89+
# - run: echo "PATH=/home/runner/.cargo/bin:$PATH" >> $GITHUB_ENV
90+
# - run: ./codecov.sh --check

codecov.sh

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
set +xe
4+
5+
REQUIRED=100
6+
7+
cargo clean
8+
RUSTFLAGS="-Zinstrument-coverage" cargo test --lib --no-run
9+
tests="target/debug/deps/$(ls target/debug/deps | grep -e "^simrs-[a-z0-9]*$")"
10+
$tests
11+
cat default.profraw > all.profraw
12+
13+
RUSTFLAGS="-Zinstrument-coverage" cargo build --examples
14+
objects=""
15+
examples="$(ls target/debug/examples | grep -e ".*-[a-z0-9]*$")"
16+
for example in $examples; do
17+
./target/debug/examples/$example 2>&1 > /dev/null
18+
objects="$objects -object ./target/debug/examples/$example"
19+
cat default.profraw >> all.profraw
20+
done
21+
22+
llvm-profdata merge -sparse all.profraw -o default.profdata
23+
if ! [[ $1 = "--check" ]]; then
24+
llvm-cov report -Xdemangler=rustfilt $tests $objects -instr-profile=default.profdata
25+
llvm-cov show -Xdemangler=rustfilt $tests $objects -instr-profile=default.profdata \
26+
-show-line-counts-or-regions \
27+
-format=html > cov.html
28+
else
29+
llvm-cov export -Xdemangler=rustfilt $tests $objects -instr-profile=default.profdata \
30+
> lcov.json
31+
percent=$(jq '.data[].totals.lines.percent' lcov.json)
32+
if (( percent < $REQUIRED )); then
33+
echo "Required ${REQUIRED}% line coverage. Coverage detected: $percent"
34+
exit 1
35+
else
36+
echo "Success!"
37+
fi
38+
fi

examples/simulation.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ impl Component for Consumer {
7777
ConsumerEvent::Received => {
7878
if busy {
7979
if let Some(product) = state.recv(self.incoming) {
80-
state.get_mut(self.working_on).map(|w| *w = Some(product));
80+
if let Some(w) = state.get_mut(self.working_on) {
81+
*w = Some(product);
82+
}
8183
scheduler.schedule(self.interval(), self_id, ConsumerEvent::Finished);
8284
}
8385
}

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl Simulation {
348348

349349
/// Runs the entire simulation from start to end.
350350
/// This function might not terminate if the end condition is not satisfied.
351-
pub fn run<F: Fn(&Simulation) -> ()>(&mut self, step_function: F) {
351+
pub fn run<F: Fn(&Simulation)>(&mut self, step_function: F) {
352352
while self.step() {
353353
step_function(self)
354354
}

0 commit comments

Comments
 (0)