-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·277 lines (241 loc) · 6.55 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·277 lines (241 loc) · 6.55 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/usr/bin/env bash
# fa-py-libraries 发布打包(借鉴 fa_w2_ws staging 思路)
# 在临时目录 rsync 后 zip,排除 dependencies/.venv/bags 等大目录,不修改工作区。
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DIST_DIR="${ROOT_DIR}/dist"
DEFAULT_BASENAME="fa-py-libraries"
usage() {
cat <<EOF
用法: $0 [选项]
维护者打包发布 zip(临时目录 staging,不修改当前工作区)。
选项:
--package 打包 zip(含 .git;主仓 + 已检出于模块)
--package-no-git 打包 zip(不含 .git,体积更小;推荐)
-o, --output <path> 指定输出 zip 路径(默认 package-no-git 到 dist/)
--skip-submodules 跳过打包前的 ./init.sh submodules
-h, --help 显示帮助
无参数时进入交互菜单。
排除(始终):
.venv/ venv/ .idea/ .vscode/ dist/
**/dependencies/ xr_bags/ joint_records/
cert.pem key.pem *.pem
__pycache__/ *.pyc *.egg-info/
.fa-env.local.toml
包含:
init.sh run.sh release.sh scripts/ .fa-env.toml README.md .gitmodules
ros2_robot_interface/ ros2-viser/ vr_pose_publisher/(不含 dependencies/)
现场解压后:
./init.sh install
# 可选 XRoboToolkit: ./init.sh install-xrobotoolkit-pc-service && ./init.sh install-xrobotoolkit
EOF
}
need_cmd() {
local cmd="$1"
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "缺少命令: $cmd"
return 1
fi
return 0
}
update_submodules() {
if ! git -C "$ROOT_DIR" rev-parse --git-dir >/dev/null 2>&1; then
echo ">>> 当前目录不是 Git 仓库,跳过子模块更新。"
return 0
fi
if [[ ! -x "${ROOT_DIR}/init.sh" ]]; then
echo "未找到可执行的 init.sh,无法更新子模块。"
exit 1
fi
echo ">>> 更新子模块到 origin/main 最新提交..."
"$ROOT_DIR/init.sh" submodules
}
resolve_output_path() {
local custom_output="${1:-}"
local nogit_tag="${2:-0}"
local suffix=""
if [[ -n "$custom_output" ]]; then
if [[ "$custom_output" != /* ]]; then
custom_output="${ROOT_DIR}/${custom_output}"
fi
if [[ "$custom_output" != *.zip ]]; then
custom_output="${custom_output}.zip"
fi
echo "$custom_output"
return
fi
mkdir -p "$DIST_DIR"
if [[ "$nogit_tag" == "1" ]]; then
suffix="_nogit"
fi
echo "${DIST_DIR}/${DEFAULT_BASENAME}-$(date +%Y%m%d-%H%M%S)${suffix}.zip"
}
# Build rsync exclude args. $1 = 1 to also exclude .git
build_rsync_excludes() {
local exclude_git="${1:-0}"
RSYNC_EXCLUDES=(
--exclude='.venv/'
--exclude='venv/'
--exclude='.idea/'
--exclude='.vscode/'
--exclude='dist/'
--exclude='dependencies/'
--exclude='xr_bags/'
--exclude='joint_records/'
--exclude='.fa-env.local.toml'
--exclude='cert.pem'
--exclude='key.pem'
--exclude='*.pem'
--exclude='__pycache__/'
--exclude='*.pyc'
--exclude='*.egg-info/'
--exclude='*.zip'
)
if [[ "$exclude_git" == "1" ]]; then
# 目录 .git/ 与子模块 gitlink 文件 .git 都排除
RSYNC_EXCLUDES+=(--exclude='.git' --exclude='.git/')
fi
}
prepare_staging() {
local include_git="${1:-0}"
local staging exclude_git=1
need_cmd rsync || return 1
if [[ "$include_git" == "1" ]]; then
exclude_git=0
fi
build_rsync_excludes "$exclude_git"
staging="$(mktemp -d "${TMPDIR:-/tmp}/${DEFAULT_BASENAME}_release.XXXXXX")" || return 1
echo ">>> 复制到临时目录: $staging" >&2
rsync -a "${RSYNC_EXCLUDES[@]}" "${ROOT_DIR}/" "${staging}/" || {
rm -rf "$staging"
return 1
}
printf '%s' "$staging"
}
cleanup_staging() {
local staging="${1:-}"
if [[ -n "$staging" && -d "$staging" ]]; then
echo ">>> 清理临时目录: $staging"
rm -rf "$staging"
fi
}
create_release_zip() {
local staging="$1"
local archive_path="$2"
local include_git="${3:-0}"
local -a zip_excludes=(
"*.zip"
)
need_cmd zip || return 1
mkdir -p "$(dirname "$archive_path")"
if [[ -f "$archive_path" ]]; then
echo "输出文件已存在: $archive_path"
return 1
fi
if [[ "$include_git" != "1" ]]; then
zip_excludes+=(".git" ".git/*" "*/.git" "*/.git/*")
fi
echo ">>> 打包目录: $staging"
echo ">>> 输出文件: $archive_path"
if [[ "$include_git" == "1" ]]; then
echo ">>> 模式: 含 .git"
else
echo ">>> 模式: 不含 .git"
fi
(
cd "$staging" || exit 1
zip -r -q "$archive_path" . -x "${zip_excludes[@]}"
) || return 1
echo ">>> 完成: $archive_path ($(du -h "$archive_path" | cut -f1))"
}
do_package() {
local include_git="${1:-0}"
local skip_submodules="${2:-0}"
local output_path="${3:-}"
local staging=""
local archive_path
package_cleanup() {
cleanup_staging "$staging"
staging=""
}
if [[ "$skip_submodules" -eq 0 ]]; then
update_submodules
else
echo ">>> 已跳过子模块更新。"
fi
archive_path="$(resolve_output_path "$output_path" "$([[ "$include_git" == "1" ]] && echo 0 || echo 1)")"
staging="$(prepare_staging "$include_git")" || return 1
trap package_cleanup EXIT
create_release_zip "$staging" "$archive_path" "$include_git" || return 1
trap - EXIT
package_cleanup
return 0
}
interactive_menu() {
local choice
echo ""
echo "fa-py-libraries 发布打包"
echo " 1) package-no-git(推荐,体积更小)"
echo " 2) package(含 .git)"
echo " 0) 取消"
echo ""
read -r -p "请输入选项 [0-2]: " choice
case "$choice" in
1) do_package 0 0 "" ;;
2) do_package 1 0 "" ;;
0|"") echo "已取消。" ;;
*) echo "无效选项。"; exit 1 ;;
esac
}
main() {
local include_git=""
local skip_submodules=0
local output_path=""
local mode=""
while [[ $# -gt 0 ]]; do
case "$1" in
--package)
mode="package"
include_git=1
shift
;;
--package-no-git)
mode="package-no-git"
include_git=0
shift
;;
-o|--output)
[[ $# -ge 2 ]] || { echo "缺少 -o 参数值"; usage; exit 1; }
output_path="$2"
# 兼容旧用法:仅 -o 时按 no-git 打包
if [[ -z "$mode" ]]; then
mode="package-no-git"
include_git=0
fi
shift 2
;;
--skip-submodules)
skip_submodules=1
shift
;;
-h|--help|help)
usage
exit 0
;;
*)
echo "未知参数: $1"
usage
exit 1
;;
esac
done
case "$mode" in
package|package-no-git)
do_package "$include_git" "$skip_submodules" "$output_path"
;;
"")
interactive_menu
;;
esac
}
main "$@"