Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 56 additions & 55 deletions .github/workflows/bbmtlib-test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: BBMTLib Tests

on:
push:
paths:
- 'BBMTLib/**'
- '.github/workflows/bbmtlib-test.yml'
pull_request:
paths:
- 'BBMTLib/**'
Expand Down Expand Up @@ -102,11 +98,66 @@ jobs:
sudo apt-get update
sudo apt-get install -y jq

- name: Verify Docker is available
run: |
if ! command -v docker >/dev/null 2>&1; then
echo "❌ Docker is required for running tests with local relay"
exit 1
fi
docker --version
echo "✓ Docker is available"

- name: Pull Nostr relay Docker image
run: |
# Pre-pull the image so Docker can use its built-in cache
# Docker on GitHub Actions automatically caches images between runs
echo "Pulling nostr-rs-relay Docker image..."
docker pull scsibug/nostr-rs-relay:latest || {
echo "❌ Failed to pull nostr-rs-relay image"
exit 1
}
echo "✓ Nostr relay image ready (Docker will cache this for subsequent runs)"

- name: Start local Nostr relay
run: |
echo "Starting local Docker-based Nostr relay..."
chmod +x scripts/*.sh
if ! ./scripts/start-local-relay.sh; then
echo "❌ Failed to start local relay. Tests require a local Docker-based relay."
echo "Relay container status:"
docker ps -a | grep bbmtlib-test-relay || echo "No relay container found"
exit 1
fi
echo "✓ Local relay is running at ws://localhost:7777"

# Verify relay is actually accessible
if ! docker ps --format '{{.Names}}' | grep -q "^bbmtlib-test-relay$"; then
echo "❌ Relay container is not running"
exit 1
fi

- name: Run comprehensive script tests
env:
RELAYS: "ws://localhost:7777"
REQUIRE_LOCAL_RELAY: "true"
run: |
echo "Running comprehensive test suite for all scripts..."
echo "Using local relay: $RELAYS"
echo "Local relay is required - tests will fail if relay is unavailable"

# Verify relay is still running before tests
if ! docker ps --format '{{.Names}}' | grep -q "^bbmtlib-test-relay$"; then
echo "❌ Local relay container is not running. Tests cannot proceed."
exit 1
fi

./scripts/test-all.sh
continue-on-error: true

- name: Stop local Nostr relay
if: always()
run: |
echo "Stopping local relay..."
./scripts/stop-local-relay.sh || true

- name: Run vet
run: go vet ./...
Expand Down Expand Up @@ -140,53 +191,3 @@ jobs:
fail_ci_if_error: false
continue-on-error: true

integration-test:
name: Integration Tests (Optional)
runs-on: ubuntu-latest
needs: test

defaults:
run:
working-directory: ./BBMTLib

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24.2'
cache-dependency-path: BBMTLib/go.sum

- name: Install dependencies
run: go mod download

- name: Install jq (for JSON validation)
run: |
sudo apt-get update
sudo apt-get install -y jq

- name: Install Docker (for local relay)
run: |
# Docker is pre-installed in GitHub Actions ubuntu-latest
# Just verify it's available
docker --version || echo "Docker not available, tests will use external relays"

- name: Run comprehensive script tests (with local relay)
env:
TIMEOUT: "120"
run: |
echo "Running comprehensive test suite with local Nostr relay..."
echo "The test script will automatically start a local relay using Docker"
echo "If Docker is unavailable, it will fall back to external relays"

# Make scripts executable
chmod +x scripts/*.sh

# Run comprehensive test script
# The script will handle starting/stopping the local relay automatically
./scripts/test-all.sh
continue-on-error: true
timeout-minutes: 15

17 changes: 11 additions & 6 deletions BBMTLib/scripts/start-local-relay.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,17 @@ mkdir -p "$DATA_DIR_ABS"
chmod 777 "$DATA_DIR_ABS" || true

# Pull the latest nostr-rs-relay image (or use a specific tag)
echo "Pulling nostr-rs-relay Docker image..."
docker pull scsibug/nostr-rs-relay:latest || {
echo -e "${YELLOW}Warning: Failed to pull image, trying to build from source...${NC}"
# If pull fails, we could build from source, but for now just exit
exit 1
}
# Check if image already exists to avoid unnecessary pulls
if docker images --format '{{.Repository}}:{{.Tag}}' | grep -q "^scsibug/nostr-rs-relay:latest$"; then
echo "✓ nostr-rs-relay image already exists, skipping pull"
else
echo "Pulling nostr-rs-relay Docker image..."
docker pull scsibug/nostr-rs-relay:latest || {
echo -e "${YELLOW}Warning: Failed to pull image, trying to build from source...${NC}"
# If pull fails, we could build from source, but for now just exit
exit 1
}
fi

# Start the relay container
# Remove :Z flag (SELinux context) as it's not needed in GitHub Actions and can cause issues
Expand Down
24 changes: 13 additions & 11 deletions BBMTLib/scripts/test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ start_local_relay() {

return 0
else
echo " Failed to start local relay, falling back to external relays"
echo " Failed to start local relay"
echo " Check /tmp/relay-start.log for details"
if [ -f /tmp/relay-start.log ]; then
echo " Last 10 lines of relay startup log:"
Expand Down Expand Up @@ -625,9 +625,10 @@ else
RELAYS_TO_USE="$LOCAL_RELAY_URL"
echo "Using local relay: $RELAYS_TO_USE"
else
RELAYS_TO_USE="${RELAYS:-wss://nostr.hifish.org,wss://nostr.xxi.quest,wss://bbw-nostr.xyz}"
echo "Using external relays: $RELAYS_TO_USE"
echo " (Note: Tests may fail due to relay connectivity)"
print_failure "nostr-keygen.sh: Local relay is required but could not be started"
echo " This test requires a local Docker-based relay to run."
echo " Please ensure Docker is available and the relay can be started."
exit 1
fi

# Try to run with a short timeout
Expand Down Expand Up @@ -719,13 +720,14 @@ else
fi

if [ -f "$KEYGEN_OUTPUT_DIR/party1-keyshare.json" ] && [ -f "$KEYGEN_OUTPUT_DIR/party2-keyshare.json" ]; then
# Use local relay if available, otherwise fall back to external
# Use local relay (required)
if [ "$USE_LOCAL_RELAY" = "true" ] && [ -n "$LOCAL_RELAY_URL" ]; then
RELAYS_TO_USE="$LOCAL_RELAY_URL"
echo " Using local relay for keysign: $RELAYS_TO_USE"
else
RELAYS_TO_USE="${RELAYS:-wss://bbw-nostr.xyz}"
echo " Using external relay for keysign: $RELAYS_TO_USE"
print_failure "nostr-keysign.sh: Local relay is required but not available"
echo " This test requires a local Docker-based relay to run."
exit 1
fi

export OUTPUT_DIR="$KEYGEN_OUTPUT_DIR"
Expand Down Expand Up @@ -786,14 +788,14 @@ else
print_failure "nostr-keygen-3party.sh: Syntax error"
fi

# Use local relay if available
# Use local relay (required)
if [ "$USE_LOCAL_RELAY" = "true" ] && [ -n "$LOCAL_RELAY_URL" ]; then
RELAYS_TO_USE="$LOCAL_RELAY_URL"
echo "Using local relay: $RELAYS_TO_USE"
else
RELAYS_TO_USE="${RELAYS:-wss://nostr.hifish.org,wss://nostr.xxi.quest,wss://bbw-nostr.xyz}"
echo "Using external relays: $RELAYS_TO_USE"
echo " (Note: Tests may fail due to relay connectivity)"
print_failure "nostr-keygen-3party.sh: Local relay is required but not available"
echo " This test requires a local Docker-based relay to run."
exit 1
fi

# Try to run with a short timeout
Expand Down