mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 15:32:48 +08:00
ci: 避免覆盖现有 .env 文件并设置 IS_DEMO 默认值
在部署工作流中,现在会先检查 .env 文件是否存在。如果文件已存在,则跳过生成步骤以避免覆盖现有配置。 同时,在从 .example.env 生成新 .env 文件时,会默认将 IS_DEMO 设置为 true。
This commit is contained in:
@@ -29,27 +29,37 @@ jobs:
|
||||
DB_HOSTNAME: ${{ env.DB_HOSTNAME }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cp .example.env .env
|
||||
if [ ! -f .env ]; then
|
||||
cp .example.env .env
|
||||
|
||||
awk -v host="$DB_HOSTNAME" -v newpwd="$MYSQL_PASSWORD" '
|
||||
BEGIN { has_host = 0; has_pwd = 0 }
|
||||
$0 ~ /^HOSTNAME=/ {
|
||||
print "HOSTNAME=" host
|
||||
has_host = 1
|
||||
next
|
||||
}
|
||||
$0 ~ /^PASSWORD=/ {
|
||||
print "PASSWORD=" newpwd
|
||||
has_pwd = 1
|
||||
next
|
||||
}
|
||||
{ print }
|
||||
END {
|
||||
if (!has_host) print "HOSTNAME=" host
|
||||
if (!has_pwd) print "PASSWORD=" newpwd
|
||||
}' .env > .env.tmp
|
||||
awk -v host="$DB_HOSTNAME" -v newpwd="$MYSQL_PASSWORD" '
|
||||
BEGIN { has_host = 0; has_pwd = 0; has_demo = 0 }
|
||||
$0 ~ /^HOSTNAME=/ {
|
||||
print "HOSTNAME=" host
|
||||
has_host = 1
|
||||
next
|
||||
}
|
||||
$0 ~ /^PASSWORD=/ {
|
||||
print "PASSWORD=" newpwd
|
||||
has_pwd = 1
|
||||
next
|
||||
}
|
||||
$0 ~ /^IS_DEMO=/ {
|
||||
print "IS_DEMO=true"
|
||||
has_demo = 1
|
||||
next
|
||||
}
|
||||
{ print }
|
||||
END {
|
||||
if (!has_host) print "HOSTNAME=" host
|
||||
if (!has_pwd) print "PASSWORD=" newpwd
|
||||
if (!has_demo) print "IS_DEMO=true"
|
||||
}' .env > .env.tmp
|
||||
|
||||
mv .env.tmp .env
|
||||
mv .env.tmp .env
|
||||
else
|
||||
echo ".env exists in repository, skip generating/replacing."
|
||||
fi
|
||||
|
||||
- name: 打包发布文件
|
||||
shell: bash
|
||||
|
||||
Reference in New Issue
Block a user