Files
userbase/.gitea/workflows/deploy-front.yml
T
2026-08-04 22:29:54 +08:00

60 lines
2.7 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: deploy-userbase-front
on:
push:
branches: [main]
paths:
- 'front/**'
- '.gitea/workflows/deploy-front.yml'
jobs:
build-and-deploy:
runs-on: ubuntu-latest
# node:20 自带 npm 与 git;通过已配置的 registry-mirrors 拉取
# /data/www/userbase 与 docker.sock 由 act_runner 全局 options 统一挂载(见 act-runner config)
container:
image: node:20
# /data/www/userbase 由 job container.volumes 声明挂载。
# 关键点:act_runner 的 container.options 中多个 --volume 只有第一个生效,
# 因此静态目录不能放在 runner options 里,必须在 workflow 的 container.volumes 明确声明,
# 且 runner config 的 valid_volumes 白名单必须含该「完整 bind 字符串」才会放行。
volumes:
- /data/www/userbase:/data/www/userbase
steps:
# 内网 Gitea 无法访问 github.com 拉取 actions/checkout,改为直接 clone 本仓库
- name: Checkout (manual, internal Gitea)
run: |
git clone --depth 1 --branch main http://192.168.10.160:3000/${GITHUB_REPOSITORY}.git /tmp/src
cp -a /tmp/src/. .
rm -rf /tmp/src
- name: Use npm mirror (npmmirror)
working-directory: front
run: npm config set registry https://registry.npmmirror.com
# node-sass(6.x) 无 Node20 预编译二进制,源码编译必失败;项目实际用 dart-sass(sass)。
# 本地 lockfile 暂不便修改,这里在 runner 内把它从 lockfile 剔除后再 npm ci(不改仓库文件)。
- name: Strip node-sass from lockfile (CI-only)
run: |
node -e "const fs=require('fs');const p='front/package-lock.json';const d=JSON.parse(fs.readFileSync(p,'utf8'));const pk=d.packages||{};for(const k of Object.keys(pk)){if(k==='node_modules/node-sass'||k.startsWith('node_modules/node-sass/'))delete pk[k];}if(d.dependencies&&d.dependencies.node-sass)delete d.dependencies.node-sass;fs.writeFileSync(p,JSON.stringify(d,null,2));"
echo "node-sass stripped from lockfile"
- name: Install dependencies
working-directory: front
run: npm ci --no-audit --no-fund
- name: Build (prod -> dist/prod)
working-directory: front
run: npm run build:prod
- name: Deploy to static dir (/data/www/userbase/front)
# /data/www/userbase 已由 job container.volumes 挂入本容器
run: |
rm -rf /data/www/userbase/front
mkdir -p /data/www/userbase/front
cp -r front/dist/prod/. /data/www/userbase/front/
echo "deployed front -> /data/www/userbase/front"
- name: Done
run: ls -la /data/www/userbase/front | head