Skip to content

Commit 29a7e57

Browse files
committed
added justfile
1 parent bb0d238 commit 29a7e57

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

β€Žexamples/justfileβ€Ž

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Polkadot Bulletin Chain - Just Commands
2+
# Install just: brew install just
3+
# Run `just --list` to see all available commands
4+
5+
# Default recipe - run the complete PAPI workflow test
6+
default: authorize-and-store
7+
8+
# Build the bulletin chain node in release mode
9+
build:
10+
cargo build --release -p polkadot-bulletin-chain
11+
12+
# Install JavaScript dependencies
13+
npm-install:
14+
npm install
15+
16+
# Clean build artifacts
17+
clean:
18+
cargo clean
19+
20+
# Test the complete workflow (builds, starts services, runs example, shuts down services)
21+
# Parameters: api=[papi|pjs] - choose between Polkadot API (papi) or Polkadot JS (pjs)
22+
authorize-and-store api="papi": build npm-install
23+
#!/usr/bin/env bash
24+
set -e
25+
26+
API_TYPE="{{ api }}"
27+
28+
if [[ "$API_TYPE" != "papi" && "$API_TYPE" != "pjs" ]]; then
29+
echo "❌ Error: api parameter must be 'papi' or 'pjs'"
30+
exit 1
31+
fi
32+
33+
echo "πŸš€ Starting $API_TYPE workflow test..."
34+
echo ""
35+
36+
# Check if IPFS is available
37+
if ! command -v ipfs &> /dev/null; then
38+
echo "❌ IPFS not found. Using local kubo binary..."
39+
IPFS_CMD="./kubo/ipfs"
40+
if [ ! -f "$IPFS_CMD" ]; then
41+
echo "❌ Error: Neither system IPFS nor ./kubo/ipfs found."
42+
echo "Please install IPFS or download kubo to ./kubo/"
43+
exit 1
44+
fi
45+
else
46+
IPFS_CMD="ipfs"
47+
fi
48+
49+
# Initialize IPFS if needed
50+
if [ ! -d ~/.ipfs ]; then
51+
echo "πŸ“¦ Initializing IPFS..."
52+
$IPFS_CMD init
53+
fi
54+
55+
# Start IPFS daemon in background
56+
echo "πŸ“‘ Starting IPFS daemon..."
57+
$IPFS_CMD daemon > /tmp/ipfs-daemon.log 2>&1 &
58+
IPFS_PID=$!
59+
echo " IPFS PID: $IPFS_PID"
60+
sleep 2
61+
62+
# Start zombienet in background
63+
echo "⚑ Starting Bulletin chain with zombienet..."
64+
POLKADOT_BULLETIN_BINARY_PATH=../target/release/polkadot-bulletin-chain ./zombienet-macos-arm64 -p native spawn ./zombienet/bulletin-polkadot-local.toml > /tmp/zombienet.log 2>&1 &
65+
ZOMBIENET_PID=$!
66+
echo " Zombienet PID: $ZOMBIENET_PID"
67+
echo " Waiting for chain to start (15 seconds)..."
68+
sleep 15
69+
70+
# Start IPFS reconnect script in background
71+
echo "πŸ”„ Starting IPFS reconnect script..."
72+
./scripts/ipfs-reconnect-solo.sh > /tmp/ipfs-reconnect.log 2>&1 &
73+
RECONNECT_PID=$!
74+
echo " Reconnect PID: $RECONNECT_PID"
75+
sleep 2
76+
77+
# Generate PAPI descriptors (only for papi)
78+
if [ "$API_TYPE" == "papi" ]; then
79+
echo "πŸ”§ Generating PAPI descriptors..."
80+
npm run papi:generate
81+
fi
82+
83+
# Determine which example to run
84+
if [ "$API_TYPE" == "papi" ]; then
85+
EXAMPLE_FILE="authorize_and_store_papi.js"
86+
else
87+
EXAMPLE_FILE="authorize_and_store.js"
88+
fi
89+
90+
# Run the example
91+
echo ""
92+
echo "🎯 Running $EXAMPLE_FILE example..."
93+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
94+
node $EXAMPLE_FILE
95+
EXAMPLE_EXIT=$?
96+
97+
echo ""
98+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
99+
if [ $EXAMPLE_EXIT -eq 0 ]; then
100+
echo "βœ… Example completed successfully!"
101+
else
102+
echo "❌ Example failed with exit code $EXAMPLE_EXIT"
103+
fi
104+
105+
echo ""
106+
echo "πŸ“ Logs available at:"
107+
echo " /tmp/ipfs-daemon.log"
108+
echo " /tmp/zombienet.log"
109+
echo " /tmp/ipfs-reconnect.log"
110+
111+
# Clean up background processes
112+
echo "🧹 Cleaning up background processes..."
113+
kill $IPFS_PID $ZOMBIENET_PID $RECONNECT_PID 2>/dev/null || true
114+
115+
116+
exit $EXAMPLE_EXIT

0 commit comments

Comments
Β (0)