Skip to content

Commit 77d8436

Browse files
ci(workflow): 更新构建流程以使用uv工具链
- 使用uv替代传统的pip和setup-python进行Python环境管理 - 优化Linux构建流程,改进DEB包结构和依赖处理 - 更新Ubuntu运行环境版本至22.04 - 简化构建脚本并提高可靠性
1 parent 0816416 commit 77d8436

File tree

1 file changed

+68
-57
lines changed

1 file changed

+68
-57
lines changed

.github/workflows/build.yml

Lines changed: 68 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,19 @@ jobs:
3333
steps:
3434
- uses: actions/checkout@v4
3535

36+
- name: Install uv
37+
uses: astral-sh/setup-uv@v5
38+
3639
- name: Set up Python
37-
uses: actions/setup-python@v5
38-
with:
39-
python-version: '3.11'
40+
run: uv python install 3.13
4041

4142
- name: Install dependencies
4243
run: |
43-
pip install pyinstaller
44-
pip install pystray Pillow requests loguru
44+
uv sync
45+
uv pip install pyinstaller
4546
4647
- name: Build
47-
run: python build.py
48+
run: uv run python build.py
4849

4950
- name: Upload artifact
5051
uses: actions/upload-artifact@v4
@@ -62,96 +63,106 @@ jobs:
6263
if: startsWith(github.ref, 'refs/tags/v')
6364
run: echo "APP_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
6465

66+
- name: Install uv
67+
uses: astral-sh/setup-uv@v5
68+
6569
- name: Install system dependencies
6670
run: |
6771
sudo apt-get update
6872
sudo apt-get install -y \
73+
python3-venv \
74+
python3-dev \
75+
pkg-config \
6976
libcairo2-dev \
70-
libgirepository-2.0-dev \
71-
gir1.2-glib-2.0 \
72-
gir1.2-ayatanaappindicator3-0.1 \
77+
libgirepository1.0-dev \
78+
gir1.2-gtk-3.0 \
7379
gir1.2-webkit2-4.1 \
74-
pkg-config \
75-
python3-dev \
76-
dpkg-dev \
77-
fakeroot
80+
gir1.2-ayatanaappindicator3-0.1 \
81+
dpkg-dev
7882
7983
- name: Build DEB package
8084
run: |
81-
PKG_DIR="build/deb/${APP_NAME}"
85+
set -e
86+
PKG="build/deb/${APP_NAME}"
8287
8388
# 目录结构
84-
mkdir -p "${PKG_DIR}/usr/share/${APP_NAME}"
85-
mkdir -p "${PKG_DIR}/usr/share/applications"
86-
mkdir -p "${PKG_DIR}/usr/bin"
87-
mkdir -p "${PKG_DIR}/DEBIAN"
89+
mkdir -p "${PKG}/opt/${APP_NAME}"
90+
mkdir -p "${PKG}/usr/bin"
91+
mkdir -p "${PKG}/usr/share/applications"
92+
mkdir -p "${PKG}/DEBIAN"
8893
8994
# 复制项目文件
90-
cp main.py "${PKG_DIR}/usr/share/${APP_NAME}/"
91-
cp -r icons htmls saying desktop_widgets "${PKG_DIR}/usr/share/${APP_NAME}/" 2>/dev/null || true
92-
cp font.ttf icon.ico introduce banner.png LICENSE README.md "${PKG_DIR}/usr/share/${APP_NAME}/" 2>/dev/null || true
93-
cp pyproject.toml "${PKG_DIR}/usr/share/${APP_NAME}/"
95+
cp *.py "${PKG}/opt/${APP_NAME}/"
96+
for item in icons htmls saying desktop_widgets font.ttf icon.ico introduce banner.png LICENSE README.md pyproject.toml; do
97+
[ -e "$item" ] && cp -r "$item" "${PKG}/opt/${APP_NAME}/"
98+
done
99+
100+
# 用 uv 创建 venv 并安装依赖
101+
cd "${PKG}/opt/${APP_NAME}"
102+
uv venv venv
103+
uv pip install --python venv/bin/python \
104+
pystray Pillow pycairo PyGObject requests loguru
105+
cd -
106+
107+
# 修复 venv 路径
108+
sed -i "s|${PWD}/${PKG}||g" "${PKG}/opt/${APP_NAME}/venv/bin/"* 2>/dev/null || true
94109
95110
# 启动脚本
96-
cat > "${PKG_DIR}/usr/bin/${APP_NAME}" << 'LAUNCHER'
111+
cat > "${PKG}/usr/bin/${APP_NAME}" <<'EOF'
97112
#!/bin/bash
98-
cd /usr/share/assignsticker
99-
python3 main.py "$@"
100-
LAUNCHER
101-
chmod +x "${PKG_DIR}/usr/bin/${APP_NAME}"
113+
export GI_TYPELIB_PATH=/usr/lib/x86_64-linux-gnu/girepository-1.0
114+
cd /opt/assignsticker
115+
exec /opt/assignsticker/venv/bin/python main.py "$@"
116+
EOF
117+
chmod +x "${PKG}/usr/bin/${APP_NAME}"
102118
103-
# Desktop Entry
104-
cat > "${PKG_DIR}/usr/share/applications/${APP_NAME}.desktop" << EOF
119+
# Desktop Entry
120+
cat > "${PKG}/usr/share/applications/${APP_NAME}.desktop" <<EOF
105121
[Desktop Entry]
106122
Name=AssignSticker
107123
Comment=Homework Kanban Application
108124
Exec=${APP_NAME}
109-
Icon=/usr/share/${APP_NAME}/icon.ico
125+
Icon=/opt/${APP_NAME}/icon.ico
110126
Type=Application
111127
Categories=Education;Office;
112128
Terminal=false
129+
StartupWMClass=assignsticker
113130
EOF
114131
115-
# Control
116-
cat > "${PKG_DIR}/DEBIAN/control" << EOF
132+
# 计算大小
133+
SIZE=$(du -sk "${PKG}" | cut -f1)
134+
135+
# Control
136+
cat > "${PKG}/DEBIAN/control" <<EOF
117137
Package: ${APP_NAME}
118138
Version: ${APP_VERSION}
119139
Section: education
120140
Priority: optional
121141
Architecture: amd64
122-
Depends: python3,
123-
python3-gi,
124-
python3-gi-cairo,
125-
python3-pil,
126-
python3-requests,
127-
gir1.2-gtk-3.0,
128-
gir1.2-webkit2-4.1,
129-
gir1.2-ayatanaappindicator3-0.1,
130-
gir1.2-glib-2.0,
131-
libcairo2,
132-
libgtk-3-0,
133-
libwebkit2gtk-4.1-0
142+
Installed-Size: ${SIZE}
143+
Depends: python3 (>= 3.10),
144+
gir1.2-gtk-3.0,
145+
gir1.2-webkit2-4.1,
146+
gir1.2-ayatanaappindicator3-0.1,
147+
libcairo2,
148+
libgtk-3-0,
149+
libwebkit2gtk-4.1-0
134150
Maintainer: SECTL <sectl@example.com>
151+
Homepage: https://github.com/sectl/AssignSticker
135152
Description: Homework Showboard Application
136-
AssignSticker is a homework management and display application.
137-
EOF
138-
139-
# postinst: 安装 pip 依赖
140-
cat > "${PKG_DIR}/DEBIAN/postinst" << 'EOF'
141-
#!/bin/bash
142-
pip3 install pystray loguru pycairo PyGObject 2>/dev/null || true
153+
AssignSticker is a homework management and display
154+
application for classroom use.
143155
EOF
144-
chmod 755 "${PKG_DIR}/DEBIAN/postinst"
145156
146-
# 打包
147-
dpkg-deb --build "${PKG_DIR}"
148-
mv "build/deb/${APP_NAME}.deb" "AssignSticker-${APP_VERSION}-linux-amd64.deb"
157+
# 打包
158+
dpkg-deb --root-owner-group --build "${PKG}"
159+
mv "build/deb/${APP_NAME}.deb" "AssignSticker-${APP_VERSION}-amd64.deb"
149160
150161
- name: Upload artifact
151162
uses: actions/upload-artifact@v4
152163
with:
153164
name: AssignSticker-linux-amd64
154-
path: AssignSticker-*-linux-amd64.deb
165+
path: "*.deb"
155166

156167
release:
157168
needs: [build-windows, build-linux]
@@ -161,7 +172,7 @@ jobs:
161172
(startsWith(github.ref, 'refs/tags/v') ||
162173
(github.event_name == 'workflow_dispatch' && inputs.create_release))
163174
steps:
164-
- name: Download all artifacts
175+
- name: Download artifacts
165176
uses: actions/download-artifact@v4
166177
with:
167178
path: artifacts

0 commit comments

Comments
 (0)