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'
|
- 'logs'
|
||||||
expire_in: 14 days
|
expire_in: 14 days
|
||||||
|
|
||||||
# Configure and run rustfmt
|
# Configure and run code checks
|
||||||
# Exits and builds fails if on bad format
|
# Exits and fails if an error is encountered
|
||||||
rustfmt:
|
checks:
|
||||||
image: "rust:slim"
|
image: "rust:slim"
|
||||||
|
stage: check
|
||||||
script:
|
script:
|
||||||
- rustup component add rustfmt
|
- scripts/checks.sh --verbose --force-install
|
||||||
- rustc -Vv && cargo -Vv
|
|
||||||
- cargo fmt --version
|
|
||||||
- cargo fmt --all -- --color=always --check
|
|
||||||
|
|
||||||
cargo-clippy:
|
cargo-clippy:
|
||||||
image: 'registry.gitlab.gnome.org/gnome/gnome-runtime-images/rust_bundle:master'
|
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
|
# 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() {
|
install_rustfmt() {
|
||||||
if ! which rustup &> /dev/null; then
|
if ! which rustup &> /dev/null; then
|
||||||
curl https://sh.rustup.rs -sSf | sh -s -- -y
|
curl https://sh.rustup.rs -sSf | sh -s -- -y
|
||||||
|
@ -11,25 +52,22 @@ install_rustfmt() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! rustup component list|grep rustfmt &> /dev/null; then
|
|
||||||
echo "Installing rustfmt…"
|
echo "Installing rustfmt…"
|
||||||
rustup component add rustfmt
|
rustup component add rustfmt
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! which cargo >/dev/null 2>&1 || ! cargo fmt --help >/dev/null 2>&1; then
|
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."
|
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
|
# No input is possible
|
||||||
echo "Performing commit."
|
exit 2
|
||||||
exit 0
|
else
|
||||||
fi
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "y: Install rustfmt via rustup"
|
echo "y: Install rustfmt via rustup"
|
||||||
echo "N: Don't install rustfmt"
|
echo "N: Don't install rustfmt"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
|
@ -40,11 +78,16 @@ if ! which cargo >/dev/null 2>&1 || ! cargo fmt --help >/dev/null 2>&1; then
|
||||||
* ) echo "Invalid input";;
|
* ) echo "Invalid input";;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $verbose -eq 1 ]]; then
|
||||||
|
rustc -Vv && cargo -Vv
|
||||||
|
cargo fmt --version
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "--Checking style--"
|
echo "--Checking style--"
|
||||||
cargo fmt --all -- --check
|
cargo fmt --all -- --color=always --check
|
||||||
if test $? != 0; then
|
if test $? != 0; then
|
||||||
echo "--Checking style fail--"
|
echo "--Checking style fail--"
|
||||||
echo "Please fix the above issues, either manually or by running: cargo fmt --all"
|
echo "Please fix the above issues, either manually or by running: cargo fmt --all"
|
||||||
|
|
Loading…
Reference in a new issue