Add path-based triggers to workflow to run tests only when relevant files change. This saves CI resources on documentation-only or README changes while maintaining broad coverage for code and configuration changes. Tests now run when these files change: - install.sh (installer script) - src/** (all source code) - tests/** (test files) - .github/workflows/** (CI configuration) - *.txt, *.toml, *.cfg (dependency/config files) - *.py (Python files in root) Tests skip when only these change: - README.md, docs, examples - Other markdown or documentation files This is especially beneficial for ARM tests which take 5-10 minutes due to QEMU emulation overhead. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
273 lines
8.8 KiB
YAML
273 lines
8.8 KiB
YAML
name: Tests
|
|
|
|
on:
|
|
push:
|
|
branches: [ "*" ]
|
|
paths:
|
|
- 'install.sh'
|
|
- 'src/**'
|
|
- 'tests/**'
|
|
- '.github/workflows/**'
|
|
- '*.txt' # requirements files
|
|
- '*.toml' # pyproject.toml
|
|
- '*.cfg' # setup.cfg
|
|
- '*.py' # any Python file in root
|
|
pull_request:
|
|
branches: [ "*" ]
|
|
paths:
|
|
- 'install.sh'
|
|
- 'src/**'
|
|
- 'tests/**'
|
|
- '.github/workflows/**'
|
|
- '*.txt' # requirements files
|
|
- '*.toml' # pyproject.toml
|
|
- '*.cfg' # setup.cfg
|
|
- '*.py' # any Python file in root
|
|
|
|
jobs:
|
|
# Detect which files changed to run only relevant tests
|
|
detect-changes:
|
|
name: Detect Changes
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
python: ${{ steps.filter.outputs.python }}
|
|
installer: ${{ steps.filter.outputs.installer }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: dorny/paths-filter@v2
|
|
id: filter
|
|
with:
|
|
filters: |
|
|
python:
|
|
- 'src/**/*.py'
|
|
- 'tests/test_*.py'
|
|
- '*.txt'
|
|
- '*.toml'
|
|
- '*.cfg'
|
|
installer:
|
|
- 'install.sh'
|
|
- 'tests/test_installer.sh'
|
|
- '.github/workflows/test.yml'
|
|
|
|
unit-tests:
|
|
name: Unit Tests
|
|
runs-on: ubuntu-latest
|
|
needs: detect-changes
|
|
if: needs.detect-changes.outputs.python == 'true'
|
|
|
|
strategy:
|
|
matrix:
|
|
python-version: ["3.8", "3.9", "3.10", "3.11"]
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Python ${{ matrix.python-version }}
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: ${{ matrix.python-version }}
|
|
|
|
- name: Install system dependencies
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y libglib2.0-dev libdbus-1-dev libcairo2-dev libgirepository1.0-dev
|
|
|
|
- name: Install Python dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
pip install pytest pytest-asyncio pytest-cov
|
|
pip install rns bleak bluezero dbus-python
|
|
|
|
- name: Create package structure
|
|
run: |
|
|
touch src/RNS/__init__.py
|
|
touch src/RNS/Interfaces/__init__.py
|
|
|
|
- name: Run unit tests
|
|
run: |
|
|
# Run only unit tests (fragmentation and prioritization)
|
|
python -m pytest tests/test_fragmentation.py tests/test_prioritization.py -v \
|
|
--cov=src/RNS/Interfaces/BLEFragmentation.py \
|
|
--cov-report=term-missing \
|
|
--cov-report=xml:coverage-unit.xml
|
|
continue-on-error: false
|
|
|
|
- name: Upload unit test coverage
|
|
if: matrix.python-version == '3.11'
|
|
uses: codecov/codecov-action@v4
|
|
with:
|
|
file: ./coverage-unit.xml
|
|
flags: unit
|
|
fail_ci_if_error: false
|
|
continue-on-error: true
|
|
|
|
integration-tests:
|
|
name: Integration Tests
|
|
runs-on: ubuntu-latest
|
|
|
|
strategy:
|
|
matrix:
|
|
python-version: ["3.8", "3.9", "3.10", "3.11"]
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Python ${{ matrix.python-version }}
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: ${{ matrix.python-version }}
|
|
|
|
- name: Install system dependencies
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y libglib2.0-dev libdbus-1-dev libcairo2-dev libgirepository1.0-dev
|
|
|
|
- name: Install Python dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
pip install pytest pytest-asyncio pytest-cov pytest-timeout
|
|
pip install rns bleak bluezero dbus-python
|
|
|
|
- name: Create package structure
|
|
run: |
|
|
touch src/RNS/__init__.py
|
|
touch src/RNS/Interfaces/__init__.py
|
|
|
|
- name: Run integration tests
|
|
run: |
|
|
# Run integration tests (no hardware required)
|
|
python -m pytest tests/ -v -m "not hardware" \
|
|
--cov=src/RNS/Interfaces \
|
|
--cov-report=term-missing \
|
|
--cov-report=xml:coverage-integration.xml \
|
|
--tb=short
|
|
continue-on-error: false
|
|
|
|
- name: Upload integration test coverage
|
|
if: matrix.python-version == '3.11'
|
|
uses: codecov/codecov-action@v4
|
|
with:
|
|
file: ./coverage-integration.xml
|
|
flags: integration
|
|
fail_ci_if_error: false
|
|
continue-on-error: true
|
|
|
|
- name: Test summary
|
|
if: always()
|
|
run: |
|
|
echo "## Integration Test Results" >> $GITHUB_STEP_SUMMARY
|
|
echo "- Python version: ${{ matrix.python-version }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "- Tests run: All integration tests (hardware tests excluded)" >> $GITHUB_STEP_SUMMARY
|
|
echo "- See test output above for details" >> $GITHUB_STEP_SUMMARY
|
|
|
|
installer-test:
|
|
name: Installer Test (Fresh System)
|
|
runs-on: ubuntu-latest
|
|
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
os-image:
|
|
- "debian:12" # Debian Bookworm (current stable)
|
|
- "debian:trixie" # Debian Trixie (testing - next release)
|
|
- "ubuntu:22.04" # Ubuntu Jammy LTS
|
|
- "ubuntu:24.04" # Ubuntu Noble (latest LTS)
|
|
- "archlinux:latest" # Arch Linux (rolling release)
|
|
|
|
# Allow Trixie and Arch to fail without blocking CI (testing/rolling can be unstable)
|
|
continue-on-error: ${{ matrix.os-image == 'debian:trixie' || matrix.os-image == 'archlinux:latest' }}
|
|
|
|
container:
|
|
image: ${{ matrix.os-image }}
|
|
env:
|
|
DEBIAN_FRONTEND: noninteractive
|
|
DEBCONF_NONINTERACTIVE_SEEN: "true"
|
|
TZ: UTC
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
path: workspace
|
|
|
|
- name: Run installer integration test
|
|
run: |
|
|
cd workspace
|
|
bash tests/test_installer.sh
|
|
continue-on-error: false
|
|
|
|
- name: Installation summary
|
|
if: always()
|
|
run: |
|
|
echo "## Installer Test Results (${{ matrix.os-image }})" >> $GITHUB_STEP_SUMMARY
|
|
echo "✓ System packages: python3-gi, python3-dbus, python3-cairo, bluez" >> $GITHUB_STEP_SUMMARY
|
|
echo "✓ Pip packages: bleak, bluezero" >> $GITHUB_STEP_SUMMARY
|
|
echo "✓ Install method: System packages (no compilation)" >> $GITHUB_STEP_SUMMARY
|
|
echo "✓ Installation time: < 1 minute" >> $GITHUB_STEP_SUMMARY
|
|
|
|
installer-test-arm:
|
|
name: Installer Test (Raspberry Pi OS - ARM)
|
|
runs-on: ubuntu-latest
|
|
# Only run on pull requests to main branch
|
|
if: github.event_name == 'pull_request' && github.base_ref == 'main'
|
|
timeout-minutes: 20 # ARM emulation is slower, allow extra time
|
|
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
# Raspberry Pi OS 32-bit (armhf/armv7)
|
|
# Based on Debian Bookworm - matches Raspberry Pi OS Lite 32-bit
|
|
- os-image: "arm32v7/debian:bookworm"
|
|
platform: "linux/arm/v7"
|
|
arch-name: "Raspberry Pi OS 32-bit (armhf)"
|
|
|
|
# Raspberry Pi OS 64-bit (arm64/aarch64)
|
|
# Based on Debian Bookworm - matches Raspberry Pi OS Lite 64-bit
|
|
- os-image: "arm64v8/debian:bookworm"
|
|
platform: "linux/arm64"
|
|
arch-name: "Raspberry Pi OS 64-bit (arm64)"
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
with:
|
|
platforms: arm,arm64
|
|
|
|
- name: Run installer test on ${{ matrix.arch-name }}
|
|
run: |
|
|
docker run --rm \
|
|
--platform ${{ matrix.platform }} \
|
|
-v $PWD:/workspace \
|
|
-w /workspace \
|
|
-e DEBIAN_FRONTEND=noninteractive \
|
|
-e DEBCONF_NONINTERACTIVE_SEEN=true \
|
|
-e TZ=UTC \
|
|
${{ matrix.os-image }} \
|
|
bash tests/test_installer.sh
|
|
continue-on-error: false
|
|
|
|
- name: Installation summary
|
|
if: always()
|
|
run: |
|
|
echo "## ARM Installer Test Results" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Architecture:** ${{ matrix.arch-name }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Platform:** ${{ matrix.platform }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Base Image:** ${{ matrix.os-image }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
if [[ "${{ matrix.platform }}" == "linux/arm/v7" ]]; then
|
|
echo "✓ System packages: python3-gi, python3-dbus, python3-cairo, bluez, libffi-dev" >> $GITHUB_STEP_SUMMARY
|
|
echo "✓ libffi-dev included for 32-bit ARM cffi compilation" >> $GITHUB_STEP_SUMMARY
|
|
else
|
|
echo "✓ System packages: python3-gi, python3-dbus, python3-cairo, bluez" >> $GITHUB_STEP_SUMMARY
|
|
fi
|
|
echo "✓ Pip packages: bleak==1.1.1, bluezero" >> $GITHUB_STEP_SUMMARY
|
|
echo "✓ BLE interface files copied" >> $GITHUB_STEP_SUMMARY
|
|
echo "✓ BlueZ experimental mode configured" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "_Note: Tests run via QEMU emulation (2-5x slower than native)_" >> $GITHUB_STEP_SUMMARY
|