Skip to content

Commit

Permalink
Merge branch 'main' into 2024-08-13-refactor-jdserver
Browse files Browse the repository at this point in the history
  • Loading branch information
plebhash committed Aug 30, 2024
2 parents 006b838 + 4173c4d commit ef254e1
Show file tree
Hide file tree
Showing 20 changed files with 802 additions and 3,464 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."
82 changes: 82 additions & 0 deletions .github/workflows/auto-rebase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Auto Rebase

on:
push:
branches:
- main
workflow_dispatch:

jobs:
rebase-outdated-prs:
runs-on: ubuntu-latest
steps:
- uses: tibdex/github-app-token@v1
id: generate-token
with:
app_id: ${{ secrets.AUTO_REBASE_APP_ID}}
private_key: ${{ secrets.AUTO_REBASE_APP_PRIVATE_KEY }}

- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ steps.generate-token.outputs.token }}
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: ${{ steps.generate-token.outputs.token }}

- 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 user.name "$PR_AUTHOR_NAME"
git config 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: ${{ steps.generate-token.outputs.token }}
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
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.idea
*/**/target
/protocols/guix-example/guix-example.h
/protocols/Cargo.lock
/benches/Cargo.lock
/ignore
/vendor/ed25519-dalek/target
/utils/buffer/target
Expand All @@ -15,3 +17,4 @@ lcov.info
cobertura.xml
/roles/*/*-config.toml
/examples/*/Cargo.lock
/scripts/sv2.h
Empty file added CHANGELOG.md
Empty file.
11 changes: 9 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,18 @@ The SRI project follows an open contributor model, where anyone is welcome to co

`cargo fmt`: this command formats your code according to the project's style guidelines. Make sure to run this command to ensure consistency in code formatting.

5. **Submit a Pull Request:** once you're satisfied with your changes, submit a pull request to the original SRI repository. Provide a clear and concise description of the changes you've made. If your pull request addresses an existing issue, reference the issue number in the description. In order to contribute to the protocol implementation, every PR must be opened against `dev` branch. To better understand which is the SRI branches structure, please have a look [here](https://github.com/stratum-mining/stratum/blob/main/RELEASE.md#principal-branches).
Alternatively, you should consider enabling git pre-push hooks:
```
$ git config core.hooksPath .githooks
```

This will make your `git push` commands take a bit longer. But it can also save you some time with potential CI issues that could come up in your PR.

5. **Submit a Pull Request:** once you're satisfied with your changes, submit a pull request to the original SRI repository. Provide a clear and concise description of the changes you've made. If your pull request addresses an existing issue, reference the issue number in the description. In order to contribute to the protocol implementation, every PR must be opened against `main` branch.

6. **Review and Iterate**

7. **Merge and Close:** Once your pull request has been approved and all discussions have been resolved, a project maintainer will merge your changes into the `dev` branch. Your contribution will then be officially part of the project. The pull request will be closed, marking the completion of your contribution.
7. **Merge and Close:** Once your pull request has been approved and all discussions have been resolved, a project maintainer will merge your changes into the `main` branch. Your contribution will then be officially part of the project. The pull request will be closed, marking the completion of your contribution.

### Your First Code Contribution
>In order to contribute, a basic learning about git and github is needed. If you're not familiar with them, have a look at https://docs.github.com/en/get-started/start-your-journey/git-and-github-learning-resources to dig into and learn how to use them.
Expand Down
26 changes: 0 additions & 26 deletions README-DEV.md

This file was deleted.

Loading

0 comments on commit ef254e1

Please sign in to comment.