ci: 避免覆盖现有 .env 文件并设置 IS_DEMO 默认值

在部署工作流中,现在会先检查 .env 文件是否存在。如果文件已存在,则跳过生成步骤以避免覆盖现有配置。
同时,在从 .example.env 生成新 .env 文件时,会默认将 IS_DEMO 设置为 true。
This commit is contained in:
augushong
2026-05-06 21:18:41 +08:00
parent 94d5bf5ce6
commit 8b45a8818b

View File

@@ -29,10 +29,11 @@ jobs:
DB_HOSTNAME: ${{ env.DB_HOSTNAME }} DB_HOSTNAME: ${{ env.DB_HOSTNAME }}
run: | run: |
set -euo pipefail set -euo pipefail
if [ ! -f .env ]; then
cp .example.env .env cp .example.env .env
awk -v host="$DB_HOSTNAME" -v newpwd="$MYSQL_PASSWORD" ' awk -v host="$DB_HOSTNAME" -v newpwd="$MYSQL_PASSWORD" '
BEGIN { has_host = 0; has_pwd = 0 } BEGIN { has_host = 0; has_pwd = 0; has_demo = 0 }
$0 ~ /^HOSTNAME=/ { $0 ~ /^HOSTNAME=/ {
print "HOSTNAME=" host print "HOSTNAME=" host
has_host = 1 has_host = 1
@@ -43,13 +44,22 @@ jobs:
has_pwd = 1 has_pwd = 1
next next
} }
$0 ~ /^IS_DEMO=/ {
print "IS_DEMO=true"
has_demo = 1
next
}
{ print } { print }
END { END {
if (!has_host) print "HOSTNAME=" host if (!has_host) print "HOSTNAME=" host
if (!has_pwd) print "PASSWORD=" newpwd if (!has_pwd) print "PASSWORD=" newpwd
if (!has_demo) print "IS_DEMO=true"
}' .env > .env.tmp }' .env > .env.tmp
mv .env.tmp .env mv .env.tmp .env
else
echo ".env exists in repository, skip generating/replacing."
fi
- name: 打包发布文件 - name: 打包发布文件
shell: bash shell: bash