dd2a0999bb
ci/woodpecker/push/woodpecker Pipeline failed
- 使用 PAYLOAD=$(cat <<ENDPAYLOAD) 替代 cat > file <<EOF - 确保环境变量在 heredoc 中正确展开 - 添加测试脚本验证环境变量展开 - 修复构建详情链接和消息内容缺失问题
138 lines
4.3 KiB
Python
138 lines
4.3 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
Woodpecker CI 配置诊断工具
|
||
检查配置文件中可能导致 CI 未触发的问题
|
||
"""
|
||
|
||
import yaml
|
||
from pathlib import Path
|
||
|
||
|
||
def diagnose_woodpecker_config(config_path):
|
||
"""诊断 Woodpecker CI 配置"""
|
||
|
||
with open(config_path, 'r', encoding='utf-8') as f:
|
||
config = yaml.safe_load(f)
|
||
|
||
print("="*70)
|
||
print("Woodpecker CI 配置诊断报告")
|
||
print("="*70)
|
||
|
||
issues = []
|
||
warnings = []
|
||
|
||
# 检查是否有 steps
|
||
if 'steps' not in config:
|
||
issues.append("❌ 缺少 'steps' 配置")
|
||
else:
|
||
print(f"\n✅ 找到 {len(config['steps'])} 个步骤")
|
||
|
||
# 检查每个步骤的 when 条件
|
||
print("\n📋 步骤触发条件检查:")
|
||
print("-" * 70)
|
||
|
||
for step_name, step_config in config.get('steps', {}).items():
|
||
if not isinstance(step_config, dict):
|
||
continue
|
||
|
||
when = step_config.get('when', {})
|
||
|
||
if not when:
|
||
warnings.append(f"⚠️ 步骤 '{step_name}' 没有 when 条件,将始终执行")
|
||
continue
|
||
|
||
# 检查 when 条件的格式
|
||
if isinstance(when, list):
|
||
print(f"\n步骤: {step_name}")
|
||
print(f" when 条件格式: 列表(多个条件)")
|
||
for i, condition in enumerate(when):
|
||
if isinstance(condition, dict):
|
||
events = condition.get('event', [])
|
||
branches = condition.get('branch', [])
|
||
print(f" 条件 {i+1}:")
|
||
print(f" 事件: {events}")
|
||
print(f" 分支: {branches}")
|
||
elif isinstance(when, dict):
|
||
print(f"\n步骤: {step_name}")
|
||
print(f" when 条件格式: 字典(单个条件)")
|
||
events = when.get('event', [])
|
||
branches = when.get('branch', [])
|
||
print(f" 事件: {events}")
|
||
print(f" 分支: {branches}")
|
||
|
||
# 检查可能导致问题的配置
|
||
print("\n\n🔍 潜在问题分析:")
|
||
print("-" * 70)
|
||
|
||
# 检查是否有 skip_clone
|
||
if config.get('skip_clone'):
|
||
warnings.append("⚠️ skip_clone 设置为 true,可能影响代码获取")
|
||
|
||
# 检查 clone 配置
|
||
clone_config = config.get('clone', {})
|
||
if clone_config:
|
||
print(f"\nClone 配置: {clone_config}")
|
||
|
||
# 检查 services
|
||
services = config.get('services', {})
|
||
if services:
|
||
print(f"\n服务配置: {list(services.keys())}")
|
||
|
||
# 检查 workspace
|
||
workspace = config.get('workspace', {})
|
||
if workspace:
|
||
print(f"\n工作区配置: {workspace}")
|
||
|
||
# 输出问题
|
||
print("\n\n📊 诊断结果:")
|
||
print("="*70)
|
||
|
||
if issues:
|
||
print("\n❌ 发现的问题:")
|
||
for issue in issues:
|
||
print(f" {issue}")
|
||
|
||
if warnings:
|
||
print("\n⚠️ 警告:")
|
||
for warning in warnings:
|
||
print(f" {warning}")
|
||
|
||
if not issues and not warnings:
|
||
print("\n✅ 配置文件语法正确,未发现明显问题")
|
||
|
||
# 输出可能的原因
|
||
print("\n\n🔍 CI 未触发的可能原因:")
|
||
print("-" * 70)
|
||
possible_reasons = [
|
||
"1. Woodpecker CI 的 Webhook 未正确配置",
|
||
"2. Git 仓库设置中禁用了该分支的 CI 触发",
|
||
"3. Woodpecker CI 服务器未运行或配置错误",
|
||
"4. 配置文件中的分支匹配规则与 Woodpecker CI 版本不兼容",
|
||
"5. 需要在 Woodpecker CI 界面手动激活该仓库",
|
||
"6. Woodpecker CI 的全局配置限制了某些分支",
|
||
"7. 推送的提交信息触发了 CI 跳过(如包含 [skip ci])",
|
||
]
|
||
|
||
for reason in possible_reasons:
|
||
print(f" {reason}")
|
||
|
||
print("\n\n💡 建议的排查步骤:")
|
||
print("-" * 70)
|
||
suggestions = [
|
||
"1. 检查 Woodpecker CI Web 界面,确认仓库已激活",
|
||
"2. 检查 Git 仓库的 Webhook 设置",
|
||
"3. 查看 Woodpecker CI 的日志",
|
||
"4. 尝试手动触发 CI(如果支持)",
|
||
"5. 检查 Woodpecker CI 的全局配置",
|
||
"6. 创建一个简单的测试分支验证配置",
|
||
]
|
||
|
||
for suggestion in suggestions:
|
||
print(f" {suggestion}")
|
||
|
||
print("\n" + "="*70)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
diagnose_woodpecker_config(".woodpecker.yml")
|