refactor: 整理脚本文件到 scripts 目录(任务 2.1/20)
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Woodpecker CI 分支匹配测试
|
||||
检查分支名称是否匹配配置中的规则
|
||||
"""
|
||||
|
||||
import fnmatch
|
||||
|
||||
def match_branch(branch_pattern, actual_branch):
|
||||
"""测试分支匹配"""
|
||||
if branch_pattern == actual_branch:
|
||||
return True
|
||||
|
||||
if branch_pattern.endswith("/**"):
|
||||
prefix = branch_pattern[:-3]
|
||||
return actual_branch.startswith(prefix + "/")
|
||||
|
||||
if "*" in branch_pattern:
|
||||
return fnmatch.fnmatch(actual_branch, branch_pattern)
|
||||
|
||||
return False
|
||||
|
||||
# 测试当前分支
|
||||
actual_branch = "release/v1.0.0"
|
||||
patterns = ["release", "release/**", "release/*"]
|
||||
|
||||
print(f"实际分支: {actual_branch}")
|
||||
print("\n匹配测试:")
|
||||
for pattern in patterns:
|
||||
result = match_branch(pattern, actual_branch)
|
||||
print(f" {pattern:20} -> {'✅ 匹配' if result else '❌ 不匹配'}")
|
||||
|
||||
# 测试其他分支
|
||||
test_branches = [
|
||||
("feature/new-feature", ["feature/**", "feature/*"]),
|
||||
("dev", ["dev"]),
|
||||
("release", ["release", "release/**"]),
|
||||
("release/v2.0.0", ["release", "release/**"]),
|
||||
]
|
||||
|
||||
print("\n\n其他分支测试:")
|
||||
for branch, patterns in test_branches:
|
||||
print(f"\n分支: {branch}")
|
||||
for pattern in patterns:
|
||||
result = match_branch(pattern, branch)
|
||||
print(f" {pattern:20} -> {'✅ 匹配' if result else '❌ 不匹配'}")
|
||||
Reference in New Issue
Block a user