mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-12-19 13:10:16 +08:00
Replaces 'git describe' with logic to find the previous tag by sorting all tags by creation date. This ensures accurate detection of the previous tag for release note generation and adds error handling if no previous tag is found.
166 lines
4.9 KiB
YAML
166 lines
4.9 KiB
YAML
name: AI RELEASE NapCat
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
tags:
|
|
- '*'
|
|
|
|
permissions: write-all
|
|
|
|
env:
|
|
OPENROUTER_API_URL: https://openrouter.ai/api/v1/chat/completions
|
|
OPENROUTER_MODEL: "openrouter/auto"
|
|
RELEASE_NAME: "NapCat"
|
|
|
|
jobs:
|
|
Build-LiteLoader:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Clone Main Repository
|
|
uses: actions/checkout@v4
|
|
- name: Use Node.js 20.X
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 20.x
|
|
- name: Build NapCat.Framework
|
|
run: |
|
|
npm i -g pnpm
|
|
pnpm i
|
|
pnpm --filter napcat-webui-frontend run build || exit 1
|
|
pnpm run build:framework
|
|
mv packages/napcat-framework/dist framework-dist
|
|
cd framework-dist
|
|
npm install --omit=dev
|
|
rm ./package-lock.json || exit 0
|
|
- name: Upload Artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: NapCat.Framework
|
|
path: framework-dist
|
|
|
|
Build-Shell:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Clone Main Repository
|
|
uses: actions/checkout@v4
|
|
- name: Use Node.js 20.X
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 20.x
|
|
- name: Build NapCat.Shell
|
|
run: |
|
|
npm i -g pnpm
|
|
pnpm i
|
|
pnpm --filter napcat-webui-frontend run build || exit 1
|
|
pnpm run build:shell
|
|
mv packages/napcat-shell/dist shell-dist
|
|
cd shell-dist
|
|
npm install --omit=dev
|
|
rm ./package-lock.json || exit 0
|
|
- name: Upload Artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: NapCat.Shell
|
|
path: shell-dist
|
|
|
|
release-napcat:
|
|
needs: [Build-LiteLoader, Build-Shell]
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Download Artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
path: ./artifacts
|
|
|
|
- name: Zip Artifacts
|
|
run: |
|
|
cd artifacts
|
|
[ -d NapCat.Framework ] && zip -qr ../NapCat.Framework.zip -r NapCat.Framework
|
|
[ -d NapCat.Shell ] && zip -qr ../NapCat.Shell.zip -r NapCat.Shell
|
|
cd ..
|
|
|
|
- name: Generate release note via OpenRouter
|
|
env:
|
|
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
|
|
OPENROUTER_API_URL: ${{ env.OPENROUTER_API_URL }}
|
|
OPENROUTER_MODEL: ${{ env.OPENROUTER_MODEL }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
# 当前 tag
|
|
CURRENT_TAG="${GITHUB_REF#refs/tags/}"
|
|
|
|
# 获取所有 tag 按创建时间倒序排列
|
|
TAGS=( $(git tag --sort=-creatordate) )
|
|
|
|
# 找到上一个 tag
|
|
PREV_TAG=""
|
|
for i in "${!TAGS[@]}"; do
|
|
if [ "${TAGS[$i]}" = "$CURRENT_TAG" ]; then
|
|
if [ $((i+1)) -lt ${#TAGS[@]} ]; then
|
|
PREV_TAG="${TAGS[$((i+1))]}"
|
|
fi
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [ -z "$PREV_TAG" ]; then
|
|
echo "❌ Could not find previous tag for $CURRENT_TAG, aborting."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Generating release note from $PREV_TAG to $CURRENT_TAG"
|
|
|
|
# 获取 commit title + body + 作者,保留换行
|
|
COMMITS=$(git log --pretty=format:'%h %B (%an)' "$PREV_TAG".."$CURRENT_TAG" | sed 's/$/\\n/')
|
|
|
|
# 读取 prompt
|
|
PROMPT_FILE=".github/prompt/release_note_prompt.txt"
|
|
SYSTEM_PROMPT=$(<"$PROMPT_FILE")
|
|
|
|
# 构建用户内容
|
|
USER_CONTENT="TAG: $CURRENT_TAG\n提交列表:\n$COMMITS"
|
|
|
|
# 构建请求 JSON
|
|
BODY=$(jq -n \
|
|
--arg system "$SYSTEM_PROMPT" \
|
|
--arg user "$USER_CONTENT" \
|
|
'{model: env.OPENROUTER_MODEL, messages:[{role:"system", content:$system},{role:"user", content:$user}], temperature:0.2, max_tokens:800}')
|
|
|
|
# 调用 OpenRouter
|
|
RESPONSE=$(curl -s -X POST "$OPENROUTER_API_URL" \
|
|
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$BODY")
|
|
|
|
echo "=== OpenRouter raw response ==="
|
|
echo "$RESPONSE" | jq .
|
|
|
|
# 提取生成内容
|
|
RELEASE_BODY=$(echo "$RESPONSE" | jq -r '.choices[0].message.content // .choices[0].text // ""')
|
|
|
|
if [ -z "$RELEASE_BODY" ]; then
|
|
echo "❌ OpenRouter failed to generate release note, terminating workflow."
|
|
exit 1
|
|
fi
|
|
|
|
# 输出到 CHANGELOG.md
|
|
echo -e "$RELEASE_BODY" > CHANGELOG.md
|
|
echo "=== generated release note ==="
|
|
cat CHANGELOG.md
|
|
|
|
- name: Create Release Draft and Upload Artifacts
|
|
uses: softprops/action-gh-release@v1
|
|
with:
|
|
name: NapCat ${{ github.ref_name }}
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
body_path: CHANGELOG.md
|
|
files: |
|
|
NapCat.Framework.zip
|
|
NapCat.Shell.zip
|
|
draft: true
|