Files
novalon-website/test-branch-matching.py
T
张翔 dd2a0999bb
ci/woodpecker/push/woodpecker Pipeline failed
fix: 修复企业微信通知环境变量展开问题
- 使用 PAYLOAD=$(cat <<ENDPAYLOAD) 替代 cat > file <<EOF
- 确保环境变量在 heredoc 中正确展开
- 添加测试脚本验证环境变量展开
- 修复构建详情链接和消息内容缺失问题
2026-03-28 22:48:22 +08:00

47 lines
1.3 KiB
Python

#!/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 '❌ 不匹配'}")