From d76b048bb97d985425033a9a2c5404a9fee66e68 Mon Sep 17 00:00:00 2001 From: chenhang Date: Fri, 12 Jun 2026 15:05:37 +0800 Subject: [PATCH] chore: move env examples to env-example/ and unify CDN env source - Reorganize env example files into a dedicated env-example/ directory for clarity - Update .gitignore to ignore env files (with examples now in env-example/) - Unify CDN credentials (CF_ZONE_ID / CF_API_TOKEN) to be sourced from .env.local in both test and production deploys - Update git_hooks/post-receive to copy production env example from new location - Update deploy scripts (pre_release_web.sh, release_web.sh) to copy the appropriate env example into .env.local before building - Update _deploy_lib.sh purge_cdn_cache to source from .env.local instead of .env --- .gitignore | 7 +------ .../.env.development.example | 0 .env.local.example => env-example/.env.local.example | 0 .../.env.production.example | 0 git_hooks/post-receive | 4 ++-- scripts/deploy/_deploy_lib.sh | 8 ++++---- scripts/release/pre_release_web.sh | 4 ++++ scripts/release/release_web.sh | 4 ++++ 8 files changed, 15 insertions(+), 12 deletions(-) rename .env.development.example => env-example/.env.development.example (100%) rename .env.local.example => env-example/.env.local.example (100%) rename .env.production.example => env-example/.env.production.example (100%) diff --git a/.gitignore b/.gitignore index 31b0b4c7..c8284491 100644 --- a/.gitignore +++ b/.gitignore @@ -30,16 +30,11 @@ yarn-debug.log* yarn-error.log* .pnpm-debug.log* -# env files (can opt-in for committing if needed) +# env files .env .env.local .env.development -.env.test .env.production -!.env.example -!.env.development.example -!.env.test.example -!.env.production.example # deploy archives (scripts/deploy/_deploy_lib.sh 的 archive() 生成) archives/ diff --git a/.env.development.example b/env-example/.env.development.example similarity index 100% rename from .env.development.example rename to env-example/.env.development.example diff --git a/.env.local.example b/env-example/.env.local.example similarity index 100% rename from .env.local.example rename to env-example/.env.local.example diff --git a/.env.production.example b/env-example/.env.production.example similarity index 100% rename from .env.production.example rename to env-example/.env.production.example diff --git a/git_hooks/post-receive b/git_hooks/post-receive index 55a9ee71..bd92f59b 100755 --- a/git_hooks/post-receive +++ b/git_hooks/post-receive @@ -8,7 +8,7 @@ # - 内部 = `npm run build && npm run start` # - 实际调用 `pnpm run build:start`(项目使用 pnpm) -# 准备生产环境变量(从 .env.production.example 复制 → .env.production) -cp -f .env.production.example .env.production +# 准备生产环境变量(从 env-example/.env.production.example 复制 → .env.production) +cp -f env-example/.env.production.example .env.production pnpm run build:start diff --git a/scripts/deploy/_deploy_lib.sh b/scripts/deploy/_deploy_lib.sh index 01fce4b3..626ef7cc 100755 --- a/scripts/deploy/_deploy_lib.sh +++ b/scripts/deploy/_deploy_lib.sh @@ -87,14 +87,14 @@ bump_version() { } # 清除 Cloudflare CDN 缓存 -# 凭据从 .env / .env.local 读(CF_ZONE_ID / CF_API_TOKEN) +# 凭据从 .env.local 读(CF_ZONE_ID / CF_API_TOKEN) purge_cdn_cache() { - # 从 .env 读 CDN 凭据(Next.js 不读取,bash 直接 source) - if [ -f .env ]; then + # 从 .env.local 读 CDN 凭据(Next.js 不读取,bash 直接 source) + if [ -f .env.local ]; then # shell 解析 KEY=VALUE(忽略注释 / 引号) set -a # shellcheck disable=SC1091 - source .env 2>/dev/null || true + source .env.local 2>/dev/null || true set +a fi diff --git a/scripts/release/pre_release_web.sh b/scripts/release/pre_release_web.sh index d859aae4..56e6a1a6 100755 --- a/scripts/release/pre_release_web.sh +++ b/scripts/release/pre_release_web.sh @@ -18,6 +18,10 @@ cp -f icons/test/favicon.ico public/favicon.ico cp -f icons/test/icons/Icon-192.png public/images/icons/Icon-192.png cp -f icons/test/icons/Icon-512.png public/images/icons/Icon-512.png +# 准备测试环境变量(env-example/.env.local.example → .env.local,供 purge_cdn_cache 读 CDN 凭据) +echo "=== 准备测试环境变量(env-example/.env.local.example → .env.local) ===" +cp -f env-example/.env.local.example .env.local + echo "=== 执行构建部署脚本(测试环境)===" ./scripts/deploy/deploy_web_test.sh diff --git a/scripts/release/release_web.sh b/scripts/release/release_web.sh index 737fc29b..691895b6 100755 --- a/scripts/release/release_web.sh +++ b/scripts/release/release_web.sh @@ -18,6 +18,10 @@ cp -f icons/production/favicon.ico public/favicon.ico cp -f icons/production/icons/Icon-192.png public/images/icons/Icon-192.png cp -f icons/production/icons/Icon-512.png public/images/icons/Icon-512.png +# 准备生产环境变量(env-example/.env.production.example → .env.local,供 purge_cdn_cache 读 CDN 凭据) +echo "=== 准备生产环境变量(env-example/.env.production.example → .env.local) ===" +cp -f env-example/.env.production.example .env.local + echo "=== 执行构建部署脚本 ===" ./scripts/deploy/deploy_web.sh