-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
97 lines (83 loc) · 2.54 KB
/
build.sh
File metadata and controls
97 lines (83 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
# 构建项目为二进制文件
# 使用方法: ./build.sh [版本号]
# 例如: ./build.sh v1.0.0
VERSION=${1:-"dev"}
echo "构建版本: $VERSION"
# 获取当前 Git commit ID
if git rev-parse --git-dir > /dev/null 2>&1; then
COMMIT_ID=$(git rev-parse --short HEAD)
echo "Commit ID: $COMMIT_ID"
else
COMMIT_ID="unknown"
echo "警告: 不在 Git 仓库中,commit ID 将设置为 'unknown'"
fi
# 检查是否安装了pyinstaller
if ! command -v pyinstaller &> /dev/null
then
echo "PyInstaller 未安装,请先运行: pip install pyinstaller"
exit 1
fi
# 删除之前的构建
rm -rf dist build __pycache__
# 生成版本信息文件
echo "生成版本信息文件..."
cat > version.py << EOF
#!/usr/bin/env python
"""
Version information for Tricode CLI
This file is automatically generated during build process
"""
import subprocess
import os
# Build-time version information
__version__ = "${VERSION}"
__commit_id__ = "${COMMIT_ID}"
def get_version_string():
"""Get formatted version string"""
return f"Tricode-cli {__version__}"
def get_full_version_string():
"""Get full version string with commit ID"""
return f"Tricode-cli {__version__} (git-{__commit_id__})"
def get_version_info():
"""Get version information as a dictionary"""
return {
"version": __version__,
"commit_id": __commit_id__,
"full": get_full_version_string()
}
def get_runtime_commit_id():
"""
Try to get commit ID at runtime (for development mode)
Falls back to build-time commit ID if not in a git repo
"""
if __commit_id__ != "unknown":
return __commit_id__
try:
commit = subprocess.check_output(
['git', 'rev-parse', '--short', 'HEAD'],
stderr=subprocess.DEVNULL,
text=True,
cwd=os.path.dirname(os.path.abspath(__file__))
).strip()
return commit
except (subprocess.CalledProcessError, FileNotFoundError):
return "unknown"
def get_runtime_version():
"""Get version with runtime commit ID detection"""
commit = get_runtime_commit_id()
return f"Tricode-cli {__version__} (git-{commit})"
EOF
echo "版本信息文件已生成: version.py"
# Build binary directly as tricode
if [ -f tricode.spec ]; then
pyinstaller tricode.spec
else
pyinstaller --onefile --name "tricode" \
--hidden-import=tiktoken_ext \
--hidden-import=tiktoken_ext.openai_public \
--collect-data tiktoken_ext \
tricode.py
fi
echo "Build complete!"
echo "Binary: dist/tricode"