GitHub Actions Integration Guide
This guide explains how to use your test suite with GitHub Actions for automated CI/CD.
π Quick Start
1. Choose Your Workflow
I've created multiple workflow options for you:
Option A: Simple Test Run (Recommended for beginners)
# File: .github/workflows/simple-test.yml
# - Basic test execution
# - Ubuntu Latest
# - Python 3.11
# - Minimal setup
Option B: Comprehensive CI/CD (Recommended for production)
# File: .github/workflows/ci.yml
# - Full pipeline with linting, security, coverage
# - Multiple Python versions
# - Integration tests
# - Package building
Option C: Multi-OS Testing (For cross-platform compatibility)
# File: .github/workflows/multi-os-test.yml
# - Tests on Ubuntu, Windows, macOS
# - Multiple Python versions
# - Cross-platform compatibility
2. Enable GitHub Actions
- Push your code to GitHub
- Go to your repository β Actions tab
- Select a workflow and click "Run workflow"
- Watch the tests run automatically!
π What Each Workflow Does
Simple Test Run (.github/workflows/simple-test.yml)
β
Installs system dependencies (tesseract, poppler, OpenGL)
β
Installs Python dependencies from requirements.txt
β
Downloads spaCy model
β
Creates dummy test data automatically
β
Runs your CLI tests
β
Runs pytest with coverage
Comprehensive CI/CD (.github/workflows/ci.yml)
β
Linting (Ruff, Black)
β
Unit tests (Python 3.10, 3.11, 3.12)
β
Integration tests
β
Security scanning (Safety, Bandit)
β
Coverage reporting
β
Package building (on main branch)
β
Artifact uploads
Multi-OS Testing (.github/workflows/multi-os-test.yml)
β
Tests on Ubuntu, Windows, macOS
β
Python 3.10, 3.11, 3.12
β
Cross-platform compatibility
β
OS-specific dependency handling
π§ How It Works
Automatic Test Data Creation
The workflows automatically create dummy test files when your example data is missing:
# .github/scripts/setup_test_data.py creates:
- example_data/example_of_emails_sent_to_a_professor_before_applying.pdf
- example_data/combined_case_notes.csv
- example_data/Bold minimalist professional cover letter.docx
- example_data/example_complaint_letter.jpg
- example_data/test_allow_list_*.csv
- example_data/partnership_toolkit_redact_*.csv
- example_data/example_outputs/doubled_output_joined.pdf_ocr_output.csv
System Dependencies
Each OS gets the right dependencies:
Ubuntu:
sudo apt-get install tesseract-ocr poppler-utils libgl1-mesa-glx
macOS:
brew install tesseract poppler
Windows:
# Handled by Python packages
Python Dependencies
pip install -r requirements.txt
pip install pytest pytest-cov reportlab pillow
π― Triggers
When Tests Run:
- β Push to main/dev branches
- β Pull requests to main/dev
- β Daily at 2 AM UTC (scheduled)
- β Manual trigger from GitHub UI
What Happens:
- Checkout code
- Install dependencies
- Create test data
- Run tests
- Generate reports
- Upload artifacts
π Test Results
Success Criteria:
- β All tests pass
- β No linting errors
- β Security checks pass
- β Coverage reports generated
Failure Handling:
- β Tests skip gracefully if files missing
- β AWS tests expected to fail without credentials
- β System dependency failures handled with fallbacks
π Monitoring
GitHub Actions Tab:
- View workflow runs
- See test results
- Download artifacts
- View logs
Artifacts Generated:
test-results.xml- JUnit test resultscoverage.xml- Coverage datahtmlcov/- HTML coverage reportbandit-report.json- Security scan results
Coverage Reports:
- Uploaded to Codecov automatically
- Available in GitHub Actions artifacts
- HTML reports for detailed analysis
π οΈ Customization
Adding New Tests:
- Add test methods to
test/test.py - Update
setup_test_data.pyif needed - Tests run automatically in all workflows
Modifying Workflows:
- Edit the
.ymlfile - Test locally first
- Push to trigger workflow
Environment Variables:
env:
PYTHON_VERSION: "3.11"
# Add your custom variables here
π¨ Troubleshooting
Common Issues:
"Example file not found"
- β Solution: Test data is created automatically
- β
Check:
setup_test_data.pyruns in workflow
"AWS credentials not configured"
- β Expected: AWS tests fail without credentials
- β Solution: Tests are designed to handle this
"System dependency error"
- β Check: OS-specific installation commands
- β Solution: Dependencies are installed automatically
"Test timeout"
- β Default: 10-minute timeout per test
- β Solution: Tests are designed to be fast
Debug Mode:
Add --verbose to pytest commands for detailed output:
pytest test/test.py -v --tb=short
π Performance
Optimizations:
- β Parallel execution where possible
- β Dependency caching for faster builds
- β Minimal system packages installed
- β Efficient test data creation
Build Times:
- Simple Test: ~5-10 minutes
- Comprehensive CI: ~15-20 minutes
- Multi-OS: ~20-30 minutes
π Security
Security Features:
- β Dependency scanning with Safety
- β Code scanning with Bandit
- β No secrets exposed in logs
- β Temporary test data cleaned up
Secrets Management:
- Use GitHub Secrets for sensitive data
- Never hardcode credentials in workflows
- Test data is dummy data only
π Success!
Once set up, your GitHub Actions will:
- Automatically test every push and PR
- Generate reports and coverage data
- Catch issues before they reach production
- Ensure compatibility across platforms
- Provide confidence in your code quality
π Next Steps
- Choose a workflow that fits your needs
- Push to GitHub to trigger the first run
- Monitor the Actions tab for results
- Customize as needed for your project
- Enjoy automated testing! π
Need help? Check the workflow logs in the GitHub Actions tab for detailed error messages and troubleshooting information.