mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-12-19 05:05:44 +08:00
Renamed workflow, improved job and step naming, and streamlined artifact zipping and release note generation. Switched to using softprops/action-gh-release for release creation and asset upload, removed manual commit list preparation, and enhanced error handling for release note generation. Updated permissions and environment variables for consistency.
135 lines
4.0 KiB
YAML
135 lines
4.0 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="${GITHUB_REF#refs/tags/}"
|
|
COMMITS=$(git log --pretty=format:'%h %s (%an)' -n 30)
|
|
PROMPT_FILE=".github/prompt/release_note_prompt.txt"
|
|
SYSTEM_PROMPT=$(<"$PROMPT_FILE")
|
|
USER_CONTENT="TAG: $TAG\n提交列表:\n$COMMITS"
|
|
|
|
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}')
|
|
|
|
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
|
|
|
|
echo "$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
|