Skip to content

Commit 8c6bf8b

Browse files
feat: Add diff issue creation after system prompt update
- Add step to get old SYSTEM_PROMPT value before updating - Save old value to /tmp/old_value.txt using base64 encoding - Add create-diff-issue job that runs after update: - Reads old value from temp file and new value from system_prompt.md - Generates diff showing changes between old and new values - Creates issue with title "[工作流] 提示词更新 <run_id>" - Issue body starts with "[工作流运行 #<run_id>](https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID})" - Adds 'workflow' and 'documentation' labels to the issue Co-Authored-By: Claude (mimo-v2-flash) <[email protected]>
1 parent 2a71b7d commit 8c6bf8b

File tree

1 file changed

+79
-1
lines changed

1 file changed

+79
-1
lines changed

.github/workflows/update-system-prompt.yml

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ jobs:
2020
with:
2121
fetch-depth: 1
2222

23+
- name: Get old SYSTEM_PROMPT value
24+
id: get_old_value
25+
run: |
26+
echo "正在获取旧的 SYSTEM_PROMPT 值..."
27+
28+
# 获取旧值并保存到临时文件
29+
OLD_VALUE=$(gh api /repos/${{ github.repository }}/actions/variables/SYSTEM_PROMPT --jq '.value' 2>/dev/null || echo "")
30+
31+
if [ -z "$OLD_VALUE" ]; then
32+
echo "未找到现有的 SYSTEM_PROMPT 变量,将作为新变量创建"
33+
else
34+
echo "已获取旧值,长度: ${#OLD_VALUE} 字符"
35+
fi
36+
37+
# 保存到临时文件(使用 base64 编码以避免特殊字符问题)
38+
echo "$OLD_VALUE" | base64 -w 0 > /tmp/old_value.txt
39+
echo "old_value_saved=true" >> $GITHUB_OUTPUT
40+
2341
- name: Update SYSTEM_PROMPT variable
2442
run: |
2543
echo "正在更新 SYSTEM_PROMPT 变量..."
@@ -40,4 +58,64 @@ jobs:
4058
-f value="$SYSTEM_PROMPT_CONTENT"
4159
4260
echo "✓ SYSTEM_PROMPT 变量已更新"
43-
echo "文件大小: $(wc -c < system_prompt.md) 字符"
61+
echo "文件大小: $(wc -c < system_prompt.md) 字符"
62+
63+
- name: Create diff issue
64+
if: steps.get_old_value.outputs.old_value_saved == 'true'
65+
uses: actions/github-script@v7
66+
with:
67+
script: |
68+
// 读取旧值
69+
const fs = require('fs');
70+
const oldValueBase64 = fs.readFileSync('/tmp/old_value.txt', 'utf8');
71+
const oldValue = Buffer.from(oldValueBase64, 'base64').toString('utf-8');
72+
73+
// 读取新值
74+
const newContent = fs.readFileSync('system_prompt.md', 'utf-8');
75+
76+
// 生成 diff
77+
const diff = generateDiff(oldValue, newContent);
78+
79+
// 构建 issue 内容
80+
const runUrl = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
81+
const issueBody = `[工作流运行 #${process.env.GITHUB_RUN_ID}](${runUrl})\n\n${diff}`;
82+
83+
// 创建 issue
84+
const issue = await github.rest.issues.create({
85+
owner: context.repo.owner,
86+
repo: context.repo.repo,
87+
title: `[工作流] 提示词更新 ${process.env.GITHUB_RUN_ID}`,
88+
body: issueBody,
89+
labels: ['workflow', 'documentation']
90+
});
91+
92+
console.log(`✓ Issue created: #${issue.data.number}`);
93+
94+
function generateDiff(oldStr, newStr) {
95+
const oldLines = oldStr.split('\n');
96+
const newLines = newStr.split('\n');
97+
98+
let diff = '```diff\n';
99+
diff += `--- 旧变量 (${oldLines.length} 行)\n`;
100+
diff += `+++ 新变量 (${newLines.length} 行)\n`;
101+
102+
const maxLines = Math.max(oldLines.length, newLines.length);
103+
for (let i = 0; i < maxLines; i++) {
104+
const oldLine = oldLines[i];
105+
const newLine = newLines[i];
106+
107+
if (oldLine === newLine) {
108+
diff += ` ${newLine}\n`;
109+
} else if (oldLine && !newLine) {
110+
diff += `- ${oldLine}\n`;
111+
} else if (!oldLine && newLine) {
112+
diff += `+ ${newLine}\n`;
113+
} else {
114+
diff += `- ${oldLine}\n`;
115+
diff += `+ ${newLine}\n`;
116+
}
117+
}
118+
119+
diff += '```';
120+
return diff;
121+
}

0 commit comments

Comments
 (0)