Skip to content

Test

Test #56

Workflow file for this run

# Tests run only on PR to main (with manual approval) or via workflow_dispatch.
# Configure environment "approval-required" in repo Settings > Environments with required reviewers.
name: Test
on:
pull_request:
branches: [main] # PRs to dev do not run tests; use workflow_dispatch for other branches
workflow_dispatch:
jobs:
test:
name: test
runs-on: ${{ matrix.os }}
environment: approval-required
permissions:
contents: read
actions: read
pull-requests: read
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
exclude:
# Reduce matrix size for faster CI
- os: windows-latest
python-version: '3.8'
- os: windows-latest
python-version: '3.9'
- os: macos-latest
python-version: '3.8'
- os: macos-latest
python-version: '3.9'
steps:
- uses: actions/checkout@v4
- name: Install UV
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache Python dependencies
uses: actions/cache@v3
with:
path: |
~/.cache/uv
.venv
key: ${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('uv.lock') }}
restore-keys: |
${{ runner.os }}-python-${{ matrix.python-version }}-
- name: Cache pytest cache
uses: actions/cache@v3
with:
path: .pytest_cache
key: ${{ runner.os }}-pytest-${{ matrix.python-version }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-pytest-${{ matrix.python-version }}-
- name: Install dependencies
run: |
uv sync --dev
- name: Prepare test report directories
run: |
mkdir -p site/reports
- name: Check for port conflicts
run: |
# Check for common test ports that might be in use
# This helps detect lingering processes from previous test runs
echo "Checking for port conflicts..."
if command -v lsof &> /dev/null; then
# Unix-like systems (Linux, macOS)
PORTS=(6881 6882 6883 5001 8080 8081 8082)
for port in "${PORTS[@]}"; do
if lsof -i :$port &> /dev/null; then
echo "⚠️ Warning: Port $port is in use"
lsof -i :$port || true
fi
done
elif command -v netstat &> /dev/null; then
# Windows or older Unix systems
PORTS=(6881 6882 6883 5001 8080 8081 8082)
for port in "${PORTS[@]}"; do
if netstat -an | grep -q ":$port "; then
echo "⚠️ Warning: Port $port is in use"
netstat -an | grep ":$port " || true
fi
done
else
echo "⚠️ Port conflict detection tools not available, skipping check"
fi
echo "Port conflict check complete"
continue-on-error: true
- name: Run tests with coverage
shell: bash
env:
CCBT_TEST_DEBUG_LOG: /tmp/ccbt-test-debug.log
run: |
# Exclude compatibility tests from main test run (they run separately)
uv run pytest -c dev/pytest.ini tests/ \
-m "not compatibility" \
--cov=ccbt \
--cov-report=xml \
--cov-report=html \
--cov-report=term-missing
- name: Upload coverage to Codecov
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
- name: Upload test artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.os }}-py${{ matrix.python-version }}
path: |
coverage.xml
htmlcov/
site/reports/junit.xml
site/reports/pytest.log
retention-days: 7