diff --git a/.github/workflows/reusable-release-frontend.yaml b/.github/workflows/reusable-release-frontend.yaml new file mode 100644 index 0000000..a9df53d --- /dev/null +++ b/.github/workflows/reusable-release-frontend.yaml @@ -0,0 +1,73 @@ +# Standalone reusable workflow for Node/Vite static sites. +# Does not reference reusable-release-skill.yaml; skill workflows remain unchanged. + +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" + node_version: + required: false + type: string + default: "20" + 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: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node_version }} + cache: npm + + - name: Install dependencies + run: npm ci + + - name: Build + run: ${{ inputs.build_command }} + + - name: Deploy (rsync dist to web root) + run: | + set -euo pipefail + test -d dist + DEST="${{ inputs.deploy_path }}" + DEST="${DEST%/}" + mkdir -p "$DEST" + rsync -a --delete 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