mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
fd4783fa087c7cb1ddab846c5109c40792c88f08
This refactor addresses code duplication where style loading was implemented separately in 5 different places, which led to bugs (like the preview video not loading custom background images that was fixed in the previous commit). New module: karaoke_gen/style_loader.py - Single source of truth for DEFAULT_STYLE_PARAMS and ASSET_KEY_MAPPINGS - load_styles_from_gcs() for backend workers to download/update styles - update_asset_paths() to replace GCS paths with local downloaded files - Helper functions: get_intro_format(), get_end_format(), get_karaoke_format() Updated files to use the unified module: - karaoke_gen/config.py: delegates to style_loader functions - backend/workers/style_helper.py: StyleConfig now wraps style_loader - backend/workers/render_video_worker.py: uses load_styles_from_gcs() - backend/api/routes/review.py: uses load_styles_from_gcs() Benefits: - Asset key mappings defined once (was duplicated in 4+ places) - Default styles defined once (was duplicated with slight variations) - Future style changes only need to be made in one place - Tests verify the unified module directly Bump version to 0.70.6
GitHub Actions CI/CD
This directory contains GitHub Actions workflows for automated testing and deployment.
Workflows
test.yml - Automated Testing & Deployment (CI/CD)
Triggers:
- Push to
mainorreplace-modal-with-google-cloudbranches - Pull requests to
main
Jobs:
Testing Phase (runs in parallel)
-
Unit Tests (~30s)
- Runs 62 unit tests with mocked dependencies
- Fast validation of business logic
- Uses Python 3.12 with pip caching
-
Emulator Integration Tests (~2min)
- Runs 11 integration tests against local GCP emulators
- Tests real Firestore and GCS interactions
- Requires:
- Java 21 (for Firestore emulator)
- Google Cloud SDK (for Firestore emulator)
- Docker (for GCS emulator via fake-gcs-server)
- Uses the same
scripts/run-emulator-tests.shas local development
-
Code Quality (~20s)
- Basic Python syntax validation
- Import checks
- Optional: flake8, black, isort
Deployment Phase (runs after all tests pass)
- Deploy to Cloud Run (~3-4min)
- Only runs on push to
replace-modal-with-google-cloudbranch (not on PRs) - Builds Docker image and pushes to Artifact Registry
- Deploys to Cloud Run with proper configuration
- Verifies deployment health
- Requires GitHub secrets:
GCP_SA_KEY- Service account key JSONADMIN_TOKENS- Admin authentication tokens
- Only runs on push to
Total Runtime:
- Testing only (PRs): ~3 minutes
- Testing + Deployment (push to branch): ~7 minutes
Local vs CI
The CI runs the exact same tests as local development:
# Local development
./scripts/run-tests.sh # Unit tests (same as CI job 1)
./scripts/run-emulator-tests.sh # Emulator tests (same as CI job 2)
python backend/validate.py # Validation (same as CI job 3)
# CI automatically runs all three on every push
Viewing Results
- Go to the Actions tab in GitHub
- Click on the latest workflow run
- View job logs and test results
- Download test artifacts (coverage reports) if needed
Adding New Tests
Tests are automatically discovered by pytest. To add new tests:
- Unit tests: Add to
backend/tests/test_*.py - Emulator tests: Add to
backend/tests/emulator/test_*.py - Cloud tests: Add to
backend/tests/test_api_integration.py(runs manually)
The CI will automatically pick them up!
Troubleshooting
Emulator Tests Fail in CI
Common issues:
- Emulator startup timeout → Increase wait time in
scripts/start-emulators.sh - Docker not available → Check GitHub Actions runner compatibility
- Port conflicts → Emulators use ports 8080 (Firestore) and 4443 (GCS)
CI is Slow
Optimizations:
- ✅ Python pip caching enabled
- ✅ Jobs run in parallel
- ✅ Docker image pre-pulled
- Future: Cache gcloud SDK installation
Tests Pass Locally But Fail in CI
Debug steps:
- Check Python version matches (3.12)
- Check environment variables are set correctly
- Review CI logs for missing dependencies
- Run tests in a clean venv locally
Setting Up Continuous Deployment
The CD pipeline is configured but requires GitHub secrets to be set. See the CD Setup Guide for detailed instructions.
Quick setup:
- Create GCP service account with deployment permissions
- Download service account key JSON
- Add GitHub secrets:
GCP_SA_KEY- Full service account key JSON contentADMIN_TOKENS- Comma-separated admin tokens
Once configured, every push to replace-modal-with-google-cloud will automatically deploy to Cloud Run after all tests pass.
Future Enhancements
- Add test coverage reporting (coveralls, codecov)
- ✅ Add deployment workflow (deploy to Cloud Run after tests pass)
- Add frontend tests (when frontend is built)
- Add performance benchmarking
- Add security scanning (dependabot, snyk)
- Migrate to Workload Identity Federation (more secure than service account keys)
Languages
Python
74.7%
TypeScript
22.1%
HTML
1.4%
Shell
1.2%
JavaScript
0.4%