Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-push githook for fmt only + remove act #1039

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
35f38b0
Rm act + call fmt bash only
rrybarczyk Jul 5, 2024
bb9e88a
Use /bin/sh instead of /usr/bin/sh
rrybarczyk Jul 5, 2024
8e15323
Rm generated sv2 header if exists before run
rrybarczyk Jul 5, 2024
223157c
sv2-header-check cmts
rrybarczyk Jul 5, 2024
cc4668b
Ignore generated sv2 header
rrybarczyk Jul 5, 2024
e876a45
Merge branch 'dev' into 2024-07-pre-push-bash-fmt-only
rrybarczyk Aug 9, 2024
7df5df7
Rename to clippy-fmt-and-test sh
rrybarczyk Aug 9, 2024
3fce388
Enforce cargo v1.75
rrybarczyk Aug 9, 2024
9e89254
Merge branch 'dev' into 2024-07-pre-push-bash-fmt-only
rrybarczyk Aug 9, 2024
2c47248
Merge branch 'dev' into 2024-07-pre-push-bash-fmt-only
rrybarczyk Aug 9, 2024
8c9923f
Merge branch 'dev' into 2024-07-pre-push-bash-fmt-only
rrybarczyk Aug 15, 2024
8e35dba
Add sha1sum on system check
rrybarczyk Aug 15, 2024
5072c34
Enforce minimum version
rrybarczyk Aug 15, 2024
390b201
Enforce no change in lock files
rrybarczyk Aug 15, 2024
7221aa0
Only roles + utils have binaries w lock files
rrybarczyk Aug 15, 2024
9f90afe
Merge branch 'dev' into 2024-07-pre-push-bash-fmt-only
rrybarczyk Aug 15, 2024
64a28e3
Merge branch 'dev' into 2024-07-pre-push-bash-fmt-only
rrybarczyk Aug 19, 2024
cd05b60
Merge branch 'dev' into 2024-07-pre-push-bash-fmt-only
rrybarczyk Aug 23, 2024
43bd3b7
stop publishing some crates
plebhash Aug 23, 2024
8da5642
Merge pull request #1143 from plebhash/stop-publishing-some-crates
plebhash Aug 28, 2024
14fef4e
Merge branch 'dev' into 2024-07-pre-push-bash-fmt-only
rrybarczyk Aug 28, 2024
55db860
Merge branch 'main' into 2024-07-pre-push-bash-fmt-only
rrybarczyk Aug 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

rrybarczyk marked this conversation as resolved.
Show resolved Hide resolved
# 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
Loading