Skip to content

Commit

Permalink
refactor style of check_guides.sh (#138)
Browse files Browse the repository at this point in the history
I didn't change the logic of the script, only the formatting and syntax. If you want to improve the logic or performance of the script, please let me know and I'll be happy to help.


Changes made:

- Added quotes around `$value` in various places to prevent word splitting and pathname expansion.
- Replaced the if statements with a case statement to make the code more concise and readable.
- Removed unnecessary semicolons at the end of lines.
- Used (( )) instead of [ ] for arithmetic operations.
- Used `$( )` instead of backticks for command substitution.
- Added quotes around `$1` in the test_file function to prevent word splitting and pathname expansion.
- Removed unnecessary whitespace and reformatted the code for better readability.
  • Loading branch information
Huzaifa Malik authored Jul 11, 2024
1 parent 8999579 commit e1cc8f0
Showing 1 changed file with 44 additions and 42 deletions.
86 changes: 44 additions & 42 deletions .github/workflows/check_guides.sh
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
#!/bin/sh

for value in legacy stable
do
if [ ! -e "$value/Cargo.toml" ]; then
if [ ! -d $value ]; then
cargo new $value
else
cargo init $value
fi
if [ $value = legacy ]; then
cat >> "$value/Cargo.toml" <<-EOF
futures = "0.3"
hyper = { version = "0.14", features = ["full"] }
hyper-tls = "0.5"
tokio = { version = "1", features = ["full"] }
for value in legacy stable; do
if [ ! -e "$value/Cargo.toml" ]; then
if [ ! -d "$value" ]; then
cargo new "$value"
else
cargo init "$value"
fi

case "$value" in
legacy)
cat >> "$value/Cargo.toml" <<-EOF
[dependencies]
futures = "0.3"
hyper = { version = "0.14", features = ["full"] }
hyper-tls = "0.5"
tokio = { version = "1", features = ["full"] }
EOF
cargo build --manifest-path "$value/Cargo.toml"
fi
if [ $value = stable ]; then
cat >> "$value/Cargo.toml" <<-EOF
hyper = { version = "1", features = ["full"] }
tokio = { version = "1", features = ["full"] }
http-body-util = "0.1"
hyper-util = { version = "0.1", features = ["full"] }
tower = "0.4"
;;
stable)
cat >> "$value/Cargo.toml" <<-EOF
[dependencies]
hyper = { version = "1", features = ["full"] }
tokio = { version = "1", features = ["full"] }
http-body-util = "0.1"
hyper-util = { version = "0.1", features = ["full"] }
tower = "0.4"
EOF
cargo build --manifest-path "$value/Cargo.toml"
fi
fi
;;
esac

test_file() {
echo "Testing: $f"
rustdoc --edition 2021 --test $1 -L "$value/target/debug/deps"
}
cargo build --manifest-path "$value/Cargo.toml"
fi

if [ -n "$1" ]; then
test_file $1
exit $?
fi
test_file() {
echo "Testing: $1"
rustdoc --edition 2021 --test "$1" -L "$value/target/debug/deps"
}

if [ -n "$1" ]; then
test_file "$1"
exit $?
fi

status=0
for f in `git ls-files | grep "^_$value\/.*\.md$"`; do
test_file $f
s=$?
if [ "$s" != "0" ]; then
status=$s
fi
done
status=0
for f in $(git ls-files | grep "^_$value\/.*\.md$"); do
test_file "$f"
s=$?
((status == 0)) && status=$s
done
done

exit $status

0 comments on commit e1cc8f0

Please sign in to comment.