forked from Ikalus1988/MisakaNet
-
Notifications
You must be signed in to change notification settings - Fork 0
125 lines (106 loc) · 4.29 KB
/
Copy pathauto-draft.yml
File metadata and controls
125 lines (106 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: Auto-Draft from Crash Tombstone
# 路线A闭环:崩溃墓碑 → draft lesson → 自动提 PR
# 触发方式:
# - workflow_dispatch: 手动传入墓碑 JSON
# - repository_dispatch: fatal-guard 远程触发(通过 API)
# - 从 crash-reports/ 目录读取墓碑文件
on:
workflow_dispatch:
inputs:
tombstone_json:
description: "fatal-guard 墓碑 JSON(可粘贴完整或路径)"
required: false
type: string
tombstone_file:
description: "墓碑 JSON 文件路径(相对于仓库根目录)"
required: false
type: string
repository_dispatch:
types: [crash-tombstone]
jobs:
auto-draft:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Generate Draft Lesson
id: draft
env:
TOMBSTONE: ${{ github.event.inputs.tombstone_json }}
TOMBSTONE_FILE: ${{ github.event.inputs.tombstone_file }}
run: |
# Validate tombstone_json length (max 64KB)
if [ -n "$TOMBSTONE" ] && [ "${#TOMBSTONE}" -gt 65536 ]; then
echo "ERROR: tombstone_json exceeds 64KB limit"
exit 1
fi
# Validate tombstone_file path (no traversal)
if [ -n "$TOMBSTONE_FILE" ]; then
case "$TOMBSTONE_FILE" in
../*|*/../*|*/..) echo "ERROR: path traversal not allowed"; exit 1 ;;
esac
fi
# Determine input source
if [ -n "$TOMBSTONE" ]; then
# Validate JSON format
echo "$TOMBSTONE" | python3 -m json.tool > /dev/null 2>&1 || { echo "ERROR: invalid JSON"; exit 1; }
echo "$TOMBSTONE" > /tmp/tombstone.json
elif [ -n "$TOMBSTONE_FILE" ] && [ -f "$TOMBSTONE_FILE" ]; then
cp "$TOMBSTONE_FILE" /tmp/tombstone.json
elif [ -f "crash-reports/latest-tombstone.json" ]; then
cp "crash-reports/latest-tombstone.json" /tmp/tombstone.json
else
echo "::warning::No tombstone input provided. Skipping."
exit 0
fi
# Generate draft lesson
python3 scripts/tombstone_to_draft.py --from-file /tmp/tombstone.json --create-bounty
# Capture the generated filename
DRAFT_FILE=$(ls -t lessons/drafts/draft-*.md 2>/dev/null | head -1)
if [ -z "$DRAFT_FILE" ]; then
echo "::warning::Draft generation produced no output"
exit 0
fi
echo "draft_file=$DRAFT_FILE" >> "$GITHUB_OUTPUT"
echo "Generated draft: $DRAFT_FILE"
- name: Create Pull Request
if: steps.draft.outputs.draft_file != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
DRAFT_FILE="${{ steps.draft.outputs.draft_file }}"
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
BRANCH="auto/draft-${TIMESTAMP}"
git config user.name "misakanet-bot"
git config user.email "bot@misakanet.org"
git checkout -b "$BRANCH"
git add lessons/drafts/
git commit -m "auto: draft lesson from crash tombstone [skip ci]"
# Push and create PR
git push origin "$BRANCH" --force
gh pr create \
--base main \
--head "$BRANCH" \
--title "🤖 Auto-Draft: Crash tombstone → draft lesson" \
--body "## Auto-generated Draft Lesson
This PR was automatically created by the **路线A 闭环** pipeline.
### What happened
1. A fatal-guard node captured a crash
2. The tombstone JSON was processed by \`scripts/tombstone_to_draft.py\`
3. A draft lesson was generated in \`lessons/drafts/\`
### Draft file
- \`$DRAFT_FILE\`
### Next Steps
- **Review**: Check if the crash data is valid (not noise)
- **Complete**: Fill in Root Cause, Solution, and Verification sections
- **Bounty**: If the draft is valid but incomplete, mark it as a bounty for Agents
### Auto-generated Bounty
A \`.bounty.json\` file was also created alongside the draft.
"