Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Config Files validations and Cargo Nextest for testing in CI pipeline #25

Merged
merged 17 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 55 additions & 17 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,58 @@ name: CI

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]
schedule:
- cron: "0 5 * * 0"

env:
LOG_LEVEL: debug
CARGO_TERM_COLOR: always
MIN_LINE_COVERAGE_TARGET: 80

jobs:
Build:
Project-Config:
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v4

- name: Install Rust
- name: Setup Rust
uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Setup Go
uses: actions/setup-go@v5
with:
components: rustfmt, clippy
go-version: stable
cache: false

- name: Format
run: cargo fmt --all --check
- name: Setup Taplo
uses: taiki-e/install-action@v2
with:
tool: taplo-cli

- name: Lints
run: cargo clippy --workspace --all-features
- name: Install yamlfmt
run: go install github.com/google/yamlfmt/cmd/yamlfmt@latest

- name: Build
run: cargo build --workspace --all-features
- name: Verify Project Config
run: cargo verify-project --verbose

- name: Verify YAML Files Format
run: yamlfmt --lint .

- name: Verify TOML Files Format
run: taplo fmt --check --verbose --diff

Documentation:
Docs:
runs-on: ubuntu-latest
needs: Project-Config
steps:
- name: Fetch Repository
uses: actions/checkout@v4

- name: Install Rust
- name: Setup Rust
uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Build Crate Doc
Expand All @@ -47,22 +62,45 @@ jobs:
- name: Doc Tests
run: cargo test --workspace --all-features --doc

Build:
runs-on: ubuntu-latest
needs: Project-Config
steps:
- name: Fetch Repository
uses: actions/checkout@v4

- name: Setup Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt, clippy

- name: Format
run: cargo fmt --all --check

- name: Lints
run: cargo clippy --workspace --all-features

- name: Build
run: cargo build --workspace --all-features

Tests:
runs-on: ubuntu-latest
needs: Build
steps:
- name: Fetch Repository
uses: actions/checkout@v4

- name: Install cargo-llvm-cov
- name: Setup cargo-llvm-cov
uses: taiki-e/[email protected]
with:
tool: cargo-llvm-cov
tool: cargo-llvm-cov,cargo-nextest

- name: Unit & Integration Tests
run: cargo llvm-cov --workspace --all-features --show-missing-lines --summary-only --fail-under-lines ${{ env.MIN_LINE_COVERAGE_TARGET }}
run: cargo llvm-cov nextest --workspace --all-features --show-missing-lines --summary-only --fail-under-lines ${{ env.MIN_LINE_COVERAGE_TARGET }}

Security:
runs-on: ubuntu-latest
needs: Build
steps:
- name: Fetch Repository
uses: actions/checkout@v4
Expand All @@ -71,4 +109,4 @@ jobs:
uses: EmbarkStudios/cargo-deny-action@v1
with:
log-level: ${{ env.LOG_LEVEL }}
command: check
command: check
3 changes: 3 additions & 0 deletions .yamlfmt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
formatter:
type: basic
retain_line_breaks_single: true
7 changes: 5 additions & 2 deletions redsumer-rs/CHANGELOG.md → CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added:

- ⚡ Implement `cargo-deny` in CI pipeline to verify security vulnerabilities. By [@JMTamayo](https://github.com/JMTamayo).
- ⚡ Implement `cargo-audit` and `cargo-deny` in Makefile. By [@JMTamayo](https://github.com/JMTamayo).
- ⚡ Implement `cargo verify-project`, `yamlfmt` and `taplo` in CI pipeline to verify config files format. By [@JMTamayo](https://github.com/JMTamayo).
- ⚡ Implement `cargo-audit`, `cargo-deny`, `cargo verify-project`, `yamlfmt`and `taplo` in Makefile. By [@JMTamayo](https://github.com/JMTamayo).
- ⚡ Implement scheduled job to run CI pipeline each Sunday at 05:00 UTC. By [@JMTamayo](https://github.com/JMTamayo).

### Changed:

- 🚀 Refactor the CI pipeline to split the process into the following steps: Build, Documentation, Tests and Security. By [@JMTamayo](https://github.com/JMTamayo).
- 🚀 CI pipeline refactor to split the process into the following steps: Project-Config, Docs, Build, Tests and Security. By [@JMTamayo](https://github.com/JMTamayo).
- 🚀 Implement cargo-nextest to run unit tests alongside llvm-cov. By [@JMTamayo](https://github.com/JMTamayo).

## ✨ v0.5.1 [2024-11-27]

Expand Down
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
[workspace]
resolver="2"
members = [
"redsumer-rs",
]
resolver = "2"
members = ["redsumer-rs"]
30 changes: 27 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ check:
clippy-check:
cargo clippy --workspace --all-features

install-nextest:
cargo install cargo-nextest

install-llvm-cov:
cargo install cargo-llvm-cov

test-llvm-cov-report:
cargo llvm-cov --workspace --all-features --show-missing-lines --open
cargo llvm-cov nextest --workspace --all-features --show-missing-lines --open

test-llvm-cov-target:
cargo llvm-cov --workspace --all-features --show-missing-lines --summary-only --fail-under-lines 80
cargo llvm-cov nextest --workspace --all-features --show-missing-lines --summary-only --fail-under-lines 80

install-cargo-audit:
cargo install cargo-audit
Expand All @@ -35,4 +38,25 @@ test-doc:
cargo test --workspace --all-features --doc

doc:
cargo doc --workspace --all-features --document-private-items --verbose --open
cargo doc --workspace --all-features --document-private-items --verbose --open

install-yamlfmt:
go install github.com/google/yamlfmt/cmd/yamlfmt@latest

yamlfmt:
yamlfmt .

yamlfmt-check:
yamlfmt --lint .

verify-project:
cargo verify-project --verbose

install-taplo:
cargo install taplo-cli

format-toml-files:
taplo fmt

toml-files-format-check:
taplo fmt --check --verbose --diff
60 changes: 27 additions & 33 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
# dependencies not shared by any other crates, would be ignored, as the target
# list here is effectively saying which targets you are building for.
targets = [
# The triple can be any string, but only the target triples built in to
# rustc (as of 1.40) can be checked against actual config expressions
#"x86_64-unknown-linux-musl",
# You can also specify which target_features you promise are enabled for a
# particular target. target_features are currently not validated against
# the actual valid features supported by the target architecture.
#{ triple = "wasm32-unknown-unknown", features = ["atomics"] },
# The triple can be any string, but only the target triples built in to
# rustc (as of 1.40) can be checked against actual config expressions
#"x86_64-unknown-linux-musl",
# You can also specify which target_features you promise are enabled for a
# particular target. target_features are currently not validated against
# the actual valid features supported by the target architecture.
#{ triple = "wasm32-unknown-unknown", features = ["atomics"] },
]
# When creating the dependency graph used as the source of truth when checks are
# executed, this field can be used to prune crates from the graph, removing them
Expand Down Expand Up @@ -70,10 +70,10 @@ feature-depth = 1
# A list of advisory IDs to ignore. Note that ignored advisories will still
# output a note when they are encountered.
ignore = [
#"RUSTSEC-0000-0000",
#{ id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" },
#"[email protected]", # you can also ignore yanked crate versions if you wish
#{ crate = "[email protected]", reason = "you can specify why you are ignoring the yanked crate" },
#"RUSTSEC-0000-0000",
#{ id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" },
#"[email protected]", # you can also ignore yanked crate versions if you wish
#{ crate = "[email protected]", reason = "you can specify why you are ignoring the yanked crate" },
]
# If this is true, then cargo deny will use the git executable to fetch advisory database.
# If this is false, then it uses a built-in git library.
Expand All @@ -88,13 +88,7 @@ ignore = [
# List of explicitly allowed licenses
# See https://spdx.org/licenses/ for list of possible licenses
# [possible values: any SPDX 3.11 short identifier (+ optional exception)].
allow = [
"MIT",
"Apache-2.0",
"Unicode-DFS-2016",
"BSD-3-Clause",
"Unicode-3.0",
]
allow = ["MIT", "Apache-2.0", "Unicode-DFS-2016", "BSD-3-Clause", "Unicode-3.0"]
# The confidence threshold for detecting a license from license text.
# The higher the value, the more closely the license text must be to the
# canonical license text of a valid SPDX license file.
Expand All @@ -103,9 +97,9 @@ confidence-threshold = 0.8
# Allow 1 or more licenses on a per-crate basis, so that particular licenses
# aren't accepted for every possible crate as with the normal allow list
exceptions = [
# Each entry is the crate and version constraint, and its specific allow
# list
#{ allow = ["Zlib"], crate = "adler32" },
# Each entry is the crate and version constraint, and its specific allow
# list
#{ allow = ["Zlib"], crate = "adler32" },
]

# Some crates don't have (easily) machine readable licensing information,
Expand Down Expand Up @@ -136,7 +130,7 @@ ignore = false
# is only published to private registries, and ignore is true, the crate will
# not have its license(s) checked
registries = [
#"https://sekretz.com/registry
#"https://sekretz.com/registry
]

# This section is considered when running `cargo deny check bans`.
Expand All @@ -163,16 +157,16 @@ workspace-default-features = "allow"
external-default-features = "allow"
# List of crates that are allowed. Use with care!
allow = [
#"[email protected]",
#{ crate = "[email protected]", reason = "you can specify a reason it is allowed" },
#"[email protected]",
#{ crate = "[email protected]", reason = "you can specify a reason it is allowed" },
]
# List of crates to deny
deny = [
#"[email protected]",
#{ crate = "[email protected]", reason = "you can specify a reason it is banned" },
# Wrapper crates can optionally be specified to allow the crate when it
# is a direct dependency of the otherwise banned crate
#{ crate = "[email protected]", wrappers = ["this-crate-directly-depends-on-ansi_term"] },
#"[email protected]",
#{ crate = "[email protected]", reason = "you can specify a reason it is banned" },
# Wrapper crates can optionally be specified to allow the crate when it
# is a direct dependency of the otherwise banned crate
#{ crate = "[email protected]", wrappers = ["this-crate-directly-depends-on-ansi_term"] },
]

# List of features to allow/deny
Expand Down Expand Up @@ -200,16 +194,16 @@ deny = [

# Certain crates/versions that will be skipped when doing duplicate detection.
skip = [
#"[email protected]",
#{ crate = "[email protected]", reason = "you can specify a reason why it can't be updated/removed" },
#"[email protected]",
#{ crate = "[email protected]", reason = "you can specify a reason why it can't be updated/removed" },
]
# Similarly to `skip` allows you to skip certain crates during duplicate
# detection. Unlike skip, it also includes the entire tree of transitive
# dependencies starting at the specified crate, up to a certain depth, which is
# by default infinite.
skip-tree = [
#"[email protected]", # will be skipped along with _all_ of its direct and transitive dependencies
#{ crate = "[email protected]", depth = 20 },
#"[email protected]", # will be skipped along with _all_ of its direct and transitive dependencies
#{ crate = "[email protected]", depth = 20 },
]

# This section is considered when running `cargo deny check sources`.
Expand Down
17 changes: 5 additions & 12 deletions redsumer-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,12 @@ version = "0.5.2"
edition = "2021"
license-file = "../LICENSE"
readme = "../README.md"
keywords = [
"redis",
"redis_streams",
]
keywords = ["redis", "redis_streams"]
homepage = "https://github.com/enerBit/redsumer-rs"
repository = "https://github.com/enerBit/redsumer-rs"
documentation = "https://docs.rs/redsumer"
categories = [
"database-implementations",
]
authors = [
"Juan Manuel Tamayo <[email protected]>",
]
categories = ["database-implementations"]
authors = ["Juan Manuel Tamayo <[email protected]>"]

[dependencies]
redis = { version = ">=0.27.2", features = ["streams"] }
Expand All @@ -26,5 +19,5 @@ tracing = { version = ">=0.1.40" }
[dev-dependencies]
redis-test = { version = "0.6.0" }
tokio = { version = "1.41.1", features = ["full"] }
time ={ version = "0.3.36" }
uuid ={ version = "1.11.0", features = ["v4"] }
time = { version = "0.3.36" }
uuid = { version = "1.11.0", features = ["v4"] }
4 changes: 2 additions & 2 deletions redsumer-rs/src/core/streams/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ pub const BEGINNING_OF_TIME_ID: &str = "0-0";

/// Get StreamIds from a StreamReadReply by key.
trait UnwrapStreamReadReply<K> {
/// Unwrap StreamReadReply by key into a Vec<StreamId>.
/// Unwrap StreamReadReply by key into a `Vec<StreamId>`.
///
/// # Arguments:
/// - **key**: A key to filter the StreamReadReply.
///
/// # Returns:
/// A Vec<StreamId> with the StreamIds found.
/// A `Vec<StreamId>` with the StreamIds found.
fn unwrap_by_key(&self, key: &K) -> Vec<StreamId>
where
K: ToString;
Expand Down
4 changes: 2 additions & 2 deletions redsumer-rs/src/redsumer/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct ReadNewMessagesOptions {
/// The number of new messages to read from the stream.
count: usize,

/// The block time [seconds] to wait for new messages to arrive in the stream.
/// The block time in `seconds` to wait for new messages to arrive in the stream.
block: usize,
}

Expand Down Expand Up @@ -90,7 +90,7 @@ pub struct ClaimMessagesOptions {
/// The number of messages to claim from the stream.
count: usize,

/// The min idle time [milliseconds] to claim the messages.
/// The min idle time in `milliseconds` to claim the messages.
min_idle_time: usize,

/// The latest ID to start claiming from.
Expand Down
Loading