78 lines
2.5 KiB
YAML
78 lines
2.5 KiB
YAML
# Standalone reusable workflow for Node/Vite static sites.
|
||
# Does not reference reusable-release-skill.yaml; skill workflows remain unchanged.
|
||
#
|
||
# Node:请在 Runner 上预装 Node 20+(勿用 actions/setup-node,避免每次从 GitHub 拉包)。
|
||
# npm:通过 npm_registry 输入使用国内镜像(默认 npmmirror)。
|
||
|
||
name: Reusable Frontend Deploy
|
||
|
||
on:
|
||
workflow_call:
|
||
inputs:
|
||
deploy_path:
|
||
description: "Target directory for static files (trailing slash optional)"
|
||
required: false
|
||
type: string
|
||
default: "/www/wwwroot/fangzhen"
|
||
build_command:
|
||
required: false
|
||
type: string
|
||
default: "npm run build:jc2009"
|
||
npm_registry:
|
||
description: "npm registry (e.g. npmmirror for CN)"
|
||
required: false
|
||
type: string
|
||
default: "https://registry.npmmirror.com"
|
||
runs_on:
|
||
description: "Runner label; must match a registered runner"
|
||
required: false
|
||
type: string
|
||
default: "ubuntu-latest"
|
||
chown_www:
|
||
description: "Run chown -R www:www after sync (requires permission on runner)"
|
||
required: false
|
||
type: boolean
|
||
default: true
|
||
|
||
jobs:
|
||
build-and-deploy:
|
||
runs-on: ${{ inputs.runs_on }}
|
||
env:
|
||
NPM_CONFIG_REGISTRY: ${{ inputs.npm_registry }}
|
||
steps:
|
||
- name: Checkout
|
||
uses: http://120.25.191.12:3000/admin/actions-checkout@v4
|
||
|
||
- name: Check Node.js (pre-installed on runner)
|
||
run: |
|
||
set -e
|
||
command -v node >/dev/null || { echo "Runner 上未找到 node,请先安装 Node 20+"; exit 1; }
|
||
command -v npm >/dev/null || { echo "Runner 上未找到 npm"; exit 1; }
|
||
node -v
|
||
npm -v
|
||
NODE_MAJOR=$(node -p "process.versions.node.split('.')[0]")
|
||
test "$NODE_MAJOR" -ge 20 || { echo "需要 Node 20 及以上,当前: $(node -v)"; exit 1; }
|
||
|
||
- name: Install dependencies
|
||
run: npm ci
|
||
|
||
- name: Build
|
||
run: ${{ inputs.build_command }}
|
||
|
||
- name: Deploy (sync dist to web root)
|
||
run: |
|
||
set -euo pipefail
|
||
test -d dist
|
||
DEST="${{ inputs.deploy_path }}"
|
||
DEST="${DEST%/}"
|
||
mkdir -p "$DEST"
|
||
find "$DEST" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
|
||
cp -a dist/. "$DEST/"
|
||
|
||
- name: Set ownership for Nginx (Baota www)
|
||
if: ${{ inputs.chown_www }}
|
||
run: |
|
||
DEST="${{ inputs.deploy_path }}"
|
||
DEST="${DEST%/}"
|
||
chown -R www:www "$DEST" || chown -R nginx:nginx "$DEST" || true
|