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
34 changes: 34 additions & 0 deletions .github/actions/setup-nats-server/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Setup NATS Server
description: Install and cache NATS Server binary

inputs:
version:
description: "NATS Server version (e.g., latest, v2.10.29, v2.11.8)"
required: false
default: "latest"

runs:
using: composite
steps:
- name: Cache NATS Server
uses: actions/cache@v4
id: cache-nats
with:
path: ~/nats-server
key: nats-server-${{ runner.os }}-${{ runner.arch }}-${{ inputs.version }}

- name: Install NATS Server
if: steps.cache-nats.outputs.cache-hit != 'true'
shell: bash
run: |
INSTALL_DIR="$HOME/nats-server"
mkdir -p "$INSTALL_DIR"
curl -fsSL https://binaries.nats.dev/nats-io/nats-server/v2@${{ inputs.version }} | PREFIX="$INSTALL_DIR" sh

- name: Add NATS Server to PATH
shell: bash
run: echo "$HOME/nats-server" >> $GITHUB_PATH

- name: Verify NATS Server
shell: bash
run: nats-server -v
27 changes: 10 additions & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
nats_version: ["v2.10.29", "v2.11.8", "main"]
include:
- nats_version: "main"
continue-on-error: true
nats_version: ["latest"]

steps:
- name: Check out repository
Expand All @@ -35,17 +32,18 @@ jobs:
- name: Install uv
uses: astral-sh/setup-uv@v6

- name: Setup NATS Server
uses: ./.github/actions/setup-nats-server
with:
version: ${{ matrix.nats_version }}

- name: Install dependencies and project
run: |
uv sync --dev
./nats/scripts/install_nats.sh
run: uv sync --dev

- name: Run tests
run: |
uv run flake8 --ignore="W391, W503, W504, E501" ./nats/src/nats/js/
uv run pytest -x -vv -s --continue-on-collection-errors ./nats/tests
env:
PATH: $HOME/nats-server:$PATH

project:
name: ${{ matrix.project }} (python-${{ matrix.python-version }}, nats-server-${{ matrix.nats-server-version }}, ${{ matrix.os }})
Expand All @@ -60,15 +58,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v5

- name: Set up Go
uses: actions/setup-go@v6
- name: Setup NATS Server
uses: ./.github/actions/setup-nats-server
with:
go-version: "stable"

- name: Install NATS Server
run: |
go install github.com/nats-io/nats-server/v2@${{ matrix.nats-server-version }}
shell: bash
version: ${{ matrix.nats-server-version }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
Expand Down
13 changes: 12 additions & 1 deletion nats-server/src/nats/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import logging
import os
import re
import shutil
import socket
import tempfile
from typing import Self
Expand Down Expand Up @@ -203,8 +204,18 @@ async def _create_server_process(

Returns:
The created subprocess.

Raises:
ServerError: If nats-server executable is not found in PATH.
"""
cmd = ["nats-server"]
nats_server_path = shutil.which("nats-server")
if not nats_server_path:
raise ServerError(
"nats-server executable not found in PATH. "
"Please install nats-server from https://github.com/nats-io/nats-server"
)

cmd = [nats_server_path]

# Direct parameter to CLI flag mapping
if host is not None:
Expand Down
12 changes: 9 additions & 3 deletions nats-server/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
particularly for verifying that the required nats-server executable is available.
"""

import shutil
import socket
import subprocess

Expand All @@ -13,14 +14,19 @@

def get_nats_server_version():
"""Get the nats-server version or fail if not installed."""
nats_server_path = shutil.which("nats-server")
if not nats_server_path:
pytest.fail("nats-server is not installed or not in PATH")
return None

try:
result = subprocess.run(["nats-server", "--version"],
result = subprocess.run([nats_server_path, "--version"],
capture_output=True,
check=True,
text=True)
return result.stdout.strip() or result.stderr.strip()
except (subprocess.SubprocessError, FileNotFoundError) as e:
pytest.fail(f"nats-server is not installed or not in PATH: {e}")
except subprocess.SubprocessError as e:
pytest.fail(f"Failed to run nats-server: {e}")
return None


Expand Down
11 changes: 0 additions & 11 deletions nats/scripts/install_nats.sh

This file was deleted.

2 changes: 1 addition & 1 deletion nats/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def start(self):
# Default path
if Path(self.bin_name).is_file():
self.bin_name = Path(self.bin_name).absolute()
# Path in `../scripts/install_nats.sh`
# Path installed via https://docs.nats.io/running-a-nats-service/introduction/installation
elif Path.home().joinpath(SERVER_BIN_DIR_NAME,
self.bin_name).is_file():
self.bin_name = str(
Expand Down
Loading