-
Notifications
You must be signed in to change notification settings - Fork 127
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 #1039 from rrybarczyk/2024-07-pre-push-bash-fmt-only
`pre-push` githook for fmt only + remove `act`
- Loading branch information
Showing
5 changed files
with
63 additions
and
53 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 |
---|---|---|
@@ -1,31 +1,56 @@ | ||
#!/bin/sh | ||
|
||
# An example hook script to verify what is about to be pushed. Called by "git | ||
# push" after it has checked the remote status, but before anything has been | ||
# pushed. If this script exits with a non-zero status nothing will be pushed. | ||
# | ||
# This hook is called with the following parameters: | ||
# | ||
# $1 -- Name of the remote to which the push is being done | ||
# $2 -- URL to which the push is being done | ||
# | ||
# If pushing without using a named remote those arguments will be equal. | ||
# | ||
# Information about the commits which are being pushed is supplied as lines to | ||
# the standard input in the form: | ||
# | ||
# <local ref> <local oid> <remote ref> <remote oid> | ||
# Pre-push hook script to run code quality checks and ensure consistency. | ||
# | ||
# This script will execute two custom scripts located in the `scripts/` directory: | ||
# 1. Enforce cargo version 1.75. | ||
# 2. clippy-on-all-workspaces.sh: Runs Clippy, tests, and formatting on all specified workspaces. | ||
# 3. sv2-header-check.sh: Ensures the `sv2.h` file generated by `build_header.sh` matches the | ||
# committed version. | ||
|
||
# Exit immediately if any command exits with a non-zero status and print each command before | ||
# executing it. | ||
set -xe | ||
|
||
remote="$1" | ||
url="$2" | ||
# Enforce minimum cargo version 1.75 | ||
REQUIRED_CARGO_VERSION="1.75.0" | ||
INSTALLED_CARGO_VERSION=$(cargo --version | awk '{print $2}') | ||
|
||
# Function to compare version numbers | ||
version_ge() { | ||
[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" = "$2" ] | ||
} | ||
|
||
if ! version_ge "$INSTALLED_CARGO_VERSION" "$REQUIRED_CARGO_VERSION"; then | ||
echo "Error: Cargo version $REQUIRED_CARGO_VERSION or higher is required. Installed version is $INSTALLED_CARGO_VERSION." | ||
exit 1 | ||
fi | ||
|
||
# Enforce lock files are not changed during clippy, test, and rustfmt | ||
if ! cargo build --manifest-path=roles/Cargo.toml --locked; then | ||
echo "Error: Cargo.lock file in roles crate is out of date. Please run 'cargo update' in the roles crate." | ||
exit 1 | ||
fi | ||
|
||
if ! cargo build --manifest-path=utils/Cargo.toml --locked; then | ||
echo "Error: Cargo.lock file in utils crate is out of date. Please run 'cargo update' in the utils crate." | ||
exit 1 | ||
fi | ||
|
||
echo "All builds succeeded with up-to-date Cargo.lock files." | ||
|
||
act --job message_generator_check --reuse -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:rust-latest | ||
act --job sv2_header_check --reuse -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:rust-latest | ||
act --job fmt --reuse -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:rust-latest | ||
act --job clippy-check --reuse -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:rust-latest | ||
act --job ci --reuse -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:rust-latest | ||
# Run clippy, test, and rustfmt on all workspaces | ||
sh ./scripts/clippy-fmt-and-test.sh | ||
if [ $? -ne 0 ]; then | ||
echo "Clippy checks or tests failed." | ||
exit 1 | ||
fi | ||
|
||
# Run sv2 header check | ||
sh ./scripts/sv2-header-check.sh | ||
if [ $? -ne 0 ]; then | ||
echo "SV2 header check failed." | ||
exit 1 | ||
fi | ||
|
||
echo "Pre-push checks passed successfully." |
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
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 |
---|---|---|
|
@@ -15,3 +15,4 @@ lcov.info | |
cobertura.xml | ||
/roles/*/*-config.toml | ||
/examples/*/Cargo.lock | ||
/scripts/sv2.h |
File renamed without changes.
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