mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
45a94ef7c7a385c85378d467f3705419bdabc287
lyrics_transcriber_local
@ 83715b70b7
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%