Skip to content

Update Python version to 3.13 in GitHub Actions workflow #29

Update Python version to 3.13 in GitHub Actions workflow

Update Python version to 3.13 in GitHub Actions workflow #29

name: Rinnai Custom Component CI
on:
push:
branches: [ dev, master ]
pull_request:
branches: [ dev, master ]
workflow_dispatch:
inputs:
run_boot:
description: "Run a short HA boot and log check"
required: false
default: false
type: boolean
jobs:
test-component:
runs-on: ubuntu-latest
env:
# Toggle to 'true' to run a short HA boot and log check. Disabled by default
# to avoid optional dependency noise like hass_frontend during CI.
# When dispatched manually, this will reflect the input value.
RUN_BOOT: ${{ github.event_name == 'workflow_dispatch' && inputs.run_boot && 'true' || 'false' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python 3.13
uses: actions/setup-python@v4
with:
python-version: '3.13'
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/manifest.json') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install Home Assistant (core)
run: |
pip install --upgrade pip
pip install homeassistant
- name: Install tooling dependencies
run: |
pip install colorlog
- name: Install test dependencies
run: |
pip install pytest pytest-asyncio pytest-homeassistant-custom-component
- name: Prepare Home Assistant config
run: |
mkdir -p ./config/custom_components
cp -r custom_components/rinnaicontrolr-ha ./config/custom_components/rinnai
# Minimal configuration.yaml that does NOT load default_config
cat > ./config/configuration.yaml <<'YAML'
homeassistant:
name: CI Test
logger:
default: warning
logs:
custom_components.rinnai: debug
YAML
- name: Verify custom component files present
run: |
test -f ./config/custom_components/rinnai/manifest.json
echo "Custom component files:"
ls -la ./config/custom_components/rinnai
# Install custom component requirements from manifest.json
- name: Install custom component requirements
run: |
python -c "import json; f=open('custom_components/rinnaicontrolr-ha/manifest.json'); reqs=json.load(f).get('requirements', []); print('Installing:', reqs); import subprocess; [subprocess.check_call(['pip', 'install', r]) for r in reqs]"
- name: Validate configuration
run: |
hass --script check_config --config ./config
- name: Import custom component module
run: |
python - <<'PY'
import os, sys, importlib
# Ensure Home Assistant config dir is on sys.path for custom_components discovery
sys.path.insert(0, os.path.abspath('./config'))
m = importlib.import_module('custom_components.rinnai')
print('Imported module:', m.__name__)
PY
- name: Import platform modules (smoke)
run: |
python - <<'PY'
import os, sys, importlib
sys.path.insert(0, os.path.abspath('./config'))
for mod in (
'custom_components.rinnai.sensor',
'custom_components.rinnai.binary_sensor',
'custom_components.rinnai.water_heater',
):
m = importlib.import_module(mod)
print('Imported platform:', m.__name__)
PY
- name: Run unit tests
run: |
pytest -q
# Optional sanity boot (short) to ensure HA core starts with minimal config
- name: Optional short boot and log check
if: ${{ env.RUN_BOOT == 'true' }}
env:
RUN_BOOT: ${{ env.RUN_BOOT }}
run: |
# Frontend component requires the Python package 'home-assistant-frontend'
pip install home-assistant-frontend
nohup hass --config ./config >/dev/null 2>&1 &
PID=$!
sleep 25
if [ -f ./config/home-assistant.log ]; then
if grep -iE 'ERROR|Traceback' ./config/home-assistant.log; then
echo 'Errors found in Home Assistant log:'
grep -iE 'ERROR|Traceback' ./config/home-assistant.log || true
kill $PID || true
exit 1
fi
fi
kill $PID || true