From 94f19cc9aa11b05eb8bf80fe717ec4b69536a57c Mon Sep 17 00:00:00 2001 From: PointerL <124577547+PointerL@users.noreply.github.com> Date: Fri, 23 Oct 2026 00:31:51 +0800 Subject: [PATCH 1/3] test(release): reject invalid version without changes Exercise release.bash with an invalid version and require the worktree, HEAD, and tags to remain unchanged. Signed-off-by: PointerL --- misc/CMakeLists.txt | 5 +++ misc/tests/release_version_test.sh | 51 ++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 misc/tests/release_version_test.sh diff --git a/misc/CMakeLists.txt b/misc/CMakeLists.txt index 0fe620310..2d01872a3 100644 --- a/misc/CMakeLists.txt +++ b/misc/CMakeLists.txt @@ -190,6 +190,11 @@ if(ENABLE_TESTING) ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DTEST_DIR=${CMAKE_CURRENT_BINARY_DIR}/tests/environment -P ${CMAKE_CURRENT_SOURCE_DIR}/tests/environment_test.cmake) + + add_test( + NAME release_version_validation + COMMAND /bin/bash ${CMAKE_CURRENT_SOURCE_DIR}/tests/release_version_test.sh + ${PROJECT_SOURCE_DIR}) endif() # polkit actions diff --git a/misc/tests/release_version_test.sh b/misc/tests/release_version_test.sh new file mode 100644 index 000000000..4bac1dec5 --- /dev/null +++ b/misc/tests/release_version_test.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. +# +# SPDX-License-Identifier: LGPL-3.0-or-later + +set -eu + +source_dir=$1 +test_dir=$(mktemp -d) +trap 'rm -rf "${test_dir}"' EXIT + +cp "${source_dir}/release.bash" "${test_dir}/release.bash" +cat >"${test_dir}/CMakeLists.txt" <<'EOF' +project( + linglong + VERSION 1.15.0) +EOF + +cd "${test_dir}" +git init --quiet +git config user.name "Linyaps Test" +git config user.email "test@linyaps.invalid" +git add CMakeLists.txt release.bash +git commit --quiet -m "initial" + +head_before=$(git rev-parse HEAD) +tags_before=$(git tag) + +if printf '1.2.invalid\n' | bash ./release.bash; then + printf 'release.bash accepted an invalid version\n' >&2 + exit 1 +fi + +if [ -n "$(git status --porcelain)" ]; then + printf 'release.bash changed the worktree for an invalid version:\n' >&2 + git status --short >&2 + exit 1 +fi + +if [ "$(git rev-parse HEAD)" != "${head_before}" ]; then + printf 'release.bash created a commit for an invalid version\n' >&2 + exit 1 +fi + +if [ "$(git tag)" != "${tags_before}" ]; then + printf 'release.bash created a tag for an invalid version\n' >&2 + exit 1 +fi + +printf 'Release version validation test passed\n' From 8e8828ef4f34b9e28da7d46fbaad91c4c31a6f0c Mon Sep 17 00:00:00 2001 From: PointerL <124577547+PointerL@users.noreply.github.com> Date: Fri, 23 Oct 2026 00:43:50 +0800 Subject: [PATCH 2/3] fix(release): validate version before updating files Reject explicit versions outside major.minor.patch before sed can modify CMakeLists.txt. Signed-off-by: PointerL --- release.bash | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/release.bash b/release.bash index 14458a5cc..d1f6df328 100755 --- a/release.bash +++ b/release.bash @@ -42,6 +42,11 @@ if [[ -z "$NEW_VERSION" ]]; then echo "自动递增小版本号: $NEW_VERSION" fi +if [[ ! "$NEW_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "错误: 版本号必须使用 major.minor.patch 格式!" >&2 + exit 1 +fi + # 更新 CMakeLists.txt 文件中的 VERSION 字段 sed -E -i "/project\s*\(/,/\)/{ s/(VERSION\s+)[0-9]+\.[0-9]+\.[0-9]+/\1${NEW_VERSION}/ From 9c1ed40ee41fc540d4b720fa4d5158c1f1f58685 Mon Sep 17 00:00:00 2001 From: PointerL <124577547+PointerL@users.noreply.github.com> Date: Fri, 23 Oct 2026 00:51:21 +0800 Subject: [PATCH 3/3] test(release): isolate version validation fixture Ignore ambient Git worktree, signing, and hook settings while exercising the release helper. Signed-off-by: PointerL --- misc/tests/release_version_test.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/misc/tests/release_version_test.sh b/misc/tests/release_version_test.sh index 4bac1dec5..c2ebd6184 100644 --- a/misc/tests/release_version_test.sh +++ b/misc/tests/release_version_test.sh @@ -9,9 +9,10 @@ set -eu source_dir=$1 test_dir=$(mktemp -d) trap 'rm -rf "${test_dir}"' EXIT +unset GIT_DIR GIT_WORK_TREE cp "${source_dir}/release.bash" "${test_dir}/release.bash" -cat >"${test_dir}/CMakeLists.txt" <<'EOF' +cat > "${test_dir}/CMakeLists.txt" <<'EOF' project( linglong VERSION 1.15.0) @@ -21,6 +22,8 @@ cd "${test_dir}" git init --quiet git config user.name "Linyaps Test" git config user.email "test@linyaps.invalid" +git config commit.gpgsign false +git config core.hooksPath /dev/null git add CMakeLists.txt release.bash git commit --quiet -m "initial"