Skip to content

Commit 1e2716d

Browse files
authored
[action] add action for auto release zip with git tag (#47)
1 parent adc72d6 commit 1e2716d

6 files changed

Lines changed: 274 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: build-and-release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: "20"
23+
cache: "npm"
24+
# 如果你没有 frontend/package-lock.json,这行可以删掉
25+
cache-dependency-path: frontend/package-lock.json
26+
27+
- name: Setup Python
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version: "3.10"
31+
32+
- name: Install system deps
33+
run: |
34+
sudo apt-get update
35+
sudo apt-get install -y zip rsync
36+
37+
- name: Build release zip (single source of truth)
38+
run: |
39+
chmod +x scripts/build_release.sh
40+
./scripts/build_release.sh "${GITHUB_REF_NAME}"
41+
42+
- name: Create GitHub Release & upload asset
43+
uses: softprops/action-gh-release@v2
44+
with:
45+
files: |
46+
DataFlow-WebUI-*.zip
47+
generate_release_notes: true

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.zip
2+
__pycache__
3+
dist_release/

README-release-en.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# DataFlow-WebUI (Release)
2+
3+
## English · Quick Start
4+
5+
### 1. Prepare Python
6+
7+
* Python **3.10 / 3.11** is recommended
8+
* Make sure `python` is available in your shell
9+
10+
Choose one:
11+
12+
**Option A: venv**
13+
14+
```bash
15+
python -m venv .venv
16+
source .venv/bin/activate # Windows: .venv\Scripts\activate
17+
```
18+
19+
**Option B: conda**
20+
21+
```bash
22+
conda create -n dataflow python=3.10
23+
conda activate dataflow
24+
```
25+
26+
### 2. Install backend dependencies
27+
28+
```bash
29+
cd backend
30+
pip install -r requirements.txt
31+
cd ..
32+
```
33+
34+
### 3. Run
35+
36+
From the **release root directory**:
37+
38+
```bash
39+
./run.sh
40+
```
41+
42+
Windows:
43+
44+
```bat
45+
run.bat
46+
```
47+
48+
Open in browser:
49+
50+
```
51+
http://localhost:8000/ui/
52+
```

README-release-zh.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# DataFlow-WebUI (Release)
2+
3+
## 中文 · 快速开始
4+
5+
### 1. 准备 Python 环境
6+
- 推荐 Python **3.10 / 3.11**
7+
- 确保命令行可以直接使用 `python`
8+
9+
你可以任选一种方式:
10+
11+
**方式 A:venv**
12+
```bash
13+
python -m venv .venv
14+
source .venv/bin/activate # Windows: .venv\Scripts\activate
15+
```
16+
17+
**方式 B:conda**
18+
19+
```bash
20+
conda create -n dataflow python=3.10
21+
conda activate dataflow
22+
```
23+
24+
### 2. 安装后端依赖
25+
26+
```bash
27+
cd backend
28+
pip install -r requirements.txt
29+
cd ..
30+
```
31+
32+
### 3. 启动服务
33+
34+
**解压后的根目录** 直接运行:
35+
36+
```bash
37+
./run.sh
38+
```
39+
40+
Windows:
41+
42+
```bat
43+
run.bat
44+
```
45+
46+
然后在浏览器打开:
47+
48+
```
49+
http://localhost:8000/ui/
50+
```

frontend/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ coverage
2929
*.sw?
3030

3131
*.tsbuildinfo
32+
33+
34+
package-lock.json
35+
yarn.lock

scripts/build_release.sh

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# 用法:
5+
# ./scripts/build_release.sh v0.1.0
6+
# 不传则自动用当前 tag;没 tag 就用 commit 短哈希
7+
VERSION="${1:-}"
8+
9+
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
10+
FRONTEND_DIR="$ROOT_DIR/frontend"
11+
BACKEND_DIR="$ROOT_DIR/backend"
12+
13+
OUT_STAGING="$ROOT_DIR/dist_release"
14+
PKG_NAME=""
15+
ZIP_NAME=""
16+
17+
# ---- 版本号推断 ----
18+
if [[ -z "$VERSION" ]]; then
19+
if git -C "$ROOT_DIR" describe --tags --exact-match >/dev/null 2>&1; then
20+
VERSION="$(git -C "$ROOT_DIR" describe --tags --exact-match)"
21+
else
22+
VERSION="dev-$(git -C "$ROOT_DIR" rev-parse --short HEAD)"
23+
fi
24+
fi
25+
26+
PKG_NAME="DataFlow-WebUI-$VERSION"
27+
ZIP_NAME="$PKG_NAME.zip"
28+
29+
echo "[build_release] VERSION=$VERSION"
30+
echo "[build_release] PKG_NAME=$PKG_NAME"
31+
32+
# ---- 依赖检查(尽早失败)----
33+
command -v node >/dev/null 2>&1 || { echo "node not found"; exit 1; }
34+
command -v npm >/dev/null 2>&1 || { echo "npm not found"; exit 1; }
35+
command -v python >/dev/null 2>&1 || { echo "python not found"; exit 1; }
36+
command -v zip >/dev/null 2>&1 || { echo "zip not found (ubuntu: apt-get install zip)"; exit 1; }
37+
command -v rsync >/dev/null 2>&1 || { echo "rsync not found (ubuntu: apt-get install rsync)"; exit 1; }
38+
39+
# ---- 清理 staging ----
40+
rm -rf "$OUT_STAGING"
41+
mkdir -p "$OUT_STAGING/$PKG_NAME"
42+
43+
# ---- 1) 构建前端(你现在 dist 已在 frontend/ 下)----
44+
echo "[build_release] Building frontend..."
45+
pushd "$FRONTEND_DIR" >/dev/null
46+
# 你仓库里是 yarn.lock;若你更想用 yarn,就把 npm ci 换成 yarn install --frozen-lockfile
47+
# 这里先用 npm(要求有 package-lock.json);如果你没 lock,建议改用 yarn
48+
if [[ -f "package-lock.json" ]]; then
49+
npm ci
50+
npm run build
51+
else
52+
echo "No package-lock.json found, using npm install (consider using yarn with yarn.lock)."
53+
npm install
54+
npm run build
55+
fi
56+
popd >/dev/null
57+
58+
# dist 必须存在
59+
if [[ ! -d "$FRONTEND_DIR/dist" ]]; then
60+
echo "[build_release] ERROR: frontend/dist not found after build."
61+
exit 1
62+
fi
63+
64+
# ---- 2) 组装发布包:保持你的目录结构 backend/ + frontend/dist ----
65+
echo "[build_release] Assembling package..."
66+
67+
# 2.1 后端:复制 backend/(排除 tests、cache、pycache 等)
68+
rsync -a \
69+
--exclude "__pycache__" \
70+
--exclude ".venv" \
71+
--exclude ".pytest_cache" \
72+
--exclude "tests" \
73+
--exclude "cache_local" \
74+
"$BACKEND_DIR/" \
75+
"$OUT_STAGING/$PKG_NAME/backend/"
76+
77+
# 2.2 前端:只复制 dist(不带 node_modules/src 等)
78+
mkdir -p "$OUT_STAGING/$PKG_NAME/frontend"
79+
rsync -a --delete \
80+
"$FRONTEND_DIR/dist/" \
81+
"$OUT_STAGING/$PKG_NAME/frontend/dist/"
82+
83+
# 2.3 顶层文档(可选)
84+
[[ -f "$ROOT_DIR/README-release-en.md" ]] && cp "$ROOT_DIR/README-release-en.md" "$OUT_STAGING/$PKG_NAME/"
85+
[[ -f "$ROOT_DIR/README-release-zh.md" ]] && cp "$ROOT_DIR/README-release-zh.md" "$OUT_STAGING/$PKG_NAME/"
86+
[[ -f "$ROOT_DIR/LICENSE" ]] && cp "$ROOT_DIR/LICENSE" "$OUT_STAGING/$PKG_NAME/" || true
87+
88+
# ---- 3) 一键启动脚本 ----
89+
# 关键:从 release 根目录启动,保证 backend 里用 ../frontend/dist 能找到前端资源
90+
cat > "$OUT_STAGING/$PKG_NAME/run.sh" <<'EOF'
91+
#!/usr/bin/env bash
92+
set -e
93+
cd "$(dirname "$0")"
94+
95+
# 后端依赖
96+
cd backend
97+
98+
uvicorn app.main:app --reload --port 8000 --reload-dir app --host=0.0.0.0
99+
EOF
100+
chmod +x "$OUT_STAGING/$PKG_NAME/run.sh"
101+
102+
cat > "$OUT_STAGING/$PKG_NAME/run.bat" <<'EOF'
103+
@echo off
104+
setlocal
105+
cd /d "%~dp0"
106+
107+
cd backend
108+
109+
uvicorn app.main:app --reload --port 8000 --reload-dir app --host=0.0.0.0
110+
EOF
111+
112+
# ---- 4) 打 zip ----
113+
echo "[build_release] Creating zip..."
114+
pushd "$OUT_STAGING" >/dev/null
115+
zip -r "$ROOT_DIR/$ZIP_NAME" "$PKG_NAME"
116+
popd >/dev/null
117+
118+
echo "[build_release] Done: $ROOT_DIR/$ZIP_NAME"

0 commit comments

Comments
 (0)