This directory contains automated workflows for continuous integration, testing, and deployment.
Triggers:
- Push to
mainordevelopbranches - Pull requests to
mainordevelop - Manual trigger via workflow_dispatch
Jobs:
-
lint-python - Python code quality
- Black (formatting)
- isort (import sorting)
- Flake8 (linting)
- Pylint (static analysis)
-
lint-javascript - JavaScript code quality
- ESLint
-
test-python - Unit tests
- Runs on Python 3.10, 3.11, 3.12
- Coverage reporting
- Uploads to Codecov
-
validate-config - Configuration validation
- Validates config.json
- Validates Dockerfile with hadolint
-
security-scan - Security checks
- Safety (dependency vulnerabilities)
- Bandit (security linting)
-
codeql-analysis - Advanced security
- GitHub CodeQL scanning
- Python and JavaScript analysis
-
docker-build - Docker image test
- Test build for all architectures
-
addon-validator - Home Assistant specific
- Validates add-on structure
- Checks metadata
-
documentation-check - Documentation
- Verifies required docs exist
- Checks markdown links
-
test-summary - Results summary
- Aggregates all job results
- Fails if critical checks fail
Triggers:
- Git tags matching
v*.*.*pattern - Manual trigger with version input
Jobs:
-
validate-version - Version checks
- Validates version format
- Checks config.json matches tag
-
run-tests - Full test suite
- Ensures all tests pass before release
-
build-and-push - Multi-arch builds
- Builds for: amd64, armv7, aarch64, armhf, i386
- Pushes to Docker Hub
- Tags with version and latest
-
create-manifest - Docker manifests
- Creates multi-arch manifests
- Enables platform-specific pulls
-
create-github-release - GitHub release
- Extracts changelog
- Creates release with notes
- Attaches artifacts
-
notify-completion - Status notification
- Reports completion status
Flake8 linter configuration:
- Max line length: 120
- Ignores: E203, W503, E501
- Excludes common directories
Pylint configuration:
- Customized rule set
- Max line length: 120
- Disabled verbose rules
Modern Python project configuration:
- Black formatting settings
- isort configuration
- pytest settings
- Coverage configuration
Pre-commit hooks for local development:
- Trailing whitespace
- YAML/JSON validation
- Black, isort, Flake8
- Bandit security checks
- ESLint for JavaScript
Automated dependency updates:
- Python packages (weekly)
- GitHub Actions (weekly)
- Docker base images (weekly)
Structured bug report form with fields:
- Description
- Expected behavior
- Steps to reproduce
- Version information
- Logs and configuration
Feature suggestion form with fields:
- Problem description
- Proposed solution
- Alternatives considered
- Additional context
Standard PR template requiring:
- Description of changes
- Type of change
- Related issues
- Testing information
- Checklist of requirements
- Screenshots (if applicable)
For full CI/CD functionality, configure these secrets in GitHub repository settings:
DOCKER_USERNAME- Docker Hub usernameDOCKER_PASSWORD- Docker Hub password or token
CODECOV_TOKEN- Codecov upload token (for coverage reporting)
Add these badges to your README.md:
[](https://github.com/MattHadfield113/home-assistant-smart-energy/actions/workflows/ci.yml)
[](https://codecov.io/gh/MattHadfield113/home-assistant-smart-energy)pip install pre-commit
pre-commit installpre-commit run --all-files# Format code
black app/ tests/
# Sort imports
isort app/ tests/
# Lint code
flake8 app/ tests/
# Static analysis
pylint app/
# Security scan
bandit -r app/
# Run tests
pytest tests/ -v --cov=app-
Before Committing
- Run pre-commit hooks
- Ensure tests pass locally
- Update documentation
-
Creating PRs
- Use descriptive titles
- Fill out PR template
- Link related issues
- Add tests for new features
-
During Review
- Address feedback promptly
- Keep commits clean
- Rebase if needed
-
Reviewing PRs
- Check all CI jobs pass
- Review code quality
- Test functionality
- Verify documentation
-
Creating Releases
- Update CHANGELOG.md
- Bump version in config.json
- Create git tag:
git tag v1.2.0 - Push tag:
git push origin v1.2.0
-
Monitoring
- Check workflow runs regularly
- Review Dependabot PRs
- Update actions annually
Linting Errors:
- Run locally:
black app/ tests/ - Check:
flake8 app/ tests/
Test Failures:
- Run locally:
pytest tests/ -v - Check test output for details
Docker Build Failures:
- Test locally:
docker build -t test . - Check Dockerfile syntax
Add-on Validation Failures:
- Validate config.json syntax
- Check required fields present
- Verify architecture list
Version Mismatch:
- Ensure config.json version matches git tag
- Format:
v1.2.3for tag,1.2.3in config
Docker Push Failures:
- Verify Docker Hub credentials
- Check image size limits
- Ensure network connectivity
GitHub Release Failures:
- Check CHANGELOG.md format
- Verify GitHub token permissions
- Review release notes extraction
- Weekly: Review Dependabot PRs
- Monthly: Update GitHub Actions versions
- Quarterly: Review and update workflows
- Annually: Audit security settings
When modifying workflows:
- Test syntax:
yamllint .github/workflows/*.yml - Validate logic: Review job dependencies
- Test with branch first
- Monitor first run carefully
- Update documentation
For issues with CI/CD:
- Check workflow run logs
- Review this documentation
- Check GitHub Actions status
- Open an issue with workflow run link