Design a GitHub Actions CI/CD Pipeline with Testing, Building, and Deployment
Create a production-grade GitHub Actions CI/CD pipeline with test matrix, security scanning, Docker deployment, and notifications.
๐ The Prompt
Generate a complete GitHub Actions CI/CD workflow file (`.github/workflows/ci-cd.yml`) for a [PROJECT_TYPE] project using [LANGUAGE_AND_FRAMEWORK]. The repository structure has [REPO_STRUCTURE_SUMMARY].
**Pipeline Requirements:**
1. **Trigger Conditions**:
- Run on push to `main` and `develop` branches
- Run on pull requests targeting `main`
- Allow manual dispatch with an input parameter for [MANUAL_INPUT_PARAM]
2. **CI Jobs**:
- **Lint & Format Check**: Run [LINTER_TOOL] and [FORMATTER_TOOL] with fail-on-warning
- **Test Matrix**: Execute tests across [VERSIONS_MATRIX] (e.g., Node 18/20, Python 3.10/3.12) on ubuntu-latest
- **Security Scan**: Integrate [SECURITY_TOOL] (e.g., Snyk, Trivy, CodeQL) to scan dependencies
- **Build**: Compile/bundle the project and upload artifacts using `actions/upload-artifact`
3. **CD Jobs** (only on `main` push):
- Build a Docker image tagged with `${{ github.sha }}` and `latest`
- Push to [CONTAINER_REGISTRY] (GHCR, ECR, Docker Hub)
- Deploy to [DEPLOYMENT_TARGET] (e.g., AWS ECS, Kubernetes, Vercel) using [DEPLOYMENT_METHOD]
- Run a post-deployment smoke test hitting [HEALTH_CHECK_URL]
4. **Optimizations**:
- Cache dependencies using the appropriate cache action
- Use `concurrency` to cancel in-progress runs on the same branch
- Store secrets references for [SECRET_LIST]
5. **Notifications**: Send a Slack/Discord notification on failure using a webhook stored in secrets.
Include inline comments explaining each step. Use reusable workflow calls or composite actions where it reduces duplication.
๐ก Tips for Better Results
Specify your exact language versions and package manager (npm, yarn, pnpm, pip, poetry) for accurate caching configuration. List all required secrets upfront so the workflow references them correctly. Test the workflow on a feature branch first by temporarily adding your branch to the trigger list.
๐ฏ Use Cases
DevOps engineers and full-stack developers use this when setting up or modernizing a CI/CD pipeline for repositories that need automated testing, security checks, containerized builds, and zero-downtime deployments.