Skip to content

Fix weather substitution tests for community edition #18

Fix weather substitution tests for community edition

Fix weather substitution tests for community edition #18

Workflow file for this run

name: CI/CD - Run Tests and Deploy
on:
push:
branches: [ develop, main ]
pull_request:
branches: [ develop, main ]
workflow_dispatch:
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
run-integration-tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
# Install all test dependencies explicitly
python -m pip install pytest>=7.4.0
python -m pip install pytest-asyncio>=0.21.0
python -m pip install pytest-homeassistant-custom-component>=0.13.0
python -m pip install pytest-cov>=4.1.0
python -m pip install homeassistant>=2024.1.0
python -m pip install freezegun>=1.2.0
# Verify freezegun installation
python -c "import freezegun; print('✓ freezegun version:', freezegun.__version__)"
- name: Set up Python module structure
run: |
# Create custom_components directory structure for imports
mkdir -p ../custom_components
ln -s "$PWD" ../custom_components/solar_energy_management
echo "PYTHONPATH=$(pwd)/.." >> $GITHUB_ENV
- name: Run integration tests
run: |
python -m pytest tests/ -v --tb=short --asyncio-mode=auto --color=yes
- name: Run energy balance and cost calculation tests
run: |
python -m pytest tests/test_flow_accumulation.py -v --tb=short --asyncio-mode=auto
python -m pytest tests/test_energy_flow_balance.py -v --tb=short --asyncio-mode=auto
- name: Run service registration tests
run: |
python -m pytest tests/test_services.py::TestEMSServices -v --tb=short --asyncio-mode=auto
trigger-deployment:
needs: run-integration-tests
runs-on: ubuntu-latest
if: success() && github.ref == 'refs/heads/develop'
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Bump version
id: bump
run: |
python -c "
import json
from pathlib import Path
import os
manifest_path = Path('manifest.json')
with open(manifest_path, 'r') as f:
data = json.load(f)
version = data['version']
major, minor, patch = map(int, version.split('.'))
patch += 1
new_version = f'{major}.{minor}.{patch}'
data['version'] = new_version
with open(manifest_path, 'w') as f:
json.dump(data, f, indent=2)
f.write('\n')
print(f'Version bumped: {version} -> {new_version}')
# Export to GITHUB_OUTPUT for use in next steps
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f'version={new_version}\n')
"
echo "Version bumped successfully"
- name: Commit and push version bump
run: |
git add manifest.json
git commit -m "🔖 Bump version [skip ci]" || echo "No changes to commit"
git push origin develop || echo "Nothing to push"
- name: Trigger n8n deployment workflow
env:
N8N_WEBHOOK_URL: ${{ secrets.N8N_WEBHOOK_URL }}
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
AUTHOR_NAME: ${{ github.event.head_commit.author.name }}
run: |
echo "✅ Tests passed! Ready for deployment."
echo "📦 Version: ${{ steps.bump.outputs.version }}"
# Send webhook to n8n with deployment info
if [ -n "$N8N_WEBHOOK_URL" ]; then
# Use jq to properly escape JSON values
PAYLOAD=$(jq -n \
--arg version "${{ steps.bump.outputs.version }}" \
--arg branch "${{ github.ref_name }}" \
--arg commit_sha "${{ github.sha }}" \
--arg commit_message "$COMMIT_MESSAGE" \
--arg author "$AUTHOR_NAME" \
--arg repository "${{ github.repository }}" \
--arg workflow "${{ github.workflow }}" \
--arg run_id "${{ github.run_id }}" \
--arg run_number "${{ github.run_number }}" \
--arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
'{
version: $version,
branch: $branch,
commit_sha: $commit_sha,
commit_message: $commit_message,
author: $author,
repository: $repository,
workflow: $workflow,
run_id: $run_id,
run_number: $run_number,
timestamp: $timestamp
}')
curl -X POST "$N8N_WEBHOOK_URL" \
-H "Content-Type: application/json" \
-d "$PAYLOAD"
echo "Webhook sent to n8n"
else
echo "N8N_WEBHOOK_URL not configured - skipping webhook"
fi