Skip to content

Commit

Permalink
Merge pull request #1039 from rrybarczyk/2024-07-pre-push-bash-fmt-only
Browse files Browse the repository at this point in the history
`pre-push` githook for fmt only + remove `act`
  • Loading branch information
plebhash authored Aug 28, 2024
2 parents 61616b9 + 55db860 commit 1c5e464
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 53 deletions.
69 changes: 47 additions & 22 deletions .githooks/pre-push
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."
25 changes: 0 additions & 25 deletions .github/workflows/release-libs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ lcov.info
cobertura.xml
/roles/*/*-config.toml
/examples/*/Cargo.lock
/scripts/sv2.h
File renamed without changes.
21 changes: 15 additions & 6 deletions scripts/sv2-header-check.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 1c5e464

Please sign in to comment.