chore: update
This commit is contained in:
@@ -29,6 +29,8 @@ __all__ = [
|
||||
"format_all",
|
||||
"format_with_ruff",
|
||||
"generate_module_docstring",
|
||||
"git_add_commit",
|
||||
"git_init_add_commit",
|
||||
"has_files",
|
||||
"init_sub_dirs",
|
||||
"lint_with_ruff",
|
||||
@@ -91,12 +93,10 @@ _INIT_VERSION_PATTERN = re.compile(
|
||||
PACKAGE_DIR = "packages"
|
||||
REQUIREMENTS_FILE = "requirements.txt"
|
||||
|
||||
_PROTECTED_PACKAGES: frozenset[str] = frozenset(
|
||||
{
|
||||
"pyflowx",
|
||||
"bitool",
|
||||
}
|
||||
)
|
||||
_PROTECTED_PACKAGES: frozenset[str] = frozenset({
|
||||
"pyflowx",
|
||||
"bitool",
|
||||
})
|
||||
|
||||
|
||||
# ============================================================================
|
||||
@@ -569,5 +569,48 @@ def not_has_git_repo() -> bool:
|
||||
|
||||
@px.register_fn
|
||||
def has_files() -> bool:
|
||||
"""检查当前目录是否有文件."""
|
||||
return bool(list(Path.cwd().glob("*")))
|
||||
"""检查当前 Git 仓库是否有未提交的更改."""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["git", "status", "--porcelain"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
return bool(result.stdout.strip())
|
||||
except (subprocess.SubprocessError, OSError):
|
||||
return False
|
||||
|
||||
|
||||
@px.register_fn
|
||||
def git_add_commit(message: str = "chore: update") -> None:
|
||||
"""执行 git add + git commit (仅当有未提交更改时).
|
||||
|
||||
Parameters
|
||||
----------
|
||||
message : str
|
||||
提交信息
|
||||
"""
|
||||
if not has_files():
|
||||
print("没有文件需要提交")
|
||||
return
|
||||
subprocess.run(["git", "add", "."], check=True)
|
||||
subprocess.run(["git", "commit", "-m", message], check=True)
|
||||
|
||||
|
||||
@px.register_fn
|
||||
def git_init_add_commit(message: str = "init commit") -> None:
|
||||
"""执行 git init (若需) + git add + git commit (若有更改).
|
||||
|
||||
Parameters
|
||||
----------
|
||||
message : str
|
||||
提交信息
|
||||
"""
|
||||
if not_has_git_repo():
|
||||
subprocess.run(["git", "init"], check=True)
|
||||
if has_files():
|
||||
subprocess.run(["git", "add", "."], check=True)
|
||||
subprocess.run(["git", "commit", "-m", message], check=True)
|
||||
else:
|
||||
print("没有文件需要提交")
|
||||
|
||||
@@ -1,54 +1,24 @@
|
||||
# gittool - Git 执行工具
|
||||
# 用法:
|
||||
# yamlrun gittool.yaml --job a # 添加并提交
|
||||
# yamlrun gittool.yaml --job c # 清理
|
||||
# yamlrun gittool.yaml --job i # 初始化、添加并提交
|
||||
# yamlrun gittool.yaml --job p # 推送
|
||||
# yamlrun gittool.yaml --job a
|
||||
# yamlrun gittool.yaml --job c
|
||||
# yamlrun gittool.yaml --job i
|
||||
# yamlrun gittool.yaml --job isub
|
||||
# yamlrun gittool.yaml --job p
|
||||
# yamlrun gittool.yaml --job pl
|
||||
strategy: thread
|
||||
jobs:
|
||||
a:
|
||||
needs: [add]
|
||||
cmd: ["git", "commit", "-m", "chore: update"]
|
||||
add:
|
||||
cmd: ["git", "add", "."]
|
||||
fn: git_add_commit
|
||||
args: ["chore: update"]
|
||||
clean:
|
||||
cmd: ["git", "clean", "-xfd", "-e", "idea.config", "-e", "idea_modules.xml", "-e", "vcs.xml"]
|
||||
c:
|
||||
needs: [clean]
|
||||
cmd: ["git", "status", "--porcelain"]
|
||||
clean:
|
||||
cmd:
|
||||
- "git"
|
||||
- "clean"
|
||||
- "-xfd"
|
||||
- "-e"
|
||||
- ".vscode"
|
||||
- "-e"
|
||||
- ".idea"
|
||||
- "-e"
|
||||
- ".editorconfig"
|
||||
- "-e"
|
||||
- ".trae"
|
||||
- "-e"
|
||||
- ".qoder"
|
||||
- "-e"
|
||||
- ".venv"
|
||||
- "-e"
|
||||
- ".git"
|
||||
- "-e"
|
||||
- ".tox"
|
||||
- "-e"
|
||||
- ".pytest_cache"
|
||||
- "-e"
|
||||
- "node_modules"
|
||||
- "-e"
|
||||
- ".ruff_cache"
|
||||
i:
|
||||
needs: [init, add_all]
|
||||
cmd: ["git", "commit", "-m", "init commit"]
|
||||
init:
|
||||
cmd: ["git", "init"]
|
||||
add_all:
|
||||
needs: [init]
|
||||
cmd: ["git", "add", "."]
|
||||
fn: git_init_add_commit
|
||||
args: ["init commit"]
|
||||
isub:
|
||||
fn: init_sub_dirs
|
||||
p:
|
||||
|
||||
Reference in New Issue
Block a user