Tests #196
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Tests | |
| on: | |
| push: | |
| branches: [ main, master, dev ] | |
| pull_request: | |
| branches: [ main, master ] | |
| schedule: | |
| - cron: "0 0 * * 0" # Run weekly to catch dependency issues | |
| permissions: | |
| contents: read | |
| jobs: | |
| style: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| cache: "pip" | |
| cache-dependency-path: requirements_test.txt | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements_test.txt | |
| - name: Check code formatting | |
| run: | | |
| black --check . | |
| - name: Lint with flake8 | |
| run: | | |
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | |
| - name: Validate manifest syntax | |
| run: | | |
| python -c "import json; data=json.load(open('manifest.json')); assert 'domain' in data and 'version' in data, 'manifest.json missing required fields'" | |
| - name: Validate services syntax | |
| run: | | |
| python -c "import yaml; yaml.safe_load(open('services.yaml'))" | |
| - name: Validate translations syntax | |
| run: | | |
| python -c "import json; json.load(open('translations/en.json'))" | |
| validate: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: HACS Action | |
| uses: hacs/action@v1 | |
| with: | |
| category: integration | |
| - name: Hassfest validation | |
| uses: home-assistant/actions/hassfest@master | |
| test: | |
| needs: [style, validate] | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ["3.10", "3.11"] | |
| fail-fast: false # Continue with other versions if one fails | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| cache: "pip" | |
| cache-dependency-path: requirements_test.txt | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements_test.txt | |
| - name: Validate test environment | |
| run: | | |
| python scripts/validate_test_env.py | |
| - name: Run test suite | |
| run: | | |
| python scripts/run_test_suite.py --config full --coverage | |
| - name: Upload coverage reports to Codecov | |
| uses: codecov/codecov-action@v4 | |
| with: | |
| file: ./coverage.xml | |
| flags: unittests | |
| env_vars: OS,PYTHON | |
| name: codecov-umbrella | |
| fail_ci_if_error: false | |
| - name: Upload test reports | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-reports-${{ matrix.python-version }} | |
| path: test_reports/ | |
| if-no-files-found: ignore | |
| performance: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| cache: "pip" | |
| cache-dependency-path: requirements_test.txt | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements_test.txt | |
| - name: Run performance tests | |
| run: | | |
| python scripts/run_test_suite.py --config performance | |
| - name: Upload performance reports | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: performance-reports | |
| path: test_reports/ | |
| if-no-files-found: ignore | |
| stress: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'schedule' # Only run stress tests on schedule | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| cache: "pip" | |
| cache-dependency-path: requirements_test.txt | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements_test.txt | |
| - name: Run stress tests | |
| run: | | |
| python scripts/run_test_suite.py --config stress | |
| - name: Upload stress test reports | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: stress-test-reports | |
| path: test_reports/ | |
| if-no-files-found: ignore | |
| analyze: | |
| needs: [test, performance] | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download all workflow run artifacts | |
| uses: actions/download-artifact@v4 | |
| - name: Generate summary report | |
| run: | | |
| mkdir -p combined_reports | |
| cp -r *-reports*/* combined_reports/ || true | |
| echo "## Test Results Summary" > $GITHUB_STEP_SUMMARY | |
| echo "### Coverage Analysis" >> $GITHUB_STEP_SUMMARY | |
| cat combined_reports/coverage_analysis.txt >> $GITHUB_STEP_SUMMARY || echo "No coverage analysis available." >> $GITHUB_STEP_SUMMARY | |
| if [ -f combined_reports/performance_report.html ]; then | |
| echo "### Performance Test Results" >> $GITHUB_STEP_SUMMARY | |
| echo "Performance test results are available in the artifacts." >> $GITHUB_STEP_SUMMARY | |
| fi | |
| if [ -f combined_reports/stress_test_reports/summary.html ]; then | |
| echo "### Stress Test Results" >> $GITHUB_STEP_SUMMARY | |
| echo "Stress test results are available in the artifacts." >> $GITHUB_STEP_SUMMARY | |
| fi |