mirror of
https://github.com/luxfi/consensus.git
synced 2026-09-24 00:26:58 +00:00
139 lines
3.8 KiB
Bash
Executable File
139 lines
3.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
echo "๐ Consolidating top-level packages..."
|
|
echo "======================================"
|
|
|
|
MOD="github.com/luxfi/consensus"
|
|
|
|
# 1. Move test-related packages to test/
|
|
echo "๐ฆ Moving e2e/ โ test/e2e/"
|
|
if [ -d "e2e" ] && [ ! -d "test/e2e" ]; then
|
|
git mv e2e test/
|
|
fi
|
|
|
|
echo "๐ฆ Moving consensustest/ โ test/helpers/"
|
|
if [ -d "consensustest" ]; then
|
|
mkdir -p test/helpers
|
|
git mv consensustest/* test/helpers/ 2>/dev/null || cp -r consensustest/* test/helpers/
|
|
rm -rf consensustest
|
|
fi
|
|
|
|
# 2. Move core primitives to core/
|
|
echo "๐ฆ Moving block/ โ core/block/"
|
|
if [ -d "block" ] && [ ! -d "core/block" ]; then
|
|
git mv block core/
|
|
fi
|
|
|
|
echo "๐ฆ Moving choices/ โ core/choices/"
|
|
if [ -d "choices" ] && [ ! -d "core/choices" ]; then
|
|
git mv choices core/
|
|
fi
|
|
|
|
echo "๐ฆ Moving dag/ โ core/dag/"
|
|
if [ -d "dag" ] && [ ! -d "core/dag" ]; then
|
|
git mv dag core/
|
|
fi
|
|
|
|
echo "๐ฆ Moving verify/ โ core/verify/"
|
|
if [ -d "verify" ] && [ ! -d "core/verify" ]; then
|
|
git mv verify core/
|
|
fi
|
|
|
|
echo "๐ฆ Moving router/ โ core/router/"
|
|
if [ -d "router" ] && [ ! -d "core/router" ]; then
|
|
git mv router core/
|
|
fi
|
|
|
|
# 3. Handle types/ (merge with existing core/types.go)
|
|
echo "๐ฆ Consolidating types/ into core/types/"
|
|
if [ -d "types" ]; then
|
|
# Move types directory contents to core/types/
|
|
if [ ! -d "core/types" ]; then
|
|
git mv types core/
|
|
else
|
|
# Merge if core/types already exists
|
|
for f in types/*; do
|
|
filename=$(basename "$f")
|
|
if [ -f "core/types/$filename" ]; then
|
|
echo "โ ๏ธ $filename already exists in core/types, skipping"
|
|
else
|
|
git mv "$f" core/types/
|
|
fi
|
|
done
|
|
rmdir types 2>/dev/null || rm -rf types
|
|
fi
|
|
fi
|
|
|
|
# 4. Move utilities to utils/
|
|
echo "๐ฆ Moving codec/ โ utils/codec/"
|
|
if [ -d "codec" ] && [ ! -d "utils/codec" ]; then
|
|
git mv codec utils/
|
|
fi
|
|
|
|
echo "๐ฆ Moving witness/ โ utils/witness/"
|
|
if [ -d "witness" ] && [ ! -d "utils/witness" ]; then
|
|
git mv witness utils/
|
|
fi
|
|
|
|
# 5. Move validator-related to validator/
|
|
echo "๐ฆ Moving uptime/ โ validator/uptime/"
|
|
if [ -d "uptime" ] && [ ! -d "validator/uptime" ]; then
|
|
git mv uptime validator/
|
|
fi
|
|
|
|
# 6. Update import paths
|
|
echo "๐ Updating import paths..."
|
|
|
|
find . -name "*.go" -type f -not -path "./.git/*" -not -path "./node/*" -exec sed -i '' \
|
|
-e "s|\"$MOD/e2e|\"$MOD/test/e2e|g" \
|
|
-e "s|\"$MOD/consensustest|\"$MOD/test/helpers|g" \
|
|
-e "s|\"$MOD/block\"|\"$MOD/core/block\"|g" \
|
|
-e "s|\"$MOD/choices\"|\"$MOD/core/choices\"|g" \
|
|
-e "s|\"$MOD/dag\"|\"$MOD/core/dag\"|g" \
|
|
-e "s|\"$MOD/verify\"|\"$MOD/core/verify\"|g" \
|
|
-e "s|\"$MOD/router\"|\"$MOD/core/router\"|g" \
|
|
-e "s|\"$MOD/types\"|\"$MOD/core/types\"|g" \
|
|
-e "s|\"$MOD/codec\"|\"$MOD/utils/codec\"|g" \
|
|
-e "s|\"$MOD/witness\"|\"$MOD/utils/witness\"|g" \
|
|
-e "s|\"$MOD/uptime|\"$MOD/validator/uptime|g" \
|
|
{} \;
|
|
|
|
# 7. Tidy and format
|
|
echo "๐งน Tidying and formatting..."
|
|
go mod tidy
|
|
gofmt -w .
|
|
|
|
# 8. Run tests
|
|
echo "๐งช Running tests..."
|
|
if go test ./... -count=1 -short; then
|
|
echo "โ
All tests passing"
|
|
else
|
|
echo "โ ๏ธ Some tests failed - review needed"
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
echo "======================================"
|
|
echo "โ
Package consolidation complete!"
|
|
echo ""
|
|
echo "Test packages โ test/:"
|
|
echo " - e2e/ โ test/e2e/"
|
|
echo " - consensustest/ โ test/helpers/"
|
|
echo ""
|
|
echo "Core primitives โ core/:"
|
|
echo " - block/ โ core/block/"
|
|
echo " - choices/ โ core/choices/"
|
|
echo " - dag/ โ core/dag/"
|
|
echo " - verify/ โ core/verify/"
|
|
echo " - router/ โ core/router/"
|
|
echo " - types/ โ core/types/"
|
|
echo ""
|
|
echo "Utilities โ utils/:"
|
|
echo " - codec/ โ utils/codec/"
|
|
echo " - witness/ โ utils/witness/"
|
|
echo ""
|
|
echo "Validator-related โ validator/:"
|
|
echo " - uptime/ โ validator/uptime/"
|
|
echo ""
|