Skip to content

Commit 1c5e464

Browse files
authored
Merge pull request #1039 from rrybarczyk/2024-07-pre-push-bash-fmt-only
`pre-push` githook for fmt only + remove `act`
2 parents 61616b9 + 55db860 commit 1c5e464

File tree

5 files changed

+63
-53
lines changed

5 files changed

+63
-53
lines changed

Diff for: .githooks/pre-push

+47-22
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,56 @@
11
#!/bin/sh
22

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.
184
#
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.
1910

11+
# Exit immediately if any command exits with a non-zero status and print each command before
12+
# executing it.
2013
set -xe
2114

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."
2441

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
3048

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
3155

56+
echo "Pre-push checks passed successfully."

Diff for: .github/workflows/release-libs.yaml

-25
Original file line numberDiff line numberDiff line change
@@ -138,29 +138,4 @@ jobs:
138138
continue-on-error: true
139139
run: |
140140
cd roles/roles-utils/rpc
141-
cargo publish
142-
- name: Publish crate jd_client
143-
continue-on-error: true
144-
run: |
145-
cd roles/jd-client
146-
cargo publish
147-
- name: Publish crate jd_server
148-
continue-on-error: true
149-
run: |
150-
cd roles/jd-server
151-
cargo publish
152-
- name: Publish crate mining_proxy_sv2
153-
continue-on-error: true
154-
run: |
155-
cd roles/mining-proxy
156-
cargo publish
157-
- name: Publish crate pool_sv2
158-
continue-on-error: true
159-
run: |
160-
cd roles/pool
161-
cargo publish
162-
- name: Publish crate translator_sv2
163-
continue-on-error: true
164-
run: |
165-
cd roles/translator
166141
cargo publish

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ lcov.info
1515
cobertura.xml
1616
/roles/*/*-config.toml
1717
/examples/*/Cargo.lock
18+
/scripts/sv2.h
File renamed without changes.

Diff for: scripts/sv2-header-check.sh

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#! /usr/bin/sh
2-
#
1+
#!/bin/sh
2+
33
# This program ensures that the `sv2.h` file generated by `build_header.sh` for the submitted PR is
44
# in sync with the `sv2.h` file committed to `protocols/v2/sv2-ffi`. If they are out of sync, the
55
# GitHub Action will fail, preventing the PR from being merged.
@@ -9,11 +9,17 @@
99
# (2) takes the SHA1 hash of the `sv2.h` file in `protocols/v2/sv2-ffi`
1010
# (3) executes `build_header.sh` to generate the `sv2.h` based on the contents of the PR
1111
# (4) takes the SHA1 hash of the `sv2.h` file generated by `build_header.sh`
12-
# (5) compares the hashes of each `sv2.h`, if they are equal then the GitHub Action passes, otherwise
13-
# the GitHub Action fails
14-
#
15-
# This script is called by `.github/workflows/sv2-header-check.yaml` on every PR onto the main branch.
12+
# (5) compares the hashes of each `sv2.h`, if they are equal then the GitHub Action passes,
13+
# otherwise the GitHub Action fails
1614
#
15+
# This script is called by `.github/workflows/sv2-header-check.yaml` on every PR onto the main
16+
# branch.
17+
18+
# Check if sha1sum is available on the system
19+
if ! command -v sha1sum >/dev/null 2>&1; then
20+
echo "Warning: sha1sum is not installed on this system."
21+
exit 1
22+
fi
1723

1824
cargo install --version 0.20.0 cbindgen
1925

@@ -22,6 +28,9 @@ set -ex
2228
# cbindgen -V
2329

2430
echo $PWD
31+
# Remove the sv2.h generated from previous runs if exists
32+
rm -f scripts/sv2.h
33+
2534
cd protocols/v2/sv2-ffi
2635
SHA1_1=$(sha1sum sv2.h)
2736
cd ../../../scripts

0 commit comments

Comments
 (0)