Skip to content

Commit

Permalink
Improve check script to allow running just some checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
orium committed Nov 10, 2024
1 parent 5a26af0 commit ecd8d30
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 44 deletions.
20 changes: 18 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ jobs:
- name: Install cargo plugins
run: |
cargo install cargo-rdme
cargo install cargo-machete
cargo install taplo-cli
cargo install cargo-deadlinks
- name: Checkout repository
uses: actions/checkout@v4

- name: Check everything
run: bash ./tools/check.sh
run: bash ./tools/check.sh basic doc_url_links unused_deps packaging fmt toml_fmt readme


msrv:
runs-on: ubuntu-latest
Expand All @@ -48,4 +51,17 @@ jobs:
uses: actions/checkout@v4

- name: Check the minimum supported rust version
run: cargo msrv verify
run: bash ./tools/check.sh msrv

clippy:
runs-on: ubuntu-latest

steps:
- name: Install rust
uses: dtolnay/rust-toolchain@stable

- name: Checkout repository
uses: actions/checkout@v4

- name: Run clippy
run: bash ./tools/check.sh clippy
17 changes: 17 additions & 0 deletions .taplo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
include = ["**/*.toml"]
exclude = ["target/**"]

[formatting]
column_width = 100
indent_string = ' '
allowed_blank_lines = 1

[[rule]]
formatting = { reorder_keys = true }
keys = [
"workspace.dependencies",
"dependencies",
"dev-dependencies",
"build-dependencies",
"lints.clippy",
]
27 changes: 13 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ repository = "https://github.com/orium/brewfatherlog"
documentation = "https://docs.rs/brewfatherlog"
readme = "README.md"

keywords = [
"brewing", "fermentation", "grainfather", "brewfather", "logging"
]
keywords = ["brewing", "fermentation", "grainfather", "brewfather", "logging"]

license = "MPL-2.0"

Expand All @@ -30,32 +28,33 @@ include = [
]

[dependencies]
tokio = { version = "1.37.0", features = ["rt-multi-thread", "macros"] }
thiserror = "1.0.61"
dirs = "5.0.1"
humantime = "2.1.0"
log = { version = "0.4.21", features = [] }
reqwest = { version = "0.12.4", features = ["json", "cookies"] }
serde = { version = "1.0.202", features = ["derive"] }
time = { version = "0.3.36", features = ["formatting"] }
serde_json = "1.0.117"
dirs = "5.0.1"
toml = "0.8.13"
serde_derive = "1.0.202"
serde_json = "1.0.117"
simplelog = "0.12.2"
log = { version = "0.4.21", features = [] }
humantime = "2.1.0"
thiserror = "1.0.61"
time = { version = "0.3.36", features = ["formatting"] }
tokio = { version = "1.37.0", features = ["rt-multi-thread", "macros"] }
toml = "0.8.13"

[features]
fatal-warnings = []

[lints.clippy]
all = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }
correctness = "deny"
all = { level = "warn", priority = -2 }
correctness = { level = "deny", priority = -1 }
pedantic = { level = "warn", priority = -2 }

enum-variant-names = "allow"
if-not-else = "allow"
inline-always = "allow"
match-bool = "allow"
missing-errors-doc = "allow"
missing-panics-doc = "allow"
module-name-repetitions = "allow"
needless-raw-string-hashes = "allow"
new-without-default = "allow"
Expand Down
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ fn init_logging() {
.expect("failed to create the program directory");

let log_file = std::fs::OpenOptions::new()
.write(true)
.append(true)
.create(true)
.open(log_file_path)
Expand All @@ -124,11 +123,13 @@ async fn log_temperature(
let age: time::Duration = now - temp_record.timestamp;

if age > Duration::from_secs(30 * 60) {
let age = Duration::from_secs(age.whole_seconds().try_into().expect("fail to convert age"));

warn!(
"Ignoring temperature {:.02} °C of fermenter \"{}\" because the temperature is too old ({}).",
temp_record.temperature,
fermenter.name,
humantime::format_duration(Duration::from_secs(age.whole_seconds() as u64)),
humantime::format_duration(age),
);
return;
}
Expand Down
106 changes: 80 additions & 26 deletions tools/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,89 @@ function on_failure {
echo -e "${RED}Whoopsie-daisy: something failed!$NC" >&2
}

assert_installed "cargo-deadlinks"
assert_installed "cargo-fmt"
assert_installed "cargo-rdme"
assert_installed "cargo"

trap on_failure ERR

echo 'Building:'
cargo build --features fatal-warnings --all-targets
echo 'Testing:'
cargo test --features fatal-warnings --all-targets
# Weirdly, the `cargo test ... --all-targets ...` above does not run the tests in the documentation, so we run the
# doc tests like this.
# See https://github.com/rust-lang/cargo/issues/6669.
echo 'Testing doc:'
cargo test --features fatal-warnings --doc
echo 'Checking the benchmarks:'
cargo bench --features fatal-warnings -- --test
echo 'Checking documentation:'
cargo doc --features fatal-warnings --no-deps

echo 'Checking links:'
cargo deadlinks

echo 'Checking packaging:'
cargo package --allow-dirty
echo 'Checking code style:'
cargo fmt -- --check
echo 'Checking readme:'
cargo rdme --check
function check_basic {
echo 'Building:'
cargo build --features fatal-warnings --all-targets
echo 'Testing:'
cargo test --features fatal-warnings --all-targets
# Weirdly, the `cargo test ... --all-targets ...` above does not run the tests in the documentation, so we run the
# doc tests like this.
# See https://github.com/rust-lang/cargo/issues/6669.
echo 'Testing doc:'
cargo test --features fatal-warnings --doc
echo 'Checking the benchmarks:'
cargo bench --features fatal-warnings -- --test
echo 'Checking documentation:'
cargo doc --features fatal-warnings --no-deps
}

function check_doc_url_links {
assert_installed "cargo-deadlinks"

echo 'Checking doc url links:'
cargo deadlinks
}

function check_unused_deps {
assert_installed "cargo-machete"

echo 'Checking unused dependencies:'
cargo machete
}

function check_packaging {
echo 'Checking packaging:'
cargo package --allow-dirty
}

function check_fmt {
assert_installed "cargo-fmt"

echo 'Checking code format:'
cargo fmt -- --check
}

function check_toml_fmt {
assert_installed "taplo"

echo 'Checking toml format:'
taplo fmt --check
}

function check_readme {
assert_installed "cargo-rdme"

echo 'Checking readme:'
cargo rdme --check
}

function check_msrv {
assert_installed "cargo-msrv"

echo 'Checking the minimum supported rust version:'
cargo msrv verify
}

function check_clippy {
assert_installed "cargo-clippy"

echo 'Checking with clippy:'
cargo clippy --all-targets -- -D warnings
}

to_run=(basic doc_url_links unused_deps packaging fmt toml_fmt readme msrv clippy)

if [ $# -ge 1 ]; then
to_run=("$@")
fi

for check in "${to_run[@]}"; do
check_$check
done

echo
echo -e "${GREEN}Everything looks lovely!$NC"
Expand Down

0 comments on commit ecd8d30

Please sign in to comment.