更新 README.md,修正 Hugging Face 链接以指向正确的项目页面 #48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Auto Release | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
auto-release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code with full history | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # 获取完整提交历史 | |
- name: Install jq for JSON parsing | |
run: sudo apt-get install -y jq | |
- name: Extract before and after SHAs from event | |
id: extract_shas | |
run: | | |
# 从事件中提取 before 和 after 的 commit hash | |
BEFORE_SHA=$(jq -r '.before' "$GITHUB_EVENT_PATH") | |
AFTER_SHA=$(jq -r '.after' "$GITHUB_EVENT_PATH") | |
# 如果是首次推送(before 为全零),获取初始提交 | |
if [ "$BEFORE_SHA" = "0000000000000000000000000000000000000000" ]; then | |
BEFORE_SHA=$(git rev-list --max-parents=0 HEAD) | |
fi | |
# 保存到环境变量 | |
echo "BEFORE_SHA=$BEFORE_SHA" >> "$GITHUB_ENV" | |
echo "AFTER_SHA=$AFTER_SHA" >> "$GITHUB_ENV" | |
- name: Generate diff for entire push | |
run: | | |
# 生成整个推送范围内的 diff | |
git diff --patch ${{ env.BEFORE_SHA }}..${{ env.AFTER_SHA }} > changes.diff | |
echo "=== Diff 内容如下 ===" | |
cat changes.diff | |
- name: Get latest tag and generate next version | |
id: get_tag | |
run: | | |
git fetch --tags | |
latest_tag=$(git tag --list 'v*' --sort=-v:refname | head -n 1) | |
if [ -z "$latest_tag" ]; then | |
echo "tag=v1.0.0" >> "$GITHUB_OUTPUT" | |
else | |
IFS='.' read -r major minor patch <<< "${latest_tag#v}" | |
if (( patch < 9 )); then | |
patch=$((patch + 1)) | |
else | |
patch=0 | |
if (( minor < 9 )); then | |
minor=$((minor + 1)) | |
else | |
minor=0 | |
major=$((major + 1)) | |
fi | |
fi | |
echo "tag=v$major.$minor.$patch" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Generate AI Release Notes | |
id: ai_notes | |
env: | |
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} | |
run: | | |
set -e | |
PROMPT="请根据以下代码差异生成符合 GitHub Release 标准的 changelog,切记只输出changelog的内容即可。要求:\n1. 使用 ### 分类标题\n2. 每项添加合适 emoji\n3. 简明扼要描述变更\n4. 不要使用代码块(三个反引号包裹)\n5. 输出语言为中文\n\n示例格式:\n### 新增功能\n- ✨ 新增了用户注册功能\n\n### 修复问题\n- 🐛 修复了登录页面的显示问题\n\n### 优化改进\n- ⚡ 优化了加载速度\n\n代码差异:\n" | |
DIFF_CONTENT=$(cat changes.diff) | |
FULL_PROMPT="$PROMPT$DIFF_CONTENT" | |
JSON_PROMPT=$(printf "%s" "$FULL_PROMPT" | jq -Rs .) | |
cat <<EOF > request.json | |
{ | |
"model": "deepseek/deepseek-chat-v3-0324:free", | |
"messages": [ | |
{ | |
"role": "user", | |
"content": $JSON_PROMPT | |
} | |
] | |
} | |
EOF | |
echo "==== request.json 内容如下 ====" | |
cat request.json | |
response=$(curl -s https://openrouter.ai/api/v1/chat/completions \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer $OPENROUTER_API_KEY" \ | |
--data-binary @request.json) | |
echo "==== API response 内容如下 ====" | |
echo "$response" | |
generated_notes=$(echo "$response" | jq -e -r '.choices[0].message.content') || { echo "AI返回内容解析失败"; exit 3; } | |
if [ -z "$generated_notes" ]; then | |
echo "AI未生成内容"; exit 4; | |
fi | |
echo "$generated_notes" > release_note.txt | |
- name: Create tag and release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config user.name github-actions | |
git config user.email github-actions@github.com | |
git tag ${{ steps.get_tag.outputs.tag }} | |
git push origin ${{ steps.get_tag.outputs.tag }} | |
note="$(cat release_note.txt)" | |
gh release create ${{ steps.get_tag.outputs.tag }} --notes "$note" --title "${{ steps.get_tag.outputs.tag }}" |