diff --git a/.githooks/pre-push b/.githooks/pre-push index f74e29cc8c..e9a8df4173 100755 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -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: -# -# +# 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." diff --git a/.github/workflows/release-libs.yaml b/.github/workflows/release-libs.yaml index 24e9251966..49418675d8 100644 --- a/.github/workflows/release-libs.yaml +++ b/.github/workflows/release-libs.yaml @@ -138,29 +138,4 @@ jobs: continue-on-error: true run: | cd roles/roles-utils/rpc - cargo publish - - name: Publish crate jd_client - continue-on-error: true - run: | - cd roles/jd-client - cargo publish - - name: Publish crate jd_server - continue-on-error: true - run: | - cd roles/jd-server - cargo publish - - name: Publish crate mining_proxy_sv2 - continue-on-error: true - run: | - cd roles/mining-proxy - cargo publish - - name: Publish crate pool_sv2 - continue-on-error: true - run: | - cd roles/pool - cargo publish - - name: Publish crate translator_sv2 - continue-on-error: true - run: | - cd roles/translator cargo publish \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6121487a25..af4c21e3e3 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ lcov.info cobertura.xml /roles/*/*-config.toml /examples/*/Cargo.lock +/scripts/sv2.h diff --git a/scripts/clippy-on-all-workspaces.sh b/scripts/clippy-fmt-and-test.sh similarity index 100% rename from scripts/clippy-on-all-workspaces.sh rename to scripts/clippy-fmt-and-test.sh diff --git a/scripts/sv2-header-check.sh b/scripts/sv2-header-check.sh index b39b0af540..7464009ebf 100755 --- a/scripts/sv2-header-check.sh +++ b/scripts/sv2-header-check.sh @@ -1,5 +1,5 @@ -#! /usr/bin/sh -# +#!/bin/sh + # This program ensures that the `sv2.h` file generated by `build_header.sh` for the submitted PR is # in sync with the `sv2.h` file committed to `protocols/v2/sv2-ffi`. If they are out of sync, the # GitHub Action will fail, preventing the PR from being merged. @@ -9,11 +9,17 @@ # (2) takes the SHA1 hash of the `sv2.h` file in `protocols/v2/sv2-ffi` # (3) executes `build_header.sh` to generate the `sv2.h` based on the contents of the PR # (4) takes the SHA1 hash of the `sv2.h` file generated by `build_header.sh` -# (5) compares the hashes of each `sv2.h`, if they are equal then the GitHub Action passes, otherwise -# the GitHub Action fails -# -# This script is called by `.github/workflows/sv2-header-check.yaml` on every PR onto the main branch. +# (5) compares the hashes of each `sv2.h`, if they are equal then the GitHub Action passes, +# otherwise the GitHub Action fails # +# This script is called by `.github/workflows/sv2-header-check.yaml` on every PR onto the main +# branch. + +# Check if sha1sum is available on the system +if ! command -v sha1sum >/dev/null 2>&1; then + echo "Warning: sha1sum is not installed on this system." + exit 1 +fi cargo install --version 0.20.0 cbindgen @@ -22,6 +28,9 @@ set -ex # cbindgen -V echo $PWD +# Remove the sv2.h generated from previous runs if exists +rm -f scripts/sv2.h + cd protocols/v2/sv2-ffi SHA1_1=$(sha1sum sv2.h) cd ../../../scripts