@@ -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 }}
0 commit comments