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 e311ec8 commit 8897bef
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 52 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ jobs:
run: |
cargo install cargo-deadlinks
cargo install cargo-machete
cargo install taplo
- 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

- name: Code coverage
if: ${{ runner.os == 'Linux' }}
Expand All @@ -59,4 +60,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 = ["tests/**", "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",
]
24 changes: 10 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ repository = "https://github.com/orium/cargo-rdme"
documentation = "https://docs.rs/cargo-rdme"
readme = "README.md"

keywords = [
"readme", "cargo", "documentation"
]
categories = [
"development-tools::cargo-plugins",
]
keywords = ["readme", "cargo", "documentation"]
categories = ["development-tools::cargo-plugins"]

license = "MPL-2.0"

Expand All @@ -35,17 +31,17 @@ include = [
codecov = { repository = "orium/cargo-rdme", branch = "main", service = "github" }

[dependencies]
toml = "0.8.19"
thiserror = "2.0.0"
syn = { version = "2.0.85", features = ["full", "extra-traits"] }
pulldown-cmark = "0.12.2"
itertools = "0.13.0"
cargo_metadata = "0.18.1"
clap = "4.5.20"
itertools = "0.13.0"
pulldown-cmark = "0.12.2"
syn = { version = "2.0.85", features = ["full", "extra-traits"] }
thiserror = "2.0.0"
toml = "0.8.19"
# Disable ssh support in git2 to avoid depending on openssl (which fails to build if an unsupported version is found).
git2 = { version = "0.19.0", default-features = false }
termcolor = "1.4.1"
cargo_metadata = "0.18.1"
indoc = "2.0.5"
termcolor = "1.4.1"
unicase = "2.8.0"

[dev-dependencies]
Expand All @@ -56,8 +52,8 @@ fatal-warnings = []

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

enum-variant-names = "allow"
if-not-else = "allow"
Expand Down
11 changes: 4 additions & 7 deletions src/transform/intralinks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,16 @@ fn rewrite_links(
let RewriteReferenceLinksResult { doc, reference_links_to_remove } =
rewrite_reference_links_definitions(doc, symbols_type, crate_name, emit_warning, config);

let doc = rewrite_markdown_links(
// TODO Refactor link removal code so that it all happens in a new phase and not inside the
// functions above.
rewrite_markdown_links(
&doc,
symbols_type,
crate_name,
emit_warning,
config,
&reference_links_to_remove,
);

// TODO Refactor link removal code so that it all happens in a new phase and not inside the
// functions above.

doc
)
}

#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
Expand Down
107 changes: 78 additions & 29 deletions tools/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,87 @@ function on_failure {
echo -e "${RED}Whoopsie-daisy: something failed!$NC" >&2
}

assert_installed "cargo-deadlinks"
assert_installed "cargo-machete"
assert_installed "cargo-fmt"
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 unused dependencies:'
cargo machete

echo 'Checking packaging:'
cargo package --allow-dirty
echo 'Checking code style:'
cargo fmt -- --check
echo 'Checking readme:'
cargo run -- --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 {
echo 'Checking readme:'
cargo run -- --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 8897bef

Please sign in to comment.