-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from zeenix/sync-contributing
π CONTRIBUTING: Sync with zbus' CONTRIBUTING.md
- Loading branch information
Showing
4 changed files
with
117 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
GITHOOKS_DIR=$( cd -- "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd ) | ||
source $GITHOOKS_DIR/util.sh | ||
|
||
ensure_rustup_installed | ||
ensure_rustfmt_installed | ||
|
||
check_formatting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
GITHOOKS_DIR=$( cd -- "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd ) | ||
source $GITHOOKS_DIR/util.sh | ||
|
||
ensure_rustup_installed | ||
ensure_clippy_installed | ||
|
||
check_clippy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/bin/bash | ||
# | ||
# Utility functions for git hook scripts. | ||
|
||
if test -t 1 && test -n "$(tput colors)" && test "$(tput colors)" -ge 8; then | ||
bold="$(tput bold)" | ||
normal="$(tput sgr0)" | ||
green="$(tput setaf 2)" | ||
red="$(tput setaf 1)" | ||
blue="$(tput setaf 4)" | ||
|
||
function hook_failure { | ||
echo "${red}${bold}FAILED:${normal} ${1}${normal}" | ||
exit 1 | ||
} | ||
|
||
function hook_info { | ||
echo "${blue}${1}${normal}" | ||
} | ||
|
||
function hook_success { | ||
echo "${green}${bold}SUCCESS:${normal} ${1}${normal}" | ||
echo | ||
echo | ||
} | ||
|
||
else | ||
function hook_failure { | ||
echo "FAILED: ${1}" | ||
exit 1 | ||
} | ||
|
||
function hook_info { | ||
echo "{$1}" | ||
} | ||
|
||
function hook_success { | ||
echo "SUCCESS: ${1}" | ||
echo | ||
echo | ||
} | ||
fi | ||
|
||
function ensure_rustup_installed() { | ||
hook_info "π¦οΈ Ensuring that rustup is installed" | ||
if ! which rustup &> /dev/null; then | ||
curl https://sh.rustup.rs -sSf | sh -s -- -y | ||
export PATH=$PATH:$HOME/.cargo/bin | ||
if ! which rustup &> /dev/null; then | ||
hook_failure "Failed to install rustup" | ||
else | ||
hook_success "rustup installed." | ||
fi | ||
else | ||
hook_success "rustup is already installed." | ||
fi | ||
} | ||
|
||
function ensure_rustfmt_installed() { | ||
hook_info "π¦οΈ Ensuring that nightly rustfmt is installed" | ||
if ! rustup component list --toolchain nightly|grep 'rustfmt-preview.*(installed)' &> /dev/null; then | ||
rustup component add rustfmt-preview --toolchain nightly | ||
hook_success "rustfmt installed." | ||
else | ||
hook_success "rustfmt is already installed." | ||
fi | ||
} | ||
|
||
function ensure_clippy_installed() { | ||
hook_info "π¦οΈ Ensuring that clippy is installed" | ||
if ! rustup component list --toolchain stable|grep 'clippy.*(installed)' &> /dev/null; then | ||
rustup component add clippy | ||
hook_success "clippy installed." | ||
else | ||
hook_success "clippy is already installed." | ||
fi | ||
} | ||
|
||
function check_formatting() { | ||
hook_info "π¨ Running 'cargo +nightly fmt -- --check'" | ||
cargo +nightly fmt -- --check \ | ||
&& hook_success "Project is formatted" \ | ||
|| hook_failure "Cargo format detected errors." | ||
} | ||
|
||
function check_clippy() { | ||
hook_info "π Running 'cargo clippy -- -D warnings'" | ||
cargo clippy -- -D warnings \ | ||
&& hook_success "Clippy detected no issues" \ | ||
|| hook_failure "Cargo clippy detected errors." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters