From 8b45a8818b6590756f6f25e3db605dfd2e8b440f Mon Sep 17 00:00:00 2001 From: augushong Date: Wed, 6 May 2026 21:18:41 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E9=81=BF=E5=85=8D=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E7=8E=B0=E6=9C=89=20.env=20=E6=96=87=E4=BB=B6=E5=B9=B6?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=20IS=5FDEMO=20=E9=BB=98=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在部署工作流中,现在会先检查 .env 文件是否存在。如果文件已存在,则跳过生成步骤以避免覆盖现有配置。 同时,在从 .example.env 生成新 .env 文件时,会默认将 IS_DEMO 设置为 true。 --- .gitea/workflows/build-and-deploy.yml | 48 ++++++++++++++++----------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/.gitea/workflows/build-and-deploy.yml b/.gitea/workflows/build-and-deploy.yml index bff4cbc..fe2a479 100644 --- a/.gitea/workflows/build-and-deploy.yml +++ b/.gitea/workflows/build-and-deploy.yml @@ -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