Skip to content

Commit

Permalink
Merge pull request #313 from systemaccounting/312-llvm-cov
Browse files Browse the repository at this point in the history
312 replace cargo tarpaulin with llvm-cov
  • Loading branch information
mxfactorial authored Nov 4, 2023
2 parents d4ad74f + 82262e9 commit 9d95528
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 32 deletions.
10 changes: 5 additions & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM mcr.microsoft.com/devcontainers/universal:2
ARG TF_VERSION=1.2.7
ARG MIGRATE_VERSION=4.15.2
ARG WATCH_VERSION=8.4.0
ARG TARPAULIN_VERSION=0.27.1
ARG CARGO_LLVM_COV_VERSION=0.5.36

RUN go install github.com/99designs/gqlgen@latest && \
go install github.com/golang/mock/mockgen@latest && \
Expand All @@ -21,10 +21,10 @@ RUN go install github.com/99designs/gqlgen@latest && \
tar -xf cargo-watch-v${WATCH_VERSION}-x86_64-unknown-linux-gnu.tar.xz && \
sudo mv cargo-watch-v${WATCH_VERSION}-x86_64-unknown-linux-gnu/cargo-watch /usr/local/bin && \
rm -rf cargo-watch-v${WATCH_VERSION}-x86_64-unknown-linux-gnu* && \
wget https://github.com/xd009642/tarpaulin/releases/download/${TARPAULIN_VERSION}/cargo-tarpaulin-x86_64-unknown-linux-gnu.tar.gz && \
tar -xf cargo-tarpaulin-x86_64-unknown-linux-gnu.tar.gz && \
sudo mv cargo-tarpaulin /usr/local/bin && \
rm -rf cargo-tarpaulin* && \
wget https://github.com/taiki-e/cargo-llvm-cov/releases/download/v${CARGO_LLVM_COV_VERSION}/cargo-llvm-cov-aarch64-unknown-linux-gnu.tar.gz && \
tar -xf cargo-llvm-cov-aarch64-unknown-linux-gnu.tar.gz && \
sudo mv cargo-llvm-cov /usr/local/bin && \
rm -rf cargo-llvm-cov* && \
npm install -g eslint && \
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' && \
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - && \
Expand Down
21 changes: 13 additions & 8 deletions .github/workflows/dev-crates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ jobs:
test:
name: crates
runs-on: ubuntu-latest
container:
image: xd009642/tarpaulin:develop-nightly
options: --security-opt seccomp=unconfined
env:
CI: true
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
Expand All @@ -28,6 +23,16 @@ jobs:
cargo fmt -- --check
cargo clippy -- -Dwarnings
working-directory: crates/types
- name: crates/types unit tests and coverage report
run: cargo tarpaulin --fail-under 95
working-directory: crates/types
- name: install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: crates/types unit tests
run: cargo test
working-directory: crates/types
- name: crates/types coverage report
run: make rust-coverage RUST_PKG=types
- name: fail crates/types coverage under 97%
run: |
if [[ $(make rust-coverage-percent RUST_PKG=types) -lt 97 ]]; then
echo 'coverage dropped below 97%'
exit 1
fi
26 changes: 18 additions & 8 deletions .github/workflows/dev-rule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ on:
push:
paths:
- 'services/rule/**'
- 'crates/**'
branches-ignore:
- 'master'
workflow_run:
workflows: [dev-crates]
types:
- completed

jobs:
test:
name: rule
runs-on: ubuntu-latest
container:
image: xd009642/tarpaulin:develop-nightly
options: --security-opt seccomp=unconfined
env:
CI: true
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
Expand All @@ -28,5 +26,17 @@ jobs:
run: |
cargo fmt -- --check
cargo clippy -- -Dwarnings
- name: unit tests and coverage
run: cargo tarpaulin
working-directory: services/rule
- name: install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: services/rule unit tests
run: cargo test
working-directory: services/rule
- name: services/rule coverage report
run: make rust-coverage RUST_PKG=rule
- name: fail services/rule coverage under 66%
run: |
if [[ $(make rust-coverage-percent RUST_PKG=rule) -lt 66 ]]; then
echo 'coverage dropped below 66%'
exit 1
fi
1 change: 0 additions & 1 deletion crates/types/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ impl AccountProfiles {
}

impl Default for AccountProfiles {
#[cfg(not(tarpaulin_include))]
fn default() -> Self {
Self::new()
}
Expand Down
2 changes: 0 additions & 2 deletions crates/types/src/account_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ impl<'a> FromSql<'a> for AccountRole {
}
}

#[cfg(not(tarpaulin_include))]
fn accepts(ty: &Type) -> bool {
*ty == Type::TEXT
}
Expand All @@ -44,7 +43,6 @@ impl ToSql for AccountRole {
}

#[allow(unused_variables)]
#[cfg(not(tarpaulin_include))]
fn accepts(ty: &Type) -> bool {
true
}
Expand Down
1 change: 0 additions & 1 deletion crates/types/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ impl FromIterator<RuleInstance> for RuleInstances {
}

impl Default for RuleInstances {
#[cfg(not(tarpaulin_include))]
fn default() -> Self {
Self::new()
}
Expand Down
3 changes: 1 addition & 2 deletions crates/types/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ mod tests {
const USEC_PER_SEC: i64 = 1_000_000;
test_buf.put_i64((1_698_641_816 - TIME_SEC_CONVERSION) * USEC_PER_SEC);
let got = TZTime::from_sql(&test_pg_type, &mut test_buf).unwrap();
let want_date = "2023-10-30T04:56:56Z";
let want = TZTime(
DateTime::parse_from_rfc3339(want_date)
DateTime::parse_from_rfc3339("2023-10-30T04:56:56Z")
.unwrap()
.with_timezone(&Utc),
);
Expand Down
3 changes: 2 additions & 1 deletion docker/.gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ RUN go install github.com/99designs/gqlgen@latest && \
unzip terraform_${TF_VERSION}_linux_amd64.zip && \
sudo mv terraform /usr/local/bin && \
rm terraform_${TF_VERSION}_linux_amd64.zip && \
rustup component add llvm-tools-preview --toolchain stable-x86_64-unknown-linux-gnu && \
cargo install cross --git https://github.com/cross-rs/cross && \
cargo install cargo-tarpaulin && \
cargo install cargo-llvm-cov && \
brew install libpq && \
brew link --force libpq && \
brew install golang-migrate && \
Expand Down
16 changes: 15 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ test-cloud:
test-local:
@$(MAKE) -C './test' test-local

rust-coverage:
ifndef RUST_PKG
@cargo llvm-cov >/dev/null 2>&1
@cargo llvm-cov report 2>/dev/null
else
@cargo llvm-cov -p $(RUST_PKG) >/dev/null 2>&1
@cargo llvm-cov report -p $(RUST_PKG) 2>/dev/null
endif

rust-coverage-percent:
@$(MAKE) rust-coverage | grep TOTAL | awk '{print $$10}' | cut -d '.' -f1

install:
brew install go
go install github.com/99designs/gqlgen@latest
Expand All @@ -73,10 +85,12 @@ install:
brew install yq
npm install -g eslint
# rust
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh -s -- -y
rustup component add llvm-tools-preview --toolchain stable-x86_64-apple-darwin
# https://www.docker.com/products/docker-desktop
cargo install cross --git https://github.com/cross-rs/cross
cargo install cargo-watch
cargo install cargo-llvm-cov

env-id:
(cd infrastructure/terraform/env-id; terraform init && terraform apply --auto-approve)
Expand Down
10 changes: 7 additions & 3 deletions project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,11 @@ params: []
- name: rust
os:
osx:
install: "curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh"
install: "curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh -s -- -y"
- name: llvm-tools-preview
os:
osx:
install: 'rustup component add llvm-tools-preview --toolchain stable-x86_64-apple-darwin'
- name: cross
os:
osx:
Expand All @@ -839,7 +843,7 @@ params: []
os:
osx:
install: 'cargo install cargo-watch'
- name: tarpaulin
- name: cargo-llvm-cov
os:
osx:
install: 'cargo install tarpaulin'
install: 'cargo install cargo-llvm-cov'
2 changes: 2 additions & 0 deletions scripts/post-create-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

go mod download

rustup component add llvm-tools-preview --toolchain stable-x86_64-unknown-linux-gnu

make --no-print-directory start
1 change: 1 addition & 0 deletions services/rule/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ async fn apply_rules(
}
}

// get connection from pool
let conn = pool.get_conn().await;

let mut rule_applied_tr_items =
Expand Down

0 comments on commit 9d95528

Please sign in to comment.