Files
wehub-resource-sync bb5c75ce05
Component Security Validation / Security Audit (push) Has been cancelled
Deploy to Cloudflare Pages / deploy (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:38:58 +08:00

1 line
9.3 KiB
JSON

{"content": "---\nallowed-tools: Read, Write, Edit, Bash\nargument-hint: [platform] | --github-actions | --gitlab-ci | --jenkins | --full-setup\ndescription: Setup comprehensive CI/CD pipeline with automated testing, building, and deployment\n---\n\n# CI/CD Pipeline Setup\n\nSetup continuous integration pipeline: $ARGUMENTS\n\n## Current Project Analysis\n\n- Project type: @package.json or @setup.py or @go.mod or @pom.xml (detect language/framework)\n- Existing workflows: !`find .github/workflows -name \"*.yml\" 2>/dev/null | head -3`\n- Git branches: !`git branch -r | head -5`\n- Dependencies: @package-lock.json or @requirements.txt or @go.sum (if exists)\n- Build scripts: Check for build commands in package.json or Makefile\n\n## Task\n\nImplement comprehensive CI/CD following best practices: $ARGUMENTS\n\n1. **Project Analysis**\n - Identify the technology stack and deployment requirements\n - Review existing build and test processes\n - Understand deployment environments (dev, staging, prod)\n - Assess current version control and branching strategy\n\n2. **CI/CD Platform Selection**\n - Choose appropriate CI/CD platform based on requirements:\n - **GitHub Actions**: Native GitHub integration, extensive marketplace\n - **GitLab CI**: Built-in GitLab, comprehensive DevOps platform\n - **Jenkins**: Self-hosted, highly customizable, extensive plugins\n - **CircleCI**: Cloud-based, optimized for speed\n - **Azure DevOps**: Microsoft ecosystem integration\n - **AWS CodePipeline**: AWS-native solution\n\n3. **Repository Setup**\n - Ensure proper `.gitignore` configuration\n - Set up branch protection rules\n - Configure merge requirements and reviews\n - Establish semantic versioning strategy\n\n4. **Build Pipeline Configuration**\n \n **GitHub Actions Example:**\n ```yaml\n name: CI/CD Pipeline\n \n on:\n push:\n branches: [ main, develop ]\n pull_request:\n branches: [ main ]\n \n jobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v3\n - name: Setup Node.js\n uses: actions/setup-node@v3\n with:\n node-version: '18'\n cache: 'npm'\n - run: npm ci\n - run: npm run test\n - run: npm run build\n ```\n\n **GitLab CI Example:**\n ```yaml\n stages:\n - test\n - build\n - deploy\n \n test:\n stage: test\n script:\n - npm ci\n - npm run test\n cache:\n paths:\n - node_modules/\n ```\n\n5. **Environment Configuration**\n - Set up environment variables and secrets\n - Configure different environments (dev, staging, prod)\n - Implement environment-specific configurations\n - Set up secure secret management\n\n6. **Automated Testing Integration**\n - Configure unit test execution\n - Set up integration test running\n - Implement E2E test execution\n - Configure test reporting and coverage\n\n **Multi-stage Testing:**\n ```yaml\n test:\n strategy:\n matrix:\n node-version: [16, 18, 20]\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v3\n - uses: actions/setup-node@v3\n with:\n node-version: ${{ matrix.node-version }}\n - run: npm ci\n - run: npm test\n ```\n\n7. **Code Quality Gates**\n - Integrate linting and formatting checks\n - Set up static code analysis (SonarQube, CodeClimate)\n - Configure security vulnerability scanning\n - Implement code coverage thresholds\n\n8. **Build Optimization**\n - Configure build caching strategies\n - Implement parallel job execution\n - Optimize Docker image builds\n - Set up artifact management\n\n **Caching Example:**\n ```yaml\n - name: Cache node modules\n uses: actions/cache@v3\n with:\n path: ~/.npm\n key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}\n restore-keys: |\n ${{ runner.os }}-node-\n ```\n\n9. **Docker Integration**\n - Create optimized Dockerfiles\n - Set up multi-stage builds\n - Configure container registry integration\n - Implement security scanning for images\n\n **Multi-stage Dockerfile:**\n ```dockerfile\n FROM node:18-alpine AS builder\n WORKDIR /app\n COPY package*.json ./\n RUN npm ci --only=production\n \n FROM node:18-alpine AS runtime\n WORKDIR /app\n COPY --from=builder /app/node_modules ./node_modules\n COPY . .\n EXPOSE 3000\n CMD [\"npm\", \"start\"]\n ```\n\n10. **Deployment Strategies**\n - Implement blue-green deployment\n - Set up canary releases\n - Configure rolling updates\n - Implement feature flags integration\n\n11. **Infrastructure as Code**\n - Use Terraform, CloudFormation, or similar tools\n - Version control infrastructure definitions\n - Implement infrastructure testing\n - Set up automated infrastructure provisioning\n\n12. **Monitoring and Observability**\n - Set up application performance monitoring\n - Configure log aggregation and analysis\n - Implement health checks and alerting\n - Set up deployment notifications\n\n13. **Security Integration**\n - Implement dependency vulnerability scanning\n - Set up container security scanning\n - Configure SAST (Static Application Security Testing)\n - Implement secrets scanning\n\n **Security Scanning Example:**\n ```yaml\n security:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v3\n - name: Run Snyk to check for vulnerabilities\n uses: snyk/actions/node@master\n env:\n SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}\n ```\n\n14. **Database Migration Handling**\n - Automate database schema migrations\n - Implement rollback strategies\n - Set up database seeding for testing\n - Configure backup and recovery procedures\n\n15. **Performance Testing Integration**\n - Set up load testing in pipeline\n - Configure performance benchmarks\n - Implement performance regression detection\n - Set up performance monitoring\n\n16. **Multi-Environment Deployment**\n - Configure staging environment deployment\n - Set up production deployment with approvals\n - Implement environment promotion workflow\n - Configure environment-specific configurations\n\n **Environment Deployment:**\n ```yaml\n deploy-staging:\n needs: test\n if: github.ref == 'refs/heads/develop'\n runs-on: ubuntu-latest\n steps:\n - name: Deploy to staging\n run: |\n # Deploy to staging environment\n \n deploy-production:\n needs: test\n if: github.ref == 'refs/heads/main'\n runs-on: ubuntu-latest\n environment: production\n steps:\n - name: Deploy to production\n run: |\n # Deploy to production environment\n ```\n\n17. **Rollback and Recovery**\n - Implement automated rollback procedures\n - Set up deployment verification tests\n - Configure failure detection and alerts\n - Document manual recovery procedures\n\n18. **Notification and Reporting**\n - Set up Slack/Teams integration for notifications\n - Configure email alerts for failures\n - Implement deployment status reporting\n - Set up metrics dashboards\n\n19. **Compliance and Auditing**\n - Implement deployment audit trails\n - Set up compliance checks (SOC 2, HIPAA, etc.)\n - Configure approval workflows for sensitive deployments\n - Document change management processes\n\n20. **Pipeline Optimization**\n - Monitor pipeline performance and costs\n - Implement pipeline parallelization\n - Optimize resource allocation\n - Set up pipeline analytics and reporting\n\n**Best Practices:**\n\n1. **Fail Fast**: Implement early failure detection\n2. **Parallel Execution**: Run independent jobs in parallel\n3. **Caching**: Cache dependencies and build artifacts\n4. **Security**: Never expose secrets in logs\n5. **Documentation**: Document pipeline processes and procedures\n6. **Monitoring**: Monitor pipeline health and performance\n7. **Testing**: Test pipeline changes in feature branches\n8. **Rollback**: Always have a rollback strategy\n\n**Sample Complete Pipeline:**\n```yaml\nname: Full CI/CD Pipeline\n\non:\n push:\n branches: [ main, develop ]\n pull_request:\n branches: [ main ]\n\njobs:\n lint-and-test:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v3\n - uses: actions/setup-node@v3\n with:\n node-version: '18'\n cache: 'npm'\n - run: npm ci\n - run: npm run lint\n - run: npm run test:coverage\n - run: npm run build\n\n security-scan:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v3\n - name: Security scan\n run: npm audit --audit-level=high\n\n deploy-staging:\n needs: [lint-and-test, security-scan]\n if: github.ref == 'refs/heads/develop'\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v3\n - name: Deploy to staging\n run: echo \"Deploying to staging\"\n\n deploy-production:\n needs: [lint-and-test, security-scan]\n if: github.ref == 'refs/heads/main'\n runs-on: ubuntu-latest\n environment: production\n steps:\n - uses: actions/checkout@v3\n - name: Deploy to production\n run: echo \"Deploying to production\"\n```\n\nStart with basic CI and gradually add more sophisticated features as your team and project mature."}