Skip to content

Commit fa67370

Browse files
committed
WIP: split justfiles into sub-justs
1 parent 15f764f commit fa67370

File tree

1 file changed

+143
-27
lines changed

1 file changed

+143
-27
lines changed

examples/justfile

Lines changed: 143 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,20 @@
1111
# just authorize-and-store papi
1212
# just authorize-and-store pjs
1313
#
14+
# 3. Run individual commands for manual testing:
15+
# just ipfs-init # Initialize IPFS (if needed)
16+
# just ipfs-start # Start IPFS daemon
17+
# just ipfs-connect # Connect to IPFS nodes
18+
# just bulletin-zombienet-start # Start zombienet
19+
# just ipfs-reconnect-start # Start IPFS reconnect script
20+
# just papi-generate # Generate PAPI descriptors
21+
# just run-example papi # Run example with PAPI or PJS
22+
# just stop-services # Stop all services
23+
#
1424
# (Use 'papi' for Polkadot API or 'pjs' for Polkadot JS)
15-
# The 'authorize-and-store' recipe will build the chain and install npm dependencies as needed.
1625

26+
# PID file locations
27+
PID_DIR := "/tmp/bulletin-pids"
1728

1829
# Default recipe - run the complete PAPI workflow test
1930
default: authorize-and-store
@@ -26,25 +37,13 @@ build:
2637
npm-install:
2738
npm install
2839

29-
# Test the complete workflow (builds, starts services, runs example, shuts down services)
30-
# Parameters: api=[papi|pjs] - choose between Polkadot API (papi) or Polkadot JS (pjs)
31-
authorize-and-store api="papi": build npm-install
40+
# Initialize IPFS if not already initialized
41+
ipfs-init:
3242
#!/usr/bin/env bash
3343
set -e
3444

35-
API_TYPE="{{ api }}"
36-
37-
if [[ "$API_TYPE" != "papi" && "$API_TYPE" != "pjs" ]]; then
38-
echo "❌ Error: api parameter must be 'papi' or 'pjs'"
39-
exit 1
40-
fi
41-
42-
echo "🚀 Starting $API_TYPE workflow test..."
43-
echo ""
44-
4545
# Check if IPFS is available
4646
if ! command -v ipfs &> /dev/null; then
47-
echo "❌ IPFS not found. Using local kubo binary..."
4847
IPFS_CMD="./kubo/ipfs"
4948
if [ ! -f "$IPFS_CMD" ]; then
5049
echo "❌ Error: Neither system IPFS nor ./kubo/ipfs found."
@@ -59,38 +58,98 @@ authorize-and-store api="papi": build npm-install
5958
if [ ! -d ~/.ipfs ]; then
6059
echo "📦 Initializing IPFS..."
6160
$IPFS_CMD init
61+
else
62+
echo "✅ IPFS already initialized"
63+
fi
64+
65+
# Start IPFS daemon in background
66+
ipfs-start:
67+
#!/usr/bin/env bash
68+
set -e
69+
70+
mkdir -p {{ PID_DIR }}
71+
72+
# Check if IPFS is available
73+
if ! command -v ipfs &> /dev/null; then
74+
IPFS_CMD="./kubo/ipfs"
75+
else
76+
IPFS_CMD="ipfs"
6277
fi
6378

64-
# Start IPFS daemon in background
6579
echo "📡 Starting IPFS daemon..."
6680
$IPFS_CMD daemon > /tmp/ipfs-daemon.log 2>&1 &
6781
IPFS_PID=$!
82+
echo $IPFS_PID > {{ PID_DIR }}/ipfs.pid
6883
echo " IPFS PID: $IPFS_PID"
84+
echo " Log: /tmp/ipfs-daemon.log"
6985
sleep 2
7086

87+
# Connect to IPFS nodes
88+
ipfs-connect:
89+
#!/usr/bin/env bash
90+
set -e
91+
92+
# Check if IPFS is available
93+
if ! command -v ipfs &> /dev/null; then
94+
IPFS_CMD="./kubo/ipfs"
95+
else
96+
IPFS_CMD="ipfs"
97+
fi
98+
7199
echo "🔗 Connecting IPFS nodes..."
72100
$IPFS_CMD swarm connect /ip4/127.0.0.1/tcp/12347/ws/p2p/12D3KooWRkZhiRhsqmrQ28rt73K7V3aCBpqKrLGSXmZ99PTcTZby || true
73101
$IPFS_CMD swarm connect /ip4/127.0.0.1/tcp/10001/ws/p2p/12D3KooWQCkBm1BYtkHpocxCwMgR8yjitEeHGx8spzcDLGt2gkBm || true
102+
103+
# Start zombienet in background
104+
bulletin-zombienet-start:
105+
#!/usr/bin/env bash
106+
set -e
107+
108+
mkdir -p {{ PID_DIR }}
74109

75-
# Start zombienet in background
76110
echo "⚡ Starting Bulletin chain with zombienet..."
77-
POLKADOT_BULLETIN_BINARY_PATH=../target/release/polkadot-bulletin-chain ./$(ls zombienet-*-*) -p native spawn ./zombienet/bulletin-polkadot-local.toml > /tmp/zombienet.log 2>&1 &
111+
POLKADOT_BULLETIN_BINARY_PATH=../target/release/polkadot-bulletin-chain ../$(ls ../zombienet-*-*) -p native spawn ./zombienet/bulletin-polkadot-local.toml > /tmp/zombienet.log 2>&1 &
78112
ZOMBIENET_PID=$!
113+
echo $ZOMBIENET_PID > {{ PID_DIR }}/zombienet.pid
79114
echo " Zombienet PID: $ZOMBIENET_PID"
115+
echo " Log: /tmp/zombienet.log"
80116
echo " Waiting for chain to start (15 seconds)..."
81117
sleep 15
118+
119+
# Start IPFS reconnect script in background
120+
ipfs-reconnect-start:
121+
#!/usr/bin/env bash
122+
set -e
123+
124+
mkdir -p {{ PID_DIR }}
82125

83-
# Start IPFS reconnect script in background
84126
echo "🔄 Starting IPFS reconnect script..."
85127
./scripts/ipfs-reconnect-solo.sh > /tmp/ipfs-reconnect.log 2>&1 &
86128
RECONNECT_PID=$!
129+
echo $RECONNECT_PID > {{ PID_DIR }}/ipfs-reconnect.pid
87130
echo " Reconnect PID: $RECONNECT_PID"
131+
echo " Log: /tmp/ipfs-reconnect.log"
88132
sleep 2
133+
134+
# Generate PAPI descriptors
135+
papi-generate:
136+
#!/usr/bin/env bash
137+
set -e
89138

90-
# Generate PAPI descriptors (only for papi)
91-
if [ "$API_TYPE" == "papi" ]; then
92-
echo "🔧 Generating PAPI descriptors..."
93-
npm run papi:generate
139+
echo "🔧 Generating PAPI descriptors..."
140+
npm run papi:generate
141+
142+
# Run the authorize-and-store example
143+
# Parameters: api=[papi|pjs] - choose between Polkadot API (papi) or Polkadot JS (pjs)
144+
run-example api="papi":
145+
#!/usr/bin/env bash
146+
set -e
147+
148+
API_TYPE="{{ api }}"
149+
150+
if [[ "$API_TYPE" != "papi" && "$API_TYPE" != "pjs" ]]; then
151+
echo "❌ Error: api parameter must be 'papi' or 'pjs'"
152+
exit 1
94153
fi
95154

96155
# Determine which example to run
@@ -100,11 +159,70 @@ authorize-and-store api="papi": build npm-install
100159
EXAMPLE_FILE="authorize_and_store.js"
101160
fi
102161

103-
# Run the example
104162
echo ""
105163
echo "🎯 Running $EXAMPLE_FILE example..."
106164
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
107165
node $EXAMPLE_FILE
166+
167+
# Stop all running services (IPFS, zombienet, reconnect script)
168+
stop-services:
169+
#!/usr/bin/env bash
170+
171+
echo "🧹 Stopping all services..."
172+
173+
# Stop services by reading PIDs from files
174+
if [ -d {{ PID_DIR }} ]; then
175+
for pidfile in {{ PID_DIR }}/*.pid; do
176+
if [ -f "$pidfile" ]; then
177+
PID=$(cat "$pidfile")
178+
SERVICE=$(basename "$pidfile" .pid)
179+
if kill $PID 2>/dev/null; then
180+
echo " ✓ Stopped $SERVICE (PID: $PID)"
181+
else
182+
echo " ⚠ $SERVICE (PID: $PID) not running or already stopped"
183+
fi
184+
rm "$pidfile"
185+
fi
186+
done
187+
rmdir {{ PID_DIR }} 2>/dev/null || true
188+
else
189+
echo " No running services found"
190+
fi
191+
192+
echo "✅ Services stopped"
193+
194+
# Test the complete workflow (builds, starts services, runs example, shuts down services)
195+
# Parameters: api=[papi|pjs] - choose between Polkadot API (papi) or Polkadot JS (pjs)
196+
authorize-and-store api="papi": build npm-install
197+
#!/usr/bin/env bash
198+
set -e
199+
200+
API_TYPE="{{ api }}"
201+
202+
if [[ "$API_TYPE" != "papi" && "$API_TYPE" != "pjs" ]]; then
203+
echo "❌ Error: api parameter must be 'papi' or 'pjs'"
204+
exit 1
205+
fi
206+
207+
echo "🚀 Starting $API_TYPE workflow test..."
208+
echo ""
209+
210+
# Initialize IPFS
211+
just ipfs-init
212+
213+
# Start services
214+
just ipfs-start
215+
just bulletin-zombienet-start
216+
just ipfs-connect
217+
just ipfs-reconnect-start
218+
219+
# Generate PAPI descriptors if needed
220+
if [ "$API_TYPE" == "papi" ]; then
221+
just papi-generate
222+
fi
223+
224+
# Run the example
225+
just run-example $API_TYPE
108226
EXAMPLE_EXIT=$?
109227

110228
echo ""
@@ -122,8 +240,6 @@ authorize-and-store api="papi": build npm-install
122240
echo " /tmp/ipfs-reconnect.log"
123241

124242
# Clean up background processes
125-
echo "🧹 Cleaning up background processes..."
126-
kill $IPFS_PID $ZOMBIENET_PID $RECONNECT_PID 2>/dev/null || true
127-
243+
just stop-services
128244

129245
exit $EXAMPLE_EXIT

0 commit comments

Comments
 (0)