Location Detection AI - Job Management API
This project uses GitHub Actions for automated builds, testing, and deployment.
The CI/CD pipeline is triggered by:
- Push to main branch: Triggers build, lint, test, and deployment to dev environment
- Pull requests to main: Triggers build, lint, and test (no deployment)
- Tagged releases (v)*: Triggers build, lint, test, and deployment to prod environment
The pipeline consists of the following jobs:
- Build: Builds the SAM application using
sam build - Lint: Runs flake8 and mypy for code quality checks
- Test: Runs unit, integration, and E2E tests using pytest
- Deploy Dev: Deploys to dev environment on merge to main
- Deploy Prod: Deploys to prod environment on tagged releases
The following secrets must be configured in GitHub repository settings:
AWS_ACCESS_KEY_ID: AWS access key for deploymentAWS_SECRET_ACCESS_KEY: AWS secret access key for deployment
Note: These secrets should be configured with least privilege IAM permissions for deployment only.
The project uses environment-specific SAM configuration files:
samconfig.toml: Default configuration for local developmentsamconfig.dev.toml: Dev environment configurationsamconfig.prod.toml: Prod environment configuration
Each environment uses separate CloudFormation stacks:
- Dev:
location-detection-dev - Prod:
location-detection-prod
Dev deployments happen automatically when code is merged to the main branch. The pipeline will:
- Build the SAM application
- Run linting and type checking
- Run all tests (unit, integration, E2E)
- Deploy to dev environment if all checks pass
Prod deployments happen automatically when a tag starting with v is pushed:
git tag v1.0.0
git push origin v1.0.0The pipeline will:
- Build the SAM application
- Run linting and type checking
- Run all tests (unit, integration, E2E)
- Deploy to prod environment if all checks pass
- Create a GitHub release with deployment details
If a deployment fails or causes issues:
- CloudFormation Rollback: SAM/CloudFormation automatically rolls back failed deployments
- Manual Rollback: Use CloudFormation console or CLI to rollback to a previous stack version
- Code Rollback: Revert the commit and push to trigger a new deployment
# Revert last commit
git revert HEAD
git push origin main
# Or rollback to a specific commit
git reset --hard <commit-hash>
git push --force origin mainWarning: Force pushing should be done with caution and team coordination.
The pipeline automatically reports status:
- Pull Requests: Status checks appear on PRs showing build, lint, and test results
- Deployments: Deployment status is logged in workflow runs
- Releases: Production deployments create GitHub releases with API URLs
For local development and testing:
# Build locally
sam build
# Run tests locally
pytest src/tests/unit/ -v
pytest src/tests/integration/ -v
# Deploy locally (requires AWS credentials)
sam deploy --config-env devBuild Failures:
- Check Python version (requires 3.11)
- Verify SAM CLI is installed correctly
- Check for dependency conflicts
Test Failures:
- Run tests locally to reproduce issues
- Check test logs in GitHub Actions workflow output
- Verify test data and mocks are configured correctly
Deployment Failures:
- Verify AWS credentials are configured correctly in GitHub Secrets
- Check IAM permissions for the deployment role
- Review CloudFormation stack events in AWS Console
- Verify SAM config files are correct for the environment
Linting Failures:
- Run
flake8 src/locally to see issues - Fix code style violations
- Update type hints if mypy reports errors
The CI/CD workflow configuration is located at:
.github/workflows/ci-cd.yml