Buckets:
| #!/usr/bin/env python3 | |
| """Scaffold a CI workflow and .env.example for a project. | |
| Stdlib only -- no third-party dependencies (references/conventions.md). | |
| Follows references/ci-cd-pipelines.md: lint+typecheck+test+build as required | |
| gates (DO003), dependency caching (DO004), and the platform-appropriate | |
| deploy step (DO007) -- Vercel/Netlify/Cloudflare Pages deploy via their own | |
| git integration by default, so no deploy step is added for those; Cloudflare | |
| Workers and Railway/Render/Fly.io need an explicit deploy step in CI. | |
| Examples: | |
| python3 generate.py --stack node --platform vercel --output ./my-app | |
| python3 generate.py --stack python --platform railway --output ./my-app | |
| python3 generate.py --stack node --platform cloudflare-workers \\ | |
| --env-vars "DATABASE_URL:Postgres connection string,STRIPE_SECRET_KEY:Stripe secret key" \\ | |
| --output ./my-app --dry-run | |
| """ | |
| import argparse | |
| from pathlib import Path | |
| STACKS = ["node", "python"] | |
| PLATFORMS = ["vercel", "netlify", "cloudflare-pages", "cloudflare-workers", "railway"] | |
| # Platforms whose native git integration handles deploy automatically -- | |
| # no deploy step needed in the CI workflow itself (DO007, DO009). | |
| GIT_INTEGRATED_PLATFORMS = {"vercel", "netlify", "cloudflare-pages"} | |
| def render_ci_node(platform: str) -> str: | |
| deploy_step = "" | |
| if platform == "cloudflare-workers": | |
| deploy_step = """ | |
| - name: Deploy to Cloudflare Workers | |
| if: github.ref == 'refs/heads/main' | |
| run: npx wrangler deploy | |
| env: | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}""" | |
| elif platform == "railway": | |
| deploy_step = """ | |
| - name: Deploy to Railway | |
| if: github.ref == 'refs/heads/main' | |
| run: npx @railway/cli up --service ${{ secrets.RAILWAY_SERVICE_ID }} | |
| env: | |
| RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}""" | |
| note = "" | |
| if platform in GIT_INTEGRATED_PLATFORMS: | |
| note = f"\n# No deploy step below -- {platform} deploys automatically via its own git integration (DO007, DO009).\n# This workflow only needs to gate merges on lint/typecheck/test/build passing.\n" | |
| return f"""name: CI | |
| {note} | |
| on: | |
| pull_request: | |
| push: | |
| branches: [main] | |
| jobs: | |
| ci: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Lint | |
| run: npm run lint | |
| - name: Typecheck | |
| run: npm run typecheck | |
| - name: Test | |
| run: npm test | |
| - name: Build | |
| run: npm run build | |
| {deploy_step} | |
| """ | |
| def render_ci_python(platform: str) -> str: | |
| deploy_step = "" | |
| if platform == "railway": | |
| deploy_step = """ | |
| - name: Deploy to Railway | |
| if: github.ref == 'refs/heads/main' | |
| run: npx @railway/cli up --service ${{ secrets.RAILWAY_SERVICE_ID }} | |
| env: | |
| RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}""" | |
| note = "" | |
| if platform in GIT_INTEGRATED_PLATFORMS: | |
| note = f"\n# No deploy step below -- {platform} deploys automatically via its own git integration (DO007, DO009).\n" | |
| return f"""name: CI | |
| {note} | |
| on: | |
| pull_request: | |
| push: | |
| branches: [main] | |
| jobs: | |
| ci: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| cache: pip | |
| - name: Install dependencies | |
| run: pip install -r requirements.txt | |
| - name: Lint | |
| run: ruff check . | |
| - name: Typecheck | |
| run: mypy . | |
| - name: Test | |
| run: pytest | |
| {deploy_step} | |
| """ | |
| CI_RENDERERS = {"node": render_ci_node, "python": render_ci_python} | |
| def render_env_example(env_vars) -> str: | |
| lines = [ | |
| "# Generated by fullstack-pro-max scripts/devops/generate.py", | |
| "# Fill in real values in a local .env (gitignored) -- never commit real secrets (DO046).", | |
| "", | |
| ] | |
| if not env_vars: | |
| lines += [ | |
| "# No --env-vars provided -- add your project's required variables here, e.g.:", | |
| "# DATABASE_URL=", | |
| "# NEXT_PUBLIC_SUPABASE_URL= # safe to expose client-side (DO049)", | |
| "# SUPABASE_SERVICE_ROLE_KEY= # server-only, never NEXT_PUBLIC_ (DO050)", | |
| ] | |
| else: | |
| for name, desc in env_vars: | |
| if desc: | |
| lines.append(f"# {desc}") | |
| lines.append(f"{name}=") | |
| lines.append("") | |
| return "\n".join(lines) + "\n" | |
| def parse_env_vars(spec: str): | |
| if not spec: | |
| return [] | |
| out = [] | |
| for part in spec.split(","): | |
| part = part.strip() | |
| if not part: | |
| continue | |
| if ":" in part: | |
| name, desc = part.split(":", 1) | |
| else: | |
| name, desc = part, "" | |
| out.append((name.strip(), desc.strip())) | |
| return out | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) | |
| parser.add_argument("--stack", required=True, choices=STACKS) | |
| parser.add_argument("--platform", required=True, choices=PLATFORMS) | |
| parser.add_argument("--env-vars", default="", help='Comma-separated "NAME:description" pairs') | |
| parser.add_argument("--output", type=Path, default=Path("./generated")) | |
| parser.add_argument("--dry-run", action="store_true") | |
| args = parser.parse_args() | |
| ci_content = CI_RENDERERS[args.stack](args.platform) | |
| env_content = render_env_example(parse_env_vars(args.env_vars)) | |
| files = [ | |
| (".github/workflows/ci.yml", ci_content), | |
| (".env.example", env_content), | |
| ] | |
| for rel_path, content in files: | |
| target = args.output / rel_path | |
| if args.dry_run: | |
| print(f"--- would write {target} ---") | |
| print(content) | |
| else: | |
| target.parent.mkdir(parents=True, exist_ok=True) | |
| target.write_text(content, encoding="utf-8") | |
| print(f"wrote {target}") | |
| if not args.dry_run: | |
| print(f"\nGenerated CI workflow for {args.stack} on {args.platform}, plus .env.example.") | |
| if args.platform in GIT_INTEGRATED_PLATFORMS: | |
| print(f"{args.platform} deploys via its own git integration -- no deploy step needed in CI.") | |
| print("Add required secrets to the platform's secret store before this workflow can deploy (DO018, DO043).") | |
| if __name__ == "__main__": | |
| main() | |
Xet Storage Details
- Size:
- 6.5 kB
- Xet hash:
- b4cfaf410e5c2bd090230d33a421e087adbd9258546904d2fb12b2499fb5f1bb
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.