Skip to content

Commit

Permalink
Merge branch 'stratum-mining:main' into doc-noise-sv2
Browse files Browse the repository at this point in the history
  • Loading branch information
Shourya742 authored Sep 13, 2024
2 parents 11b5d76 + 8da5e5f commit 08bb99d
Show file tree
Hide file tree
Showing 38 changed files with 1,162 additions and 4,200 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."
77 changes: 77 additions & 0 deletions .github/workflows/auto-rebase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Auto Rebase

on:
push:
branches:
- main
workflow_dispatch:

jobs:
rebase-outdated-prs:
runs-on: ubuntu-latest
steps:

- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}
fetch-depth: 0 # Fetch full history to have the entire commit history

- name: Fetch open pull requests with label
run: |
gh auth setup-git
gh pr list --state open --label "ready-to-be-merged" --json number,headRepositoryOwner,headRefName --jq '.[] | "\(.number) \(.headRepositoryOwner.login) \(.headRefName)"' > pr_details.txt
env:
GITHUB_TOKEN: ${{ secrets.PAT }}

- name: Rebase pull requests
run: |
while read pr_number pr_owner pr_branch; do
echo "Processing PR #$pr_number"
# Add the contributor's fork as a remote
git remote add contributor https://github.com/$pr_owner/$(gh repo view --json name -q '.name').git
# Fetch the contributor's branches
git fetch contributor
# Create a unique branch name for this PR
unique_branch_name="contributor-branch-$pr_number"
# Checkout the branch from the contributor's fork
git checkout -b $unique_branch_name contributor/$pr_branch
# Set the committer name and email to match the PR author
PR_AUTHOR_NAME=$(gh pr view $pr_number --json author --jq '.author.login')
PR_AUTHOR_EMAIL="${PR_AUTHOR_NAME}@users.noreply.github.com"
git config --global user.name "$PR_AUTHOR_NAME"
git config --global user.email "$PR_AUTHOR_EMAIL"
# Rebase the branch on top of the main branch
git fetch origin main
if ! git rebase origin/main; then
echo "Conflict detected. Aborting rebase and continuing."
git rebase --abort
# Post a comment on the PR to notify the author about the conflict
gh pr comment $pr_number --body "Hey @$PR_AUTHOR_NAME, your PR cannot be rebased due to conflicts. Could you resolve them, please?"
continue
fi
# Push the rebased branch back to the contributor's fork
git push --force-with-lease contributor $unique_branch_name:$pr_branch
# Remove the remote
git remote remove contributor
# Ensure we are not on the branch to be deleted
git checkout main
# Delete the local unique branch
git branch -D $unique_branch_name
done < pr_details.txt
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
30 changes: 30 additions & 0 deletions .github/workflows/lockfiles.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Lockfiles

# Trigger the workflow on push or pull request events for the dev and main branches
on:
push:
branches:
- dev
- main
pull_request:
branches:
- dev
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Build with locked dependencies
run: |
cargo build --manifest-path=roles/Cargo.toml --locked
cargo build --manifest-path=utils/Cargo.toml --locked
1 change: 1 addition & 0 deletions .github/workflows/mg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ jobs:

sv1-test:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
Loading

0 comments on commit 08bb99d

Please sign in to comment.