mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-06 13:05:09 +00:00
feat: 自动化version打包
This commit is contained in:
166
.github/workflows/auto-release.yml
vendored
Normal file
166
.github/workflows/auto-release.yml
vendored
Normal file
@@ -0,0 +1,166 @@
|
||||
name: Build Release (OpenRouter AI notes on tag)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*' # 任意 tag push 时触发,可改为 'v*.*.*'
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
env:
|
||||
OPENROUTER_API_URL: https://openrouter.ai/api/v1/chat/completions
|
||||
OPENROUTER_MODEL: "deepseek/deepseek-chat-v3-0324:free"
|
||||
RELEASE_NAME: "NapCat"
|
||||
|
||||
jobs:
|
||||
Build-LiteLoader:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- 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 -f package-lock.json
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: NapCat.Framework
|
||||
path: framework-dist
|
||||
|
||||
Build-Shell:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- 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 -f package-lock.json
|
||||
- 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:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: ./artifacts
|
||||
|
||||
- name: Make zips
|
||||
run: |
|
||||
cd artifacts || exit 0
|
||||
[ -d NapCat.Shell ] && (cd NapCat.Shell && zip -qr ../NapCat.Shell.zip .)
|
||||
[ -d NapCat.Framework ] && (cd NapCat.Framework && zip -qr ../NapCat.Framework.zip .)
|
||||
cd ..
|
||||
ls -la
|
||||
|
||||
- name: Prepare commits list
|
||||
run: |
|
||||
TAG="${GITHUB_REF#refs/tags/}"
|
||||
git fetch --all --tags || true
|
||||
PREV_TAG=$(git tag --sort=-creatordate | grep -v "^$" | awk -v t="$TAG" '$0!=t{print; exit}')
|
||||
if [ -n "$PREV_TAG" ]; then
|
||||
git log --pretty=format:'%h %s (%an)' "$PREV_TAG..$TAG" > /tmp/commits.txt || git log --pretty=format:'%h %s (%an)' -n 30 > /tmp/commits.txt
|
||||
else
|
||||
git log --pretty=format:'%h %s (%an)' -n 30 > /tmp/commits.txt
|
||||
fi
|
||||
echo "=== commits ==="
|
||||
sed -n '1,200p' /tmp/commits.txt || true
|
||||
|
||||
- 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
|
||||
PROMPT_FILE=".github/prompt/release_note_prompt.txt"
|
||||
TAG="${GITHUB_REF#refs/tags/}"
|
||||
ARTIFACTS_LIST=$(ls ./artifacts 2>/dev/null | tr '\n' ',' | sed 's/,$//')
|
||||
COMMITS=$(sed 's/"/\\"/g' /tmp/commits.txt || echo "无提交信息")
|
||||
USER_CONTENT="$(printf "TAG: %s\nARTIFACTS: %s\n\n提交列表:\n%s" "$TAG" "$ARTIFACTS_LIST" "$COMMITS")"
|
||||
SYSTEM_PROMPT="$(jq -Rs . < "$PROMPT_FILE")"
|
||||
|
||||
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 "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
|
||||
-d "$BODY")
|
||||
|
||||
echo "$RESPONSE" | jq -r '.choices[0].message.content // .choices[0].text // ""' > /tmp/release_body.txt || true
|
||||
echo "=== generated release note ==="
|
||||
sed -n '1,200p' /tmp/release_body.txt || true
|
||||
|
||||
- name: Create or update release & upload assets
|
||||
env:
|
||||
GHTOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
REPO: ${{ github.repository }}
|
||||
TAG: "${{ github.ref_name }}"
|
||||
run: |
|
||||
set -euo pipefail
|
||||
BODY=$(sed 's/"/\\"/g' /tmp/release_body.txt || echo "Automated release")
|
||||
# check existing release for this tag
|
||||
EXIST=$(curl -s -H "Authorization: token $GHTOKEN" "https://api.github.com/repos/$REPO/releases/tags/$TAG" || true)
|
||||
RID=$(echo "$EXIST" | jq -r '.id // empty')
|
||||
if [ -n "$RID" ]; then
|
||||
echo "Update existing release id $RID"
|
||||
jq -n --arg body "$BODY" '{body:$body}' > /tmp/update.json
|
||||
curl -s -X PATCH -H "Authorization: token $GHTOKEN" -H "Content-Type: application/json" \
|
||||
"https://api.github.com/repos/$REPO/releases/$RID" -d @/tmp/update.json | jq -r '.id'
|
||||
else
|
||||
echo "Create release for tag $TAG"
|
||||
jq -n --arg tag "$TAG" --arg name "${RELEASE_NAME} $TAG" --arg body "$BODY" \
|
||||
'{tag_name:$tag, name:$name, body:$body, draft:true, prerelease:false}' > /tmp/create.json
|
||||
CREATE_RESP=$(curl -s -X POST -H "Authorization: token $GHTOKEN" -H "Content-Type: application/json" \
|
||||
"https://api.github.com/repos/$REPO/releases" -d @/tmp/create.json)
|
||||
RID=$(echo "$CREATE_RESP" | jq -r '.id')
|
||||
fi
|
||||
|
||||
upload() {
|
||||
f="$1"
|
||||
[ -f "$f" ] || { echo "skip $f"; return; }
|
||||
NAME=$(basename "$f")
|
||||
UPLOAD_URL=$(curl -s -H "Authorization: token $GHTOKEN" "https://api.github.com/repos/$REPO/releases/$RID" | jq -r '.upload_url')
|
||||
UPLOAD_URL="${UPLOAD_URL%\{*}?name=${NAME}"
|
||||
echo "Uploading $NAME..."
|
||||
curl -s -X POST -H "Authorization: token $GHTOKEN" -H "Content-Type: application/zip" --data-binary @"$f" "$UPLOAD_URL" | jq -r '.id'
|
||||
}
|
||||
|
||||
upload "./artifacts/NapCat.Framework.zip"
|
||||
upload "./artifacts/NapCat.Shell.zip"
|
||||
echo "done"
|
||||
Reference in New Issue
Block a user