chore(git): add comprehensive Git workflow configuration and documentation
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
269
scripts/git-workflow.sh
Executable file
269
scripts/git-workflow.sh
Executable file
@@ -0,0 +1,269 @@
|
||||
#!/bin/bash
|
||||
|
||||
# git-workflow.sh - Helper script for Git workflow in MEV Bot project
|
||||
|
||||
set -e # Exit on any error
|
||||
|
||||
echo "MEV Bot Git Workflow Helper"
|
||||
echo "=========================="
|
||||
|
||||
# Function to display usage
|
||||
usage() {
|
||||
echo "Usage: $0 [command]"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
echo " status - Show git status"
|
||||
echo " commit - Commit changes with conventional commits"
|
||||
echo " push - Push changes with pre-push checks"
|
||||
echo " feature NAME - Create new feature branch"
|
||||
echo " fix NAME - Create new fix branch"
|
||||
echo " sync - Sync current branch with develop"
|
||||
echo " pr - Prepare for pull request"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 commit"
|
||||
echo " $0 feature add-market-scanner"
|
||||
echo " $0 fix resolve-memory-leak"
|
||||
}
|
||||
|
||||
# Function to check if we're in the right directory
|
||||
check_directory() {
|
||||
if [ ! -f "go.mod" ]; then
|
||||
echo "Error: This script must be run from the project root directory"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to show git status
|
||||
show_status() {
|
||||
echo "Git Status:"
|
||||
echo "==========="
|
||||
git status
|
||||
}
|
||||
|
||||
# Function to commit changes
|
||||
commit_changes() {
|
||||
echo "Committing changes..."
|
||||
echo "Available file types to add:"
|
||||
|
||||
# Show what files are modified
|
||||
if [ -n "$(git diff --name-only)" ]; then
|
||||
echo "Modified files:"
|
||||
git diff --name-only
|
||||
fi
|
||||
|
||||
if [ -n "$(git diff --name-only --cached)" ]; then
|
||||
echo "Staged files:"
|
||||
git diff --name-only --cached
|
||||
fi
|
||||
|
||||
# Ask user what to do
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo "1) Add all changes and commit"
|
||||
echo "2) Add specific files and commit"
|
||||
echo "3) Commit already staged changes"
|
||||
echo "4) Cancel"
|
||||
|
||||
read -p "Choose option (1-4): " choice
|
||||
|
||||
case $choice in
|
||||
1)
|
||||
git add .
|
||||
;;
|
||||
2)
|
||||
echo "Enter files to add (space separated):"
|
||||
read files
|
||||
git add $files
|
||||
;;
|
||||
3)
|
||||
# Use already staged files
|
||||
;;
|
||||
4)
|
||||
echo "Commit cancelled"
|
||||
return
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option"
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
# Run pre-commit hook manually to show what it does
|
||||
echo "Running pre-commit checks..."
|
||||
.git/hooks/pre-commit
|
||||
|
||||
# Get commit message
|
||||
echo ""
|
||||
echo "Enter commit message (follow conventional commits format):"
|
||||
echo "Examples:"
|
||||
echo " feat(market): add new arbitrage detection algorithm"
|
||||
echo " fix(parser): resolve race condition in transaction parsing"
|
||||
echo " perf(pricing): optimize Uniswap V3 calculations"
|
||||
read -p "Commit message: " commit_msg
|
||||
|
||||
if [ -n "$commit_msg" ]; then
|
||||
git commit -m "$commit_msg"
|
||||
echo "Changes committed successfully!"
|
||||
else
|
||||
echo "No commit message provided. Commit cancelled."
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to push changes
|
||||
push_changes() {
|
||||
echo "Pushing changes..."
|
||||
|
||||
# Run pre-push hook manually to show what it does
|
||||
echo "Running pre-push checks..."
|
||||
.git/hooks/pre-push
|
||||
|
||||
# Get current branch
|
||||
branch=$(git rev-parse --abbrev-ref HEAD)
|
||||
|
||||
# Push to origin
|
||||
git push -u origin $branch
|
||||
echo "Changes pushed successfully!"
|
||||
}
|
||||
|
||||
# Function to create feature branch
|
||||
create_feature_branch() {
|
||||
local feature_name=$1
|
||||
|
||||
if [ -z "$feature_name" ]; then
|
||||
echo "Error: Feature name required"
|
||||
echo "Usage: $0 feature <feature-name>"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "Creating feature branch: feature/$feature_name"
|
||||
|
||||
# Switch to develop and pull latest
|
||||
git checkout develop
|
||||
git pull origin develop
|
||||
|
||||
# Create new feature branch
|
||||
git checkout -b feature/$feature_name
|
||||
echo "Feature branch 'feature/$feature_name' created and switched to."
|
||||
}
|
||||
|
||||
# Function to create fix branch
|
||||
create_fix_branch() {
|
||||
local fix_name=$1
|
||||
|
||||
if [ -z "$fix_name" ]; then
|
||||
echo "Error: Fix name required"
|
||||
echo "Usage: $0 fix <fix-name>"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "Creating fix branch: fix/$fix_name"
|
||||
|
||||
# Switch to develop and pull latest
|
||||
git checkout develop
|
||||
git pull origin develop
|
||||
|
||||
# Create new fix branch
|
||||
git checkout -b fix/$fix_name
|
||||
echo "Fix branch 'fix/$fix_name' created and switched to."
|
||||
}
|
||||
|
||||
# Function to sync with develop
|
||||
sync_with_develop() {
|
||||
echo "Syncing current branch with develop..."
|
||||
|
||||
# Get current branch
|
||||
current_branch=$(git rev-parse --abbrev-ref HEAD)
|
||||
|
||||
# Stash any changes
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
echo "Stashing changes..."
|
||||
git stash
|
||||
stashed=true
|
||||
fi
|
||||
|
||||
# Switch to develop and pull
|
||||
git checkout develop
|
||||
git pull origin develop
|
||||
|
||||
# Switch back to original branch and rebase
|
||||
git checkout $current_branch
|
||||
git rebase develop
|
||||
|
||||
# Pop stash if we had one
|
||||
if [ "$stashed" = true ]; then
|
||||
echo "Restoring stashed changes..."
|
||||
git stash pop
|
||||
fi
|
||||
|
||||
echo "Sync completed!"
|
||||
}
|
||||
|
||||
# Function to prepare for PR
|
||||
prepare_pr() {
|
||||
echo "Preparing for Pull Request..."
|
||||
|
||||
# Run tests
|
||||
echo "Running tests..."
|
||||
go test ./...
|
||||
|
||||
# Run linter if available
|
||||
if command -v golangci-lint >/dev/null 2>&1; then
|
||||
echo "Running linter..."
|
||||
golangci-lint run
|
||||
else
|
||||
echo "golangci-lint not found. Skipping linting."
|
||||
fi
|
||||
|
||||
# Check git status
|
||||
echo ""
|
||||
echo "Git status:"
|
||||
git status
|
||||
|
||||
echo ""
|
||||
echo "Ready for Pull Request!"
|
||||
echo "Next steps:"
|
||||
echo "1. Push your branch: git push -u origin \$(git rev-parse --abbrev-ref HEAD)"
|
||||
echo "2. Create PR on GitHub/GitLab"
|
||||
echo "3. Request review from team members"
|
||||
}
|
||||
|
||||
# Main script logic
|
||||
check_directory
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
usage
|
||||
exit 0
|
||||
fi
|
||||
|
||||
COMMAND=$1
|
||||
shift
|
||||
|
||||
case $COMMAND in
|
||||
status)
|
||||
show_status
|
||||
;;
|
||||
commit)
|
||||
commit_changes
|
||||
;;
|
||||
push)
|
||||
push_changes
|
||||
;;
|
||||
feature)
|
||||
create_feature_branch $1
|
||||
;;
|
||||
fix)
|
||||
create_fix_branch $1
|
||||
;;
|
||||
sync)
|
||||
sync_with_develop
|
||||
;;
|
||||
pr)
|
||||
prepare_pr
|
||||
;;
|
||||
*)
|
||||
echo "Unknown command: $COMMAND"
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user