This document describes the GitHub Actions workflows used in the Divemap project.
- Backend Tests Workflow
- Workflow Triggers
- Environment Setup
- Test Execution
- Coverage Reports
- Troubleshooting
The backend tests workflow (backend-tests.yml) automatically runs when backend code changes are detected. This ensures that all backend changes are properly tested before merging.
- Automatic Triggering: Runs on PR creation and commits to main/master branches
- Path Filtering: Only runs when backend files are modified
- Virtual Environment: Uses Python virtual environment for isolation
- Dependency Caching: Caches pip dependencies for faster builds
- Service Containers: Provides Redis service for testing
- Coverage Reporting: Generates and uploads test coverage reports
- Artifact Upload: Saves test results and coverage reports as artifacts
The workflow is triggered by:
- Pull Requests: When a PR is created or updated targeting
mainormasterbranches - Direct Pushes: When code is pushed directly to
mainormasterbranches - Path Changes: Only when files in the
backend/directory or the workflow file itself are modified
on:
pull_request:
branches: [ main, master ]
paths:
- 'backend/**'
- '.github/workflows/backend-tests.yml'
push:
branches: [ main, master ]
paths:
- 'backend/**'
- '.github/workflows/backend-tests.yml'The workflow sets up a complete testing environment:
- Python Version: 3.11
- Virtual Environment: Created in
backend/divemap_venv/ - Dependencies: Installed from
backend/requirements.txt - PYTHONPATH: Configured for proper module resolution
Currently, no external services are required for testing as the backend uses SQLite for testing and doesn't require Redis in the test environment.
DATABASE_URL=sqlite:///./test.db
SECRET_KEY=test-secret-key-for-ci
GOOGLE_CLIENT_ID=test-client-id
GOOGLE_CLIENT_SECRET=test-client-secretThe workflow executes tests using the following steps:
- Checkout Code: Clones the repository
- Setup Python: Installs Python 3.11
- Cache Dependencies: Uses GitHub Actions cache for pip packages
- Install Dependencies: Creates virtual environment and installs requirements
- Setup Environment: Configures environment variables
- Run Tests: Executes pytest with coverage reporting
cd backend
source divemap_venv/bin/activate
export PYTHONPATH="/home/runner/work/divemap/divemap/backend/divemap_venv/lib/python3.11/site-packages:$PYTHONPATH"
python -m pytest tests/ -v --cov=app --cov-report=term-missing --cov-report=html --cov-report=xmlThe workflow generates multiple coverage report formats:
- Terminal Output: Shows missing lines in terminal
- HTML Report: Detailed coverage report in HTML format
- XML Report: Coverage data in XML format for external tools
- Codecov Integration: Uploads coverage to Codecov service using
CODECOV_TOKENsecret - Artifact Storage: Saves coverage reports as workflow artifacts
- Failure Handling: Coverage upload doesn't fail the workflow
- Directory Scanning: Automatically finds coverage files in the backend directory
Problem: ModuleNotFoundError during test execution
Solution: Ensure PYTHONPATH is correctly set:
export PYTHONPATH="/path/to/venv/lib/python3.11/site-packages:$PYTHONPATH"Problem: Tests fail due to external service connection errors
Solution: Currently, no external services are required for testing. If Redis or other services are added in the future, ensure they are properly configured in the workflow.
Problem: Package installation fails
Solution: Clear cache and reinstall:
pip cache purge
pip install -r requirements.txt --no-cache-dirProblem: SQLite database conflicts
Solution: Ensure tests use isolated SQLite databases:
SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db"Problem: Coverage upload fails with "No coverage reports found"
Solution:
- Ensure
CODECOV_TOKENsecret is set in repository settings - Verify coverage files are generated in the correct directory
- Check that pytest-cov is properly installed and configured
- Ensure the
directoryparameter points to the correct location
Debugging Steps:
# Check if coverage files exist
ls -la backend/coverage.xml
ls -la backend/htmlcov/
# Verify pytest-cov installation
pip list | grep coverage- Check Workflow Logs: Review the complete workflow execution logs
- Verify Environment: Ensure all environment variables are set correctly
- Test Locally: Run the same commands locally to reproduce issues
- Check Dependencies: Verify all required packages are in requirements.txt
- Service Health: Confirm Redis service is running and accessible
- Dependency Caching: Uses GitHub Actions cache for pip packages
- Parallel Execution: Tests run in parallel where possible
- Lightweight Setup: No external services required for testing
- Artifact Cleanup: Automatically cleans up test artifacts
- Python Version: Update
python-versionin setup-python action - Dependencies: Update
requirements.txtfor new packages - Environment Variables: Add new variables as needed
- Service Containers: Add new services if required
- Workflow Status: Check Actions tab in GitHub repository
- Coverage Trends: Monitor Codecov dashboard for coverage trends
- Performance: Track workflow execution times
- Failures: Review failed workflow runs for patterns
- Keep Dependencies Updated: Regularly update requirements.txt
- Test Locally First: Always test changes locally before pushing
- Monitor Coverage: Maintain high test coverage
- Review Logs: Check workflow logs for optimization opportunities
- Document Changes: Update this documentation when workflow changes