mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-12-19 13:10:16 +08:00
Enhances the release note generation step to compare commits between the previous and current tags, includes commit bodies and authors, and formats output for better readability. Also adds more robust extraction and output handling for the generated release notes.
152 lines
4.5 KiB
YAML
152 lines
4.5 KiB
YAML
name: "Build Action"
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- '*' # 任意 tag push 时触发
|
|
|
|
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
|
|
PREV_TAG=$(git describe --tags --abbrev=0 "$CURRENT_TAG^")
|
|
|
|
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
|