|
1 | 1 | #!/bin/sh
|
2 | 2 |
|
3 |
| -# An example hook script to verify what is about to be pushed. Called by "git |
4 |
| -# push" after it has checked the remote status, but before anything has been |
5 |
| -# pushed. If this script exits with a non-zero status nothing will be pushed. |
6 |
| -# |
7 |
| -# This hook is called with the following parameters: |
8 |
| -# |
9 |
| -# $1 -- Name of the remote to which the push is being done |
10 |
| -# $2 -- URL to which the push is being done |
11 |
| -# |
12 |
| -# If pushing without using a named remote those arguments will be equal. |
13 |
| -# |
14 |
| -# Information about the commits which are being pushed is supplied as lines to |
15 |
| -# the standard input in the form: |
16 |
| -# |
17 |
| -# <local ref> <local oid> <remote ref> <remote oid> |
| 3 | +# Pre-push hook script to run code quality checks and ensure consistency. |
18 | 4 | #
|
| 5 | +# This script will execute two custom scripts located in the `scripts/` directory: |
| 6 | +# 1. Enforce cargo version 1.75. |
| 7 | +# 2. clippy-on-all-workspaces.sh: Runs Clippy, tests, and formatting on all specified workspaces. |
| 8 | +# 3. sv2-header-check.sh: Ensures the `sv2.h` file generated by `build_header.sh` matches the |
| 9 | +# committed version. |
19 | 10 |
|
| 11 | +# Exit immediately if any command exits with a non-zero status and print each command before |
| 12 | +# executing it. |
20 | 13 | set -xe
|
21 | 14 |
|
22 |
| -remote="$1" |
23 |
| -url="$2" |
| 15 | +# Enforce minimum cargo version 1.75 |
| 16 | +REQUIRED_CARGO_VERSION="1.75.0" |
| 17 | +INSTALLED_CARGO_VERSION=$(cargo --version | awk '{print $2}') |
| 18 | + |
| 19 | +# Function to compare version numbers |
| 20 | +version_ge() { |
| 21 | + [ "$(printf '%s\n' "$@" | sort -V | head -n 1)" = "$2" ] |
| 22 | +} |
| 23 | + |
| 24 | +if ! version_ge "$INSTALLED_CARGO_VERSION" "$REQUIRED_CARGO_VERSION"; then |
| 25 | + echo "Error: Cargo version $REQUIRED_CARGO_VERSION or higher is required. Installed version is $INSTALLED_CARGO_VERSION." |
| 26 | + exit 1 |
| 27 | +fi |
| 28 | + |
| 29 | +# Enforce lock files are not changed during clippy, test, and rustfmt |
| 30 | +if ! cargo build --manifest-path=roles/Cargo.toml --locked; then |
| 31 | + echo "Error: Cargo.lock file in roles crate is out of date. Please run 'cargo update' in the roles crate." |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | + |
| 35 | +if ! cargo build --manifest-path=utils/Cargo.toml --locked; then |
| 36 | + echo "Error: Cargo.lock file in utils crate is out of date. Please run 'cargo update' in the utils crate." |
| 37 | + exit 1 |
| 38 | +fi |
| 39 | + |
| 40 | +echo "All builds succeeded with up-to-date Cargo.lock files." |
24 | 41 |
|
25 |
| -act --job message_generator_check --reuse -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:rust-latest |
26 |
| -act --job sv2_header_check --reuse -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:rust-latest |
27 |
| -act --job fmt --reuse -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:rust-latest |
28 |
| -act --job clippy-check --reuse -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:rust-latest |
29 |
| -act --job ci --reuse -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:rust-latest |
| 42 | +# Run clippy, test, and rustfmt on all workspaces |
| 43 | +sh ./scripts/clippy-fmt-and-test.sh |
| 44 | +if [ $? -ne 0 ]; then |
| 45 | + echo "Clippy checks or tests failed." |
| 46 | + exit 1 |
| 47 | +fi |
30 | 48 |
|
| 49 | +# Run sv2 header check |
| 50 | +sh ./scripts/sv2-header-check.sh |
| 51 | +if [ $? -ne 0 ]; then |
| 52 | + echo "SV2 header check failed." |
| 53 | + exit 1 |
| 54 | +fi |
31 | 55 |
|
| 56 | +echo "Pre-push checks passed successfully." |
0 commit comments