# 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)。 # Checkout:不用 actions/checkout(host 模式下 JS Action 仍会进无 Node 的容器);改用 git + github.token。 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/sandbox/web" 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 env: GITEA_HOST: git.jc2009.com GITEA_TOKEN: ${{ github.token }} run: | set -euo pipefail git config --global --add safe.directory '*' REPO="${{ github.repository }}" SHA="${{ github.sha }}" URL="https://x-access-token:${GITEA_TOKEN}@${GITEA_HOST}/${REPO}.git" WS="${GITHUB_WORKSPACE:-$(pwd)}" cd "$WS" if [ -d .git ]; then git remote set-url origin "$URL" || { git remote remove origin 2>/dev/null || true; git remote add origin "$URL"; } else shopt -s dotglob nullglob || true rm -rf ./* ./.??* 2>/dev/null || true git init git remote add origin "$URL" fi git fetch --depth 1 origin "$SHA" git checkout --force FETCH_HEAD - 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