调整流水线

This commit is contained in:
2026-04-16 13:58:32 +08:00
parent 8778d641ab
commit a6bbd89350

View File

@@ -4,6 +4,9 @@
# Node请在 Runner 上预装 Node 20+(勿用 actions/setup-node避免每次从 GitHub 拉包)。 # Node请在 Runner 上预装 Node 20+(勿用 actions/setup-node避免每次从 GitHub 拉包)。
# npm通过 npm_registry 输入使用国内镜像(默认 npmmirror # npm通过 npm_registry 输入使用国内镜像(默认 npmmirror
# Checkout不用 actions/checkouthost 模式下 JS Action 仍会进无 Node 的容器);改用 git + github.token。 # Checkout不用 actions/checkouthost 模式下 JS Action 仍会进无 Node 的容器);改用 git + github.token。
# 重要act_runner 会把 run: 脚本写到 $GITHUB_WORKSPACE/workflow/*.sh
# 所以 checkout 绝对不能在 workspace 根上 rm -rf ./*,否则会把自己这个脚本一起删了。
# 解决办法:克隆到 $GITHUB_WORKSPACE/_src 子目录,后续 step 都在该子目录操作。
# 浅拉不要用「裸 SHA」作 fetch 参数Gitea 上易失败);按分支 clone 再对齐 SHA。 # 浅拉不要用「裸 SHA」作 fetch 参数Gitea 上易失败);按分支 clone 再对齐 SHA。
name: Reusable Frontend Deploy name: Reusable Frontend Deploy
@@ -42,10 +45,13 @@ jobs:
defaults: defaults:
run: run:
shell: bash shell: bash
working-directory: ${{ github.workspace }}/_src
env: env:
NPM_CONFIG_REGISTRY: ${{ inputs.npm_registry }} NPM_CONFIG_REGISTRY: ${{ inputs.npm_registry }}
steps: steps:
- name: Checkout - name: Checkout
# 这一步在 workspace 根执行,不能用默认的 _src此时还不存在
working-directory: ${{ github.workspace }}
env: env:
GITEA_HOST: git.jc2009.com GITEA_HOST: git.jc2009.com
GITEA_TOKEN: ${{ github.token }} GITEA_TOKEN: ${{ github.token }}
@@ -59,23 +65,25 @@ jobs:
TOKEN="${GITEA_TOKEN:-${GITHUB_TOKEN:-}}" TOKEN="${GITEA_TOKEN:-${GITHUB_TOKEN:-}}"
test -n "$TOKEN" || { echo "Checkout: empty token (github.token not available to this job)"; exit 1; } test -n "$TOKEN" || { echo "Checkout: empty token (github.token not available to this job)"; exit 1; }
URL="https://x-access-token:${TOKEN}@${GITEA_HOST}/${REPO}.git" URL="https://x-access-token:${TOKEN}@${GITEA_HOST}/${REPO}.git"
WS="${GITHUB_WORKSPACE:-$(pwd)}"
cd "$WS" SRC_DIR="${GITHUB_WORKSPACE}/_src"
shopt -s dotglob nullglob || true # 只清理 _src不动 workspace 根(保护 runner 写入的 workflow/*.sh
rm -rf ./* ./.??* 2>/dev/null || true rm -rf "$SRC_DIR"
git clone --depth 1 --branch "$BRANCH" "$URL" . git clone --depth 1 --branch "$BRANCH" "$URL" "$SRC_DIR"
cd "$SRC_DIR"
if [ "$(git rev-parse HEAD)" != "$SHA" ]; then if [ "$(git rev-parse HEAD)" != "$SHA" ]; then
git fetch --depth 200 origin "refs/heads/${BRANCH}" git fetch --depth 200 origin "refs/heads/${BRANCH}"
git checkout --force "$SHA" git checkout --force "$SHA"
fi fi
echo "Checked out $(git rev-parse HEAD) to $SRC_DIR"
- name: Check Node.js (pre-installed on runner) - name: Check Node.js (pre-installed on runner)
run: | run: |
set -e set -e
command -v node >/dev/null || { echo "Runner 上未找到 node请先安装 Node 20+"; exit 1; } command -v node >/dev/null || { echo "Runner 上未找到 node请先安装 Node 20+"; exit 1; }
command -v npm >/dev/null || { echo "Runner 上未找到 npm"; exit 1; } command -v npm >/dev/null || { echo "Runner 上未找到 npm"; exit 1; }
node -v node -v
npm -v npm -v
NODE_MAJOR=$(node -p "process.versions.node.split('.')[0]") NODE_MAJOR=$(node -p "process.versions.node.split('.')[0]")
test "$NODE_MAJOR" -ge 20 || { echo "需要 Node 20 及以上,当前: $(node -v)"; exit 1; } test "$NODE_MAJOR" -ge 20 || { echo "需要 Node 20 及以上,当前: $(node -v)"; exit 1; }
@@ -97,7 +105,7 @@ jobs:
- name: Set ownership for Nginx (Baota www) - name: Set ownership for Nginx (Baota www)
run: | run: |
case "${{ inputs.chown_www }}" in false|False|"false") exit 0 ;; esac if [ "${{ inputs.chown_www }}" != "true" ]; then exit 0; fi
DEST="${{ inputs.deploy_path }}" DEST="${{ inputs.deploy_path }}"
DEST="${DEST%/}" DEST="${DEST%/}"
chown -R www:www "$DEST" || chown -R nginx:nginx "$DEST" || true chown -R www:www "$DEST" || chown -R nginx:nginx "$DEST" || true