Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 77 additions & 10 deletions .github/workflows/build-desktop-tauri.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,18 @@ jobs:

version=""
if [ "${should_build}" = "true" ]; then
workdir="$(mktemp -d)"
repo_dir="${workdir}/AstrBot"
git init "${repo_dir}"
git -C "${repo_dir}" remote add origin "${source_git_url}"
git -C "${repo_dir}" fetch --depth 1 origin "${source_git_ref}"
git -C "${repo_dir}" checkout --detach FETCH_HEAD
version="$(python3 scripts/ci/read-project-version.py "${repo_dir}/pyproject.toml")"
if printf '%s' "${source_git_ref}" | grep -Eq '^v[0-9]+(\.[0-9]+){1,2}([.-][0-9A-Za-z.-]+)?$'; then
version="${source_git_ref#v}"
echo "Resolved version directly from source tag: ${source_git_ref}"
else
workdir="$(mktemp -d)"
repo_dir="${workdir}/AstrBot"
git init "${repo_dir}"
git -C "${repo_dir}" remote add origin "${source_git_url}"
git -C "${repo_dir}" fetch --depth 1 origin "${source_git_ref}"
git -C "${repo_dir}" checkout --detach FETCH_HEAD
version="$(python3 scripts/ci/read-project-version.py "${repo_dir}/pyproject.toml")"
fi
else
version="${source_git_ref#v}"
if [ -z "${version}" ] || [ "${version}" = "${source_git_ref}" ]; then
Expand All @@ -122,8 +127,63 @@ jobs:
echo "Resolved AstrBot version: ${version}"
echo "Build enabled: ${should_build}"

build-linux:
sync_repo_version:
name: Sync Repository Version
needs: resolve_build_context
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout branch
if: ${{ needs.resolve_build_context.outputs.should_build == 'true' && github.event_name == 'schedule' }}
uses: actions/checkout@v6.0.2
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
with:
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
ref: ${{ github.ref_name }}

- name: Setup Toolchains
if: ${{ needs.resolve_build_context.outputs.should_build == 'true' && github.event_name == 'schedule' }}
uses: ./.github/actions/setup-toolchains
with:
setup-python: 'false'

- name: Setup pnpm
if: ${{ needs.resolve_build_context.outputs.should_build == 'true' && github.event_name == 'schedule' }}
uses: pnpm/action-setup@v4.2.0
with:
version: 10.28.2

- name: Sync desktop version to upstream tag
if: ${{ needs.resolve_build_context.outputs.should_build == 'true' && github.event_name == 'schedule' }}
env:
ASTRBOT_SOURCE_GIT_URL: ${{ needs.resolve_build_context.outputs.source_git_url }}
ASTRBOT_SOURCE_GIT_REF: ${{ needs.resolve_build_context.outputs.source_git_ref }}
ASTRBOT_DESKTOP_VERSION: ${{ needs.resolve_build_context.outputs.astrbot_version }}
run: make update

- name: Commit and push version files
if: ${{ needs.resolve_build_context.outputs.should_build == 'true' && github.event_name == 'schedule' }}
env:
ASTRBOT_VERSION: ${{ needs.resolve_build_context.outputs.astrbot_version }}
TARGET_REF_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail

changed_files="$(git status --porcelain -- package.json src-tauri/Cargo.toml src-tauri/tauri.conf.json)"
if [ -z "${changed_files}" ]; then
echo "Version files are already up to date. Nothing to commit."
exit 0
fi

git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add package.json src-tauri/Cargo.toml src-tauri/tauri.conf.json
git commit -m "chore(version): sync desktop version to v${ASTRBOT_VERSION}"
git push origin "HEAD:${TARGET_REF_NAME}"

build-linux:
needs:
- resolve_build_context
- sync_repo_version
if: ${{ needs.resolve_build_context.outputs.should_build == 'true' }}
name: linux-${{ matrix.arch }}
runs-on: ${{ matrix.runner }}
Expand Down Expand Up @@ -157,6 +217,7 @@ jobs:
env:
ASTRBOT_SOURCE_GIT_URL: ${{ needs.resolve_build_context.outputs.source_git_url }}
ASTRBOT_SOURCE_GIT_REF: ${{ needs.resolve_build_context.outputs.source_git_ref }}
ASTRBOT_DESKTOP_VERSION: ${{ needs.resolve_build_context.outputs.astrbot_version }}
GITHUB_TOKEN: ${{ github.token }}
GH_TOKEN: ${{ github.token }}
run: cargo tauri build --bundles deb,rpm
Expand All @@ -171,7 +232,9 @@ jobs:
src-tauri/target/release/bundle/**/*.rpm

build-macos:
needs: resolve_build_context
needs:
- resolve_build_context
- sync_repo_version
if: ${{ needs.resolve_build_context.outputs.should_build == 'true' }}
name: macos-${{ matrix.arch }}
runs-on: ${{ matrix.runner }}
Expand Down Expand Up @@ -199,6 +262,7 @@ jobs:
env:
ASTRBOT_SOURCE_GIT_URL: ${{ needs.resolve_build_context.outputs.source_git_url }}
ASTRBOT_SOURCE_GIT_REF: ${{ needs.resolve_build_context.outputs.source_git_ref }}
ASTRBOT_DESKTOP_VERSION: ${{ needs.resolve_build_context.outputs.astrbot_version }}
ASTRBOT_DESKTOP_CRYPTOGRAPHY_FALLBACK_VERSIONS: ${{ vars.ASTRBOT_DESKTOP_CRYPTOGRAPHY_FALLBACK_VERSIONS || '' }}
GITHUB_TOKEN: ${{ github.token }}
GH_TOKEN: ${{ github.token }}
Expand Down Expand Up @@ -339,7 +403,9 @@ jobs:
src-tauri/target/${{ matrix.target }}/release/bundle/**/*.app.tar.gz

build-windows:
needs: resolve_build_context
needs:
- resolve_build_context
- sync_repo_version
if: ${{ needs.resolve_build_context.outputs.should_build == 'true' }}
name: windows-${{ matrix.arch }}
runs-on: ${{ matrix.runner }}
Expand Down Expand Up @@ -367,6 +433,7 @@ jobs:
env:
ASTRBOT_SOURCE_GIT_URL: ${{ needs.resolve_build_context.outputs.source_git_url }}
ASTRBOT_SOURCE_GIT_REF: ${{ needs.resolve_build_context.outputs.source_git_ref }}
ASTRBOT_DESKTOP_VERSION: ${{ needs.resolve_build_context.outputs.astrbot_version }}
ASTRBOT_DESKTOP_CRYPTOGRAPHY_FALLBACK_VERSIONS: ${{ vars.ASTRBOT_DESKTOP_CRYPTOGRAPHY_FALLBACK_VERSIONS || '' }}
GITHUB_TOKEN: ${{ github.token }}
GH_TOKEN: ${{ github.token }}
Expand Down
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ RESOURCES_BACKEND_DIR ?= $(RESOURCES_DIR)/backend
RESOURCES_WEBUI_DIR ?= $(RESOURCES_DIR)/webui
ASTRBOT_LOCAL_DIR ?= $(VENDOR_DIR)/AstrBot-local
ASTRBOT_LOCAL_DESKTOP_DIR ?= $(ASTRBOT_LOCAL_DIR)/desktop
ASTRBOT_SOURCE_GIT_URL ?= https://github.com/AstrBotDevs/AstrBot.git
ASTRBOT_SOURCE_GIT_REF ?= master
RUST_MANIFEST ?= src-tauri/Cargo.toml
NODE_MODULES_DIR ?= node_modules
PNPM_STORE_DIR ?= .pnpm-store
TAURI_TARGET_DIR ?= src-tauri/target

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

Expand All @@ -21,6 +23,7 @@ help:
@echo ""
@echo " make deps Install JS dependencies"
@echo " make sync-version Sync desktop version from AstrBot source"
@echo " make update Sync desktop version from upstream AstrBot"
@echo " make prepare Alias of prepare-resources"
@echo " make prepare-webui Build and sync WebUI resources"
@echo " make prepare-backend Build and sync backend runtime resources"
Expand Down Expand Up @@ -48,6 +51,13 @@ deps:
sync-version:
pnpm run sync:version

update:
ASTRBOT_SOURCE_DIR= \
ASTRBOT_SOURCE_GIT_URL=$(ASTRBOT_SOURCE_GIT_URL) \
ASTRBOT_SOURCE_GIT_REF=$(ASTRBOT_SOURCE_GIT_REF) \
ASTRBOT_DESKTOP_VERSION=$(ASTRBOT_DESKTOP_VERSION) \
pnpm run sync:version

prepare-webui:
pnpm run prepare:webui

Expand Down
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,34 @@ make clean
make prune
```

## 版本维护(重要)

桌面端版本会同步到以下三个文件:

- `package.json`
- `src-tauri/Cargo.toml`
- `src-tauri/tauri.conf.json`

### `make sync-version` 与 `make update` 的区别

- `make sync-version`:从当前解析到的 AstrBot 源同步版本,受本地环境变量影响(例如 `ASTRBOT_SOURCE_DIR`)。
- `make update`:用于“对齐上游”,会忽略 `ASTRBOT_SOURCE_DIR`,并使用 `ASTRBOT_SOURCE_GIT_URL` + `ASTRBOT_SOURCE_GIT_REF` 同步版本。

推荐日常使用 `make update`,避免本地切分支导致版本漂移。
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated

示例:

```bash
# 同步到上游 master
make update

# 同步到指定上游 tag
make update ASTRBOT_SOURCE_GIT_REF=v4.17.5

# 强制写入指定版本(通常用于 CI)
make update ASTRBOT_DESKTOP_VERSION=4.17.5
```

## 上游仓库策略

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

## CI 版本同步策略

`build-desktop-tauri` 工作流在定时任务(`schedule`)检测到上游新 tag 且需要构建时,会先自动同步并提交上述三个版本文件,然后继续构建产物。

- 定时构建:会自动回写版本到仓库(commit + push)。
- 手动触发(`workflow_dispatch`):默认只构建,不自动回写版本文件。

## 构建流程说明

`src-tauri/tauri.conf.json` 已配置 `beforeBuildCommand=pnpm run prepare:resources`,构建时会自动执行以下流程:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "astrbot-desktop-tauri",
"version": "4.17.5",
"version": "4.17.6",
"description": "AstrBot desktop shell powered by Tauri",
"private": true,
"packageManager": "pnpm@10.28.2",
Expand Down
18 changes: 16 additions & 2 deletions scripts/prepare-resources.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const DEFAULT_ASTRBOT_SOURCE_GIT_URL = 'https://github.com/AstrBotDevs/AstrBot.g
const sourceRepoUrlRaw =
process.env.ASTRBOT_SOURCE_GIT_URL?.trim() || DEFAULT_ASTRBOT_SOURCE_GIT_URL;
const sourceRepoRefRaw = process.env.ASTRBOT_SOURCE_GIT_REF?.trim() || '';
const desktopVersionOverride = process.env.ASTRBOT_DESKTOP_VERSION?.trim() || '';
const PYTHON_BUILD_STANDALONE_RELEASE =
process.env.ASTRBOT_PBS_RELEASE?.trim() || '20260211';
const PYTHON_BUILD_STANDALONE_VERSION =
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Expand Down Expand Up @@ -270,6 +271,13 @@ const syncDesktopVersionFiles = async (version) => {
}
};

const resolveDesktopVersion = async (sourceDir) => {
if (desktopVersionOverride) {
return desktopVersionOverride;
}
return readAstrbotVersionFromPyproject(sourceDir);
};

const resolvePbsTarget = () => {
const platformMap = {
linux: 'linux',
Expand Down Expand Up @@ -430,9 +438,15 @@ const main = async () => {
await mkdir(path.join(projectRoot, 'resources'), { recursive: true });
ensureSourceRepo(sourceDir);
ensureStartupShellAssets();
const astrbotVersion = await readAstrbotVersionFromPyproject(sourceDir);
const astrbotVersion = await resolveDesktopVersion(sourceDir);
await syncDesktopVersionFiles(astrbotVersion);
console.log(`[prepare-resources] Synced desktop version to AstrBot ${astrbotVersion}`);
if (desktopVersionOverride) {
console.log(
`[prepare-resources] Synced desktop version to override ${astrbotVersion} (ASTRBOT_DESKTOP_VERSION)`,
);
} else {
console.log(`[prepare-resources] Synced desktop version to AstrBot ${astrbotVersion}`);
}

if (mode === 'version') {
return;
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "astrbot-desktop-tauri"
version = "4.17.5"
version = "4.17.6"
description = "AstrBot desktop shell powered by Tauri"
authors = ["AstrBot"]
license = "AGPL-3.0"
Expand Down
Loading