ci: Make CI use same checks as pre-commit hook
This commit is contained in:
parent
a53b20bfab
commit
7f790a854f
2 changed files with 72 additions and 31 deletions
|
@ -32,15 +32,13 @@ flatpak:
|
|||
- 'logs'
|
||||
expire_in: 14 days
|
||||
|
||||
# Configure and run rustfmt
|
||||
# Exits and builds fails if on bad format
|
||||
rustfmt:
|
||||
# Configure and run code checks
|
||||
# Exits and fails if an error is encountered
|
||||
checks:
|
||||
image: "rust:slim"
|
||||
stage: check
|
||||
script:
|
||||
- rustup component add rustfmt
|
||||
- rustc -Vv && cargo -Vv
|
||||
- cargo fmt --version
|
||||
- cargo fmt --all -- --color=always --check
|
||||
- scripts/checks.sh --verbose --force-install
|
||||
|
||||
cargo-clippy:
|
||||
image: 'registry.gitlab.gnome.org/gnome/gnome-runtime-images/rust_bundle:master'
|
||||
|
|
|
@ -1,6 +1,47 @@
|
|||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
# Source: https://gitlab.gnome.org/GNOME/fractal/blob/master/hooks/pre-commit.hook
|
||||
|
||||
# Usage info
|
||||
show_help() {
|
||||
cat << EOF
|
||||
Run conformity checks on the current Rust project.
|
||||
|
||||
If a dependency is not found, helps the user to install it.
|
||||
|
||||
USAGE: ${0##*/} [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-f, --force-install Install missing dependencies without asking
|
||||
-v, --verbose Use verbose output
|
||||
-h, --help Display this help and exit
|
||||
|
||||
ERROR CODES:
|
||||
1 Check failed
|
||||
2 Missing dependency
|
||||
EOF
|
||||
}
|
||||
|
||||
# Initialize variables
|
||||
verbose=0
|
||||
force_install=0
|
||||
|
||||
# Check arguments
|
||||
while [[ "$1" ]]; do case $1 in
|
||||
-f | --force-install )
|
||||
force_install=1
|
||||
;;
|
||||
-v | --verbose )
|
||||
verbose=1
|
||||
;;
|
||||
-h | --help )
|
||||
show_help
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
show_help >&2
|
||||
exit 1
|
||||
esac; shift; done
|
||||
|
||||
install_rustfmt() {
|
||||
if ! which rustup &> /dev/null; then
|
||||
curl https://sh.rustup.rs -sSf | sh -s -- -y
|
||||
|
@ -11,25 +52,22 @@ install_rustfmt() {
|
|||
fi
|
||||
fi
|
||||
|
||||
if ! rustup component list|grep rustfmt &> /dev/null; then
|
||||
echo "Installing rustfmt…"
|
||||
rustup component add rustfmt
|
||||
fi
|
||||
}
|
||||
|
||||
if ! which cargo >/dev/null 2>&1 || ! cargo fmt --help >/dev/null 2>&1; then
|
||||
echo "Unable to check Fractal’s code style, because rustfmt could not be run."
|
||||
|
||||
if [ ! -t 1 ]; then
|
||||
if [[ $force_install -eq 1 ]]; then
|
||||
install_rustfmt
|
||||
elif [ ! -t 1 ]; then
|
||||
# No input is possible
|
||||
echo "Performing commit."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
exit 2
|
||||
else
|
||||
echo ""
|
||||
echo "y: Install rustfmt via rustup"
|
||||
echo "N: Don't install rustfmt"
|
||||
|
||||
echo ""
|
||||
while true
|
||||
do
|
||||
|
@ -40,11 +78,16 @@ if ! which cargo >/dev/null 2>&1 || ! cargo fmt --help >/dev/null 2>&1; then
|
|||
* ) echo "Invalid input";;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $verbose -eq 1 ]]; then
|
||||
rustc -Vv && cargo -Vv
|
||||
cargo fmt --version
|
||||
fi
|
||||
|
||||
echo "--Checking style--"
|
||||
cargo fmt --all -- --check
|
||||
cargo fmt --all -- --color=always --check
|
||||
if test $? != 0; then
|
||||
echo "--Checking style fail--"
|
||||
echo "Please fix the above issues, either manually or by running: cargo fmt --all"
|
||||
|
|
Loading…
Reference in a new issue