Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🐛 Bug Fix: 修复部署脚本中环境变量推送失败的问题
📋 问题描述
在 CI/CD 部署过程中,
pushPagesSecret函数在推送环境变量到 Cloudflare Pages 时失败,报错:错误日志:
❌ Failed to push secrets: Error: Command failed: pnpm dlx wrangler pages secret bulk /home/runner/work/***/.env.runtime🔍 根本原因
wrangler pages secret bulk命令要求输入文件必须是有效的 JSON 格式,但原代码生成的.env.runtime文件是标准的.env格式(键值对格式):# ❌ 原格式(不被接受) AUTH_GITHUB_ID=xxx AUTH_SECRET=yyy而 Wrangler 期望的格式是:
✨ 解决方案
修改
scripts/deploy/index.ts中的pushPagesSecret函数:.env格式的环境变量解析为 JavaScript 对象,然后使用JSON.stringify()转换为 JSON 格式.env.runtime改为.env.runtime.json,更清晰地表明文件格式indexOf('=')替代split('='),正确处理值中包含=的情况🧪 测试验证
📊 影响范围
scripts/deploy/index.ts