Skip to content

Commit bbfb06d

Browse files
authored
Merge pull request #21 from zouyonghe/main
fix: stabilize tray quit/restart and automate version sync
2 parents ea9b6ed + 357eb3d commit bbfb06d

9 files changed

Lines changed: 201 additions & 92 deletions

File tree

.github/workflows/build-desktop-tauri.yml

Lines changed: 88 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,18 @@ jobs:
9898
9999
version=""
100100
if [ "${should_build}" = "true" ]; then
101-
workdir="$(mktemp -d)"
102-
repo_dir="${workdir}/AstrBot"
103-
git init "${repo_dir}"
104-
git -C "${repo_dir}" remote add origin "${source_git_url}"
105-
git -C "${repo_dir}" fetch --depth 1 origin "${source_git_ref}"
106-
git -C "${repo_dir}" checkout --detach FETCH_HEAD
107-
version="$(python3 scripts/ci/read-project-version.py "${repo_dir}/pyproject.toml")"
101+
if printf '%s' "${source_git_ref}" | grep -Eq '^v[0-9]+(\.[0-9]+){1,2}([.-][0-9A-Za-z.-]+)?$'; then
102+
version="${source_git_ref#v}"
103+
echo "Resolved version directly from source tag: ${source_git_ref}"
104+
else
105+
workdir="$(mktemp -d)"
106+
repo_dir="${workdir}/AstrBot"
107+
git init "${repo_dir}"
108+
git -C "${repo_dir}" remote add origin "${source_git_url}"
109+
git -C "${repo_dir}" fetch --depth 1 origin "${source_git_ref}"
110+
git -C "${repo_dir}" checkout --detach FETCH_HEAD
111+
version="$(python3 scripts/ci/read-project-version.py "${repo_dir}/pyproject.toml")"
112+
fi
108113
else
109114
version="${source_git_ref#v}"
110115
if [ -z "${version}" ] || [ "${version}" = "${source_git_ref}" ]; then
@@ -122,9 +127,72 @@ jobs:
122127
echo "Resolved AstrBot version: ${version}"
123128
echo "Build enabled: ${should_build}"
124129
125-
build-linux:
130+
sync_repo_version:
131+
name: Sync Repository Version
126132
needs: resolve_build_context
127-
if: ${{ needs.resolve_build_context.outputs.should_build == 'true' }}
133+
if: ${{ needs.resolve_build_context.outputs.should_build == 'true' && github.event_name == 'schedule' }}
134+
runs-on: ubuntu-latest
135+
permissions:
136+
contents: write
137+
steps:
138+
- name: Checkout branch
139+
uses: actions/checkout@v6.0.2
140+
with:
141+
fetch-depth: 0
142+
ref: ${{ github.ref_name }}
143+
144+
- name: Setup Toolchains
145+
uses: ./.github/actions/setup-toolchains
146+
with:
147+
setup-python: 'false'
148+
149+
- name: Setup pnpm
150+
uses: pnpm/action-setup@v4.2.0
151+
with:
152+
version: 10.28.2
153+
154+
- name: Sync desktop version to upstream tag
155+
env:
156+
ASTRBOT_SOURCE_GIT_URL: ${{ needs.resolve_build_context.outputs.source_git_url }}
157+
ASTRBOT_SOURCE_GIT_REF: ${{ needs.resolve_build_context.outputs.source_git_ref }}
158+
ASTRBOT_DESKTOP_VERSION: ${{ needs.resolve_build_context.outputs.astrbot_version }}
159+
run: make update
160+
161+
- name: Commit and push version files
162+
env:
163+
ASTRBOT_VERSION: ${{ needs.resolve_build_context.outputs.astrbot_version }}
164+
TARGET_REF_NAME: ${{ github.ref_name }}
165+
run: |
166+
set -euo pipefail
167+
168+
changed_files="$(git status --porcelain -- package.json src-tauri/Cargo.toml src-tauri/tauri.conf.json)"
169+
if [ -z "${changed_files}" ]; then
170+
echo "Version files are already up to date. Nothing to commit."
171+
exit 0
172+
fi
173+
174+
git config user.name "github-actions[bot]"
175+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
176+
git add package.json src-tauri/Cargo.toml src-tauri/tauri.conf.json
177+
git commit -m "chore(version): sync desktop version to v${ASTRBOT_VERSION}"
178+
179+
git fetch origin "${TARGET_REF_NAME}"
180+
if ! git pull --rebase origin "${TARGET_REF_NAME}"; then
181+
echo "::warning::Failed to rebase onto origin/${TARGET_REF_NAME}. Skipping push to avoid noisy failures."
182+
git rebase --abort || true
183+
exit 0
184+
fi
185+
186+
if ! git push origin "HEAD:${TARGET_REF_NAME}"; then
187+
echo "::warning::Push to ${TARGET_REF_NAME} was rejected (likely branch protection or race). Skipping."
188+
exit 0
189+
fi
190+
191+
build-linux:
192+
needs:
193+
- resolve_build_context
194+
- sync_repo_version
195+
if: ${{ needs.resolve_build_context.outputs.should_build == 'true' && (needs.sync_repo_version.result == 'success' || needs.sync_repo_version.result == 'skipped') }}
128196
name: linux-${{ matrix.arch }}
129197
runs-on: ${{ matrix.runner }}
130198
strategy:
@@ -157,6 +225,7 @@ jobs:
157225
env:
158226
ASTRBOT_SOURCE_GIT_URL: ${{ needs.resolve_build_context.outputs.source_git_url }}
159227
ASTRBOT_SOURCE_GIT_REF: ${{ needs.resolve_build_context.outputs.source_git_ref }}
228+
ASTRBOT_DESKTOP_VERSION: ${{ needs.resolve_build_context.outputs.astrbot_version }}
160229
GITHUB_TOKEN: ${{ github.token }}
161230
GH_TOKEN: ${{ github.token }}
162231
run: cargo tauri build --bundles deb,rpm
@@ -171,8 +240,10 @@ jobs:
171240
src-tauri/target/release/bundle/**/*.rpm
172241
173242
build-macos:
174-
needs: resolve_build_context
175-
if: ${{ needs.resolve_build_context.outputs.should_build == 'true' }}
243+
needs:
244+
- resolve_build_context
245+
- sync_repo_version
246+
if: ${{ needs.resolve_build_context.outputs.should_build == 'true' && (needs.sync_repo_version.result == 'success' || needs.sync_repo_version.result == 'skipped') }}
176247
name: macos-${{ matrix.arch }}
177248
runs-on: ${{ matrix.runner }}
178249
strategy:
@@ -199,6 +270,7 @@ jobs:
199270
env:
200271
ASTRBOT_SOURCE_GIT_URL: ${{ needs.resolve_build_context.outputs.source_git_url }}
201272
ASTRBOT_SOURCE_GIT_REF: ${{ needs.resolve_build_context.outputs.source_git_ref }}
273+
ASTRBOT_DESKTOP_VERSION: ${{ needs.resolve_build_context.outputs.astrbot_version }}
202274
ASTRBOT_DESKTOP_CRYPTOGRAPHY_FALLBACK_VERSIONS: ${{ vars.ASTRBOT_DESKTOP_CRYPTOGRAPHY_FALLBACK_VERSIONS || '' }}
203275
GITHUB_TOKEN: ${{ github.token }}
204276
GH_TOKEN: ${{ github.token }}
@@ -339,8 +411,10 @@ jobs:
339411
src-tauri/target/${{ matrix.target }}/release/bundle/**/*.app.tar.gz
340412
341413
build-windows:
342-
needs: resolve_build_context
343-
if: ${{ needs.resolve_build_context.outputs.should_build == 'true' }}
414+
needs:
415+
- resolve_build_context
416+
- sync_repo_version
417+
if: ${{ needs.resolve_build_context.outputs.should_build == 'true' && (needs.sync_repo_version.result == 'success' || needs.sync_repo_version.result == 'skipped') }}
344418
name: windows-${{ matrix.arch }}
345419
runs-on: ${{ matrix.runner }}
346420
env:
@@ -367,6 +441,7 @@ jobs:
367441
env:
368442
ASTRBOT_SOURCE_GIT_URL: ${{ needs.resolve_build_context.outputs.source_git_url }}
369443
ASTRBOT_SOURCE_GIT_REF: ${{ needs.resolve_build_context.outputs.source_git_ref }}
444+
ASTRBOT_DESKTOP_VERSION: ${{ needs.resolve_build_context.outputs.astrbot_version }}
370445
ASTRBOT_DESKTOP_CRYPTOGRAPHY_FALLBACK_VERSIONS: ${{ vars.ASTRBOT_DESKTOP_CRYPTOGRAPHY_FALLBACK_VERSIONS || '' }}
371446
GITHUB_TOKEN: ${{ github.token }}
372447
GH_TOKEN: ${{ github.token }}

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ RESOURCES_BACKEND_DIR ?= $(RESOURCES_DIR)/backend
77
RESOURCES_WEBUI_DIR ?= $(RESOURCES_DIR)/webui
88
ASTRBOT_LOCAL_DIR ?= $(VENDOR_DIR)/AstrBot-local
99
ASTRBOT_LOCAL_DESKTOP_DIR ?= $(ASTRBOT_LOCAL_DIR)/desktop
10+
ASTRBOT_SOURCE_GIT_URL ?= https://github.com/AstrBotDevs/AstrBot.git
11+
ASTRBOT_SOURCE_GIT_REF ?= master
1012
RUST_MANIFEST ?= src-tauri/Cargo.toml
1113
NODE_MODULES_DIR ?= node_modules
1214
PNPM_STORE_DIR ?= .pnpm-store
1315
TAURI_TARGET_DIR ?= src-tauri/target
1416

15-
.PHONY: help deps sync-version prepare-webui prepare-backend prepare-resources dev build \
17+
.PHONY: help deps sync-version update prepare-webui prepare-backend prepare-resources dev build \
1618
prepare rebuild lint test doctor prune size clean clean-rust clean-resources \
1719
clean-vendor-local clean-vendor clean-node clean-all
1820

@@ -21,6 +23,7 @@ help:
2123
@echo ""
2224
@echo " make deps Install JS dependencies"
2325
@echo " make sync-version Sync desktop version from AstrBot source"
26+
@echo " make update Sync desktop version from upstream AstrBot"
2427
@echo " make prepare Alias of prepare-resources"
2528
@echo " make prepare-webui Build and sync WebUI resources"
2629
@echo " make prepare-backend Build and sync backend runtime resources"
@@ -48,6 +51,13 @@ deps:
4851
sync-version:
4952
pnpm run sync:version
5053

54+
update:
55+
ASTRBOT_SOURCE_DIR= \
56+
ASTRBOT_SOURCE_GIT_URL=$(ASTRBOT_SOURCE_GIT_URL) \
57+
ASTRBOT_SOURCE_GIT_REF=$(ASTRBOT_SOURCE_GIT_REF) \
58+
ASTRBOT_DESKTOP_VERSION=$(ASTRBOT_DESKTOP_VERSION) \
59+
pnpm run sync:version
60+
5161
prepare-webui:
5262
pnpm run prepare:webui
5363

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,34 @@ make clean
125125
make prune
126126
```
127127

128+
## 版本维护(重要)
129+
130+
桌面端版本会同步到以下三个文件:
131+
132+
- `package.json`
133+
- `src-tauri/Cargo.toml`
134+
- `src-tauri/tauri.conf.json`
135+
136+
### `make sync-version``make update` 的区别
137+
138+
- `make sync-version`:从当前解析到的 AstrBot 源同步版本,受本地环境变量影响(例如 `ASTRBOT_SOURCE_DIR`)。
139+
- `make update`:用于“对齐上游”,会忽略 `ASTRBOT_SOURCE_DIR`,并使用 `ASTRBOT_SOURCE_GIT_URL` + `ASTRBOT_SOURCE_GIT_REF` 同步版本。
140+
141+
推荐日常使用 `make update`,避免本地切换分支导致版本漂移。
142+
143+
示例:
144+
145+
```bash
146+
# 同步到上游 master
147+
make update
148+
149+
# 同步到指定上游 tag
150+
make update ASTRBOT_SOURCE_GIT_REF=v4.17.5
151+
152+
# 强制写入指定版本(通常用于 CI)
153+
make update ASTRBOT_DESKTOP_VERSION=4.17.5
154+
```
155+
128156
## 上游仓库策略
129157

130158
默认上游仓库:
@@ -151,6 +179,13 @@ export ASTRBOT_SOURCE_GIT_URL=https://github.com/zouyonghe/AstrBot.git
151179
export ASTRBOT_SOURCE_GIT_REF=cpython-runtime-refactor
152180
```
153181

182+
## CI 版本同步策略
183+
184+
`build-desktop-tauri` 工作流在定时任务(`schedule`)检测到上游新 tag 且需要构建时,会先自动同步并提交上述三个版本文件,然后继续构建产物。
185+
186+
- 定时构建:会自动回写版本到仓库(commit + push)。
187+
- 手动触发(`workflow_dispatch`):默认只构建,不自动回写版本文件。
188+
154189
## 构建流程说明
155190

156191
`src-tauri/tauri.conf.json` 已配置 `beforeBuildCommand=pnpm run prepare:resources`,构建时会自动执行以下流程:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "astrbot-desktop-tauri",
3-
"version": "4.17.5",
3+
"version": "4.17.6",
44
"description": "AstrBot desktop shell powered by Tauri",
55
"private": true,
66
"packageManager": "pnpm@10.28.2",

scripts/prepare-resources.mjs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const DEFAULT_ASTRBOT_SOURCE_GIT_URL = 'https://github.com/AstrBotDevs/AstrBot.g
88
const sourceRepoUrlRaw =
99
process.env.ASTRBOT_SOURCE_GIT_URL?.trim() || DEFAULT_ASTRBOT_SOURCE_GIT_URL;
1010
const sourceRepoRefRaw = process.env.ASTRBOT_SOURCE_GIT_REF?.trim() || '';
11+
const desktopVersionOverride = process.env.ASTRBOT_DESKTOP_VERSION?.trim() || '';
1112
const PYTHON_BUILD_STANDALONE_RELEASE =
1213
process.env.ASTRBOT_PBS_RELEASE?.trim() || '20260211';
1314
const PYTHON_BUILD_STANDALONE_VERSION =
@@ -427,12 +428,35 @@ const ensureStartupShellAssets = () => {
427428

428429
const main = async () => {
429430
const sourceDir = resolveSourceDir();
431+
const needsSourceRepo = mode !== 'version' || !desktopVersionOverride;
430432
await mkdir(path.join(projectRoot, 'resources'), { recursive: true });
431-
ensureSourceRepo(sourceDir);
433+
if (needsSourceRepo) {
434+
ensureSourceRepo(sourceDir);
435+
} else {
436+
console.log(
437+
'[prepare-resources] Skip source repo sync in version-only mode because ASTRBOT_DESKTOP_VERSION is set.',
438+
);
439+
}
432440
ensureStartupShellAssets();
433-
const astrbotVersion = await readAstrbotVersionFromPyproject(sourceDir);
441+
const astrbotVersion = desktopVersionOverride || (await readAstrbotVersionFromPyproject(sourceDir));
442+
443+
if (desktopVersionOverride && needsSourceRepo) {
444+
const sourceVersion = await readAstrbotVersionFromPyproject(sourceDir);
445+
if (sourceVersion !== desktopVersionOverride) {
446+
console.warn(
447+
`[prepare-resources] Version override drift detected: ASTRBOT_DESKTOP_VERSION=${desktopVersionOverride}, source pyproject version=${sourceVersion} (${sourceDir})`,
448+
);
449+
}
450+
}
451+
434452
await syncDesktopVersionFiles(astrbotVersion);
435-
console.log(`[prepare-resources] Synced desktop version to AstrBot ${astrbotVersion}`);
453+
if (desktopVersionOverride) {
454+
console.log(
455+
`[prepare-resources] Synced desktop version to override ${astrbotVersion} (ASTRBOT_DESKTOP_VERSION)`,
456+
);
457+
} else {
458+
console.log(`[prepare-resources] Synced desktop version to AstrBot ${astrbotVersion}`);
459+
}
436460

437461
if (mode === 'version') {
438462
return;

src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "astrbot-desktop-tauri"
3-
version = "4.17.5"
3+
version = "4.17.6"
44
description = "AstrBot desktop shell powered by Tauri"
55
authors = ["AstrBot"]
66
license = "AGPL-3.0"

0 commit comments

Comments
 (0)