diff --git a/README.md b/README.md index 304cac4..183921f 100644 --- a/README.md +++ b/README.md @@ -26,13 +26,8 @@ AI 修改本项目时优先读: ```toml dependencies = [ -<<<<<<< HEAD - "iti-flask @ git+ssh://git@example.com/iTi-Flask.git@v0.2.0", - "iti-system @ git+ssh://git@example.com/iTi-System.git@v0.2.1", -======= "iti-flask @ git+https://git.noahlan.cn/iti-framework/iTi-Flask.git@v0.2.2", "iti-system @ git+https://git.noahlan.cn/iti-framework/iTi-System.git@v0.2.2", ->>>>>>> 9c8246e (docs: docs更新) ] ``` @@ -101,6 +96,13 @@ uv run pytest -q 它不跟随 `iTi-Flask` 自动发版。 ```bash -./scripts/iti-system.sh release -./scripts/iti-system.sh release v0.2.2 +./iti-system.sh release +./iti-system.sh release v0.2.2 +``` + +Windows: + +```bat +iti-system.cmd release +iti-system.cmd release v0.2.2 ``` diff --git a/iti-system.cmd b/iti-system.cmd new file mode 100644 index 0000000..6281350 --- /dev/null +++ b/iti-system.cmd @@ -0,0 +1,6 @@ +@echo off +setlocal + +set "SCRIPT_DIR=%~dp0" +call "%SCRIPT_DIR%scripts\iti-system.cmd" %* +exit /b %ERRORLEVEL% diff --git a/iti-system.sh b/iti-system.sh new file mode 100755 index 0000000..07ad31f --- /dev/null +++ b/iti-system.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh +set -eu + +SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +exec sh "$SCRIPT_DIR/scripts/iti-system.sh" "$@" diff --git a/iti_system/__about__.py b/iti_system/__about__.py index ce6aeaf..27482d2 100644 --- a/iti_system/__about__.py +++ b/iti_system/__about__.py @@ -1,8 +1,4 @@ # SPDX-FileCopyrightText: 2025-present NoahLan <6995syu@163.com> # # SPDX-License-Identifier: MIT -<<<<<<< HEAD -__version__ = "0.2.1" -======= __version__ = "0.2.2" ->>>>>>> 9c8246e (docs: docs更新) diff --git a/scripts/iti-system.cmd b/scripts/iti-system.cmd new file mode 100644 index 0000000..b5a71ba --- /dev/null +++ b/scripts/iti-system.cmd @@ -0,0 +1,77 @@ +@echo off +setlocal enabledelayedexpansion + +set "SCRIPT_DIR=%~dp0" +set "ROOT_DIR=%SCRIPT_DIR%.." +pushd "%ROOT_DIR%" >nul +set "ROOT_DIR=%CD%" + +set "PROJECT_VENV=%ROOT_DIR%\.venv" +if defined VIRTUAL_ENV ( + if /I not "%VIRTUAL_ENV%"=="%PROJECT_VENV%" ( + if /I not "%VIRTUAL_ENV%"=="%PROJECT_VENV%\" set "VIRTUAL_ENV=" + ) +) + +set "COMMAND=%~1" +if "%COMMAND%"=="" set "COMMAND=help" +shift /1 + +if "%COMMAND%"=="help" goto help +if "%COMMAND%"=="-h" goto help +if "%COMMAND%"=="--help" goto help +if "%COMMAND%"=="install" goto install +if "%COMMAND%"=="test" goto test +if "%COMMAND%"=="release" goto release + +echo 未知命令:%COMMAND% 1>&2 +echo. 1>&2 +goto help_error + +:help +echo iTi-System 开发脚本 +echo. +echo 用法: +echo iti-system.cmd ^<命令^> [参数] +echo. +echo 常用命令: +echo help 显示帮助 +echo install 安装开发依赖:uv sync --extra dev +echo test 运行测试:uv run pytest -q +echo release [版本] 发布系统包:测试、改版本、提交、打 tag、推送 +popd >nul +exit /b 0 + +:help_error +call :help +exit /b 2 + +:install +uv sync --extra dev +goto end + +:test +uv run pytest -q +goto end + +:release +set "SHELL_CMD=" +where sh >nul 2>nul && set "SHELL_CMD=sh" +if not defined SHELL_CMD ( + where bash >nul 2>nul && set "SHELL_CMD=bash" +) +if not defined SHELL_CMD ( + echo 找不到 sh 或 bash,无法运行 release 脚本 1>&2 + exit /b 1 +) +if "%~1"=="" ( + "%SHELL_CMD%" scripts/release.sh +) else ( + "%SHELL_CMD%" scripts/release.sh %* +) +goto end + +:end +set "EXIT_CODE=%ERRORLEVEL%" +popd >nul +exit /b %EXIT_CODE% diff --git a/scripts/iti-system.sh b/scripts/iti-system.sh index 1d59ddd..2f2b142 100755 --- a/scripts/iti-system.sh +++ b/scripts/iti-system.sh @@ -18,7 +18,7 @@ show_help() { iTi-System 开发脚本 用法: - ./scripts/iti-system.sh <命令> [参数] + ./iti-system.sh <命令> [参数] 常用命令: help 显示帮助 diff --git a/scripts/release.sh b/scripts/release.sh index 3ea98a4..563f310 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -5,6 +5,7 @@ ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) cd "$ROOT_DIR" ABOUT_FILE="$ROOT_DIR/iti_system/__about__.py" +PYPROJECT_FILE="$ROOT_DIR/pyproject.toml" README_FILE="$ROOT_DIR/README.md" die() { @@ -46,13 +47,16 @@ bump_patch() { } version_is_newer() { - current_parts=$(parse_version "$1") + current_version=$1 + target_version=$2 + + current_parts=$(parse_version "$current_version") set -- $current_parts current_major=$1 current_minor=$2 current_patch=$3 - target_parts=$(parse_version "$2") + target_parts=$(parse_version "$target_version") set -- $target_parts target_major=$1 target_minor=$2 @@ -104,18 +108,49 @@ replace_first_exact_line() { fi } +replace_first_line_with_prefix() { + file=$1 + prefix=$2 + new_line=$3 + tmp_file=$(mktemp) + + if awk -v prefix="$prefix" -v new="$new_line" ' + BEGIN { done = 0 } + index($0, prefix) == 1 && !done { + print new + done = 1 + next + } + { print } + END { if (!done) exit 1 } + ' "$file" >"$tmp_file"; then + mv "$tmp_file" "$file" + else + rm -f "$tmp_file" + die "line not updated in $file" + fi +} + write_about_version() { - current_version=$1 - target_version=$2 - replace_first_exact_line "$ABOUT_FILE" "__version__ = \"$current_version\"" "__version__ = \"$target_version\"" + target_version=$1 + replace_first_line_with_prefix "$ABOUT_FILE" "__version__ = " "__version__ = \"$target_version\"" } -write_readme_tags() { - current_version=$1 - target_version=$2 - old_line=' "iti-system @ git+https://git.noahlan.cn/iti-framework/iTi-System.git@v'"$current_version"'",' - new_line=' "iti-system @ git+https://git.noahlan.cn/iti-framework/iTi-System.git@v'"$target_version"'",' - replace_first_exact_line "$README_FILE" "$old_line" "$new_line" +write_pyproject_framework_tag() { + target_version=$1 + replace_first_line_with_prefix "$PYPROJECT_FILE" 'iti-flask = { git = "https://git.noahlan.cn/iti-framework/iTi-Flask.git", tag = "' "iti-flask = { git = \"https://git.noahlan.cn/iti-framework/iTi-Flask.git\", tag = \"v$target_version\" }" +} + +write_readme_dependency_tags() { + target_version=$1 + replace_first_line_with_prefix "$README_FILE" ' "iti-flask @ git+https://git.noahlan.cn/iti-framework/iTi-Flask.git@v' ' "iti-flask @ git+https://git.noahlan.cn/iti-framework/iTi-Flask.git@v'"$target_version"'",' + replace_first_line_with_prefix "$README_FILE" ' "iti-system @ git+https://git.noahlan.cn/iti-framework/iTi-System.git@v' ' "iti-system @ git+https://git.noahlan.cn/iti-framework/iTi-System.git@v'"$target_version"'",' +} + +write_readme_release_examples() { + target_version=$1 + replace_first_line_with_prefix "$README_FILE" './iti-system.sh release v' "./iti-system.sh release v$target_version" + replace_first_line_with_prefix "$README_FILE" 'iti-system.cmd release v' "iti-system.cmd release v$target_version" } ensure_clean_tree() { @@ -162,10 +197,12 @@ main() { ensure_tag_absent "$target_tag" uv run pytest -q - write_about_version "$current_version" "$target_version" - write_readme_tags "$current_version" "$target_version" + write_about_version "$target_version" + write_pyproject_framework_tag "$target_version" + write_readme_dependency_tags "$target_version" + write_readme_release_examples "$target_version" - git add iti_system/__about__.py README.md + git add iti_system/__about__.py pyproject.toml README.md git commit -m "chore: release $target_tag" git tag -a "$target_tag" -m "release $target_tag" git push origin "$branch" "$target_tag"