Skip to content

Merge branch 'dev'

Merge branch 'dev' #1

Workflow file for this run

name: Build and Release
# 触发条件:push main;BsKeyTools 版本未变则自动跳过
on:
push:
branches: [main]
permissions:
contents: write
jobs:
# ── Job 0: 检测 BsKeyTools 版本是否需要发布 ────────────────────────────
check-version:
runs-on: ubuntu-latest
outputs:
bskt_version: ${{ steps.ver.outputs.BSKT_VERSION }}
bscv_version: ${{ steps.ver.outputs.BSCV_VERSION }}
tag: ${{ steps.ver.outputs.TAG }}
should_release: ${{ steps.ver.outputs.SHOULD_RELEASE }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect versions and check tag
id: ver
run: |
# BsKeyTools 版本(BulletKeyTools.ms)
BSKT=$(python3 -c "
import re, sys
with open('_BsKeyTools/Scripts/BulletScripts/BulletKeyTools.ms', encoding='utf-8', errors='replace') as f:
c = f.read()
m = re.search(r'global\s+curVerBsKeyTools\s*=\s*\"([^\"]+)\"', c)
if not m: sys.exit('curVerBsKeyTools not found in BulletKeyTools.ms')
print(m.group(1))
")
# BsCleanVirus 版本(BsCleanVirus.ms)
BSCV=$(python3 -c "
import re, sys
with open('_BsKeyTools/Scripts/BulletScripts/BsCleanVirus.ms', encoding='utf-8', errors='replace') as f:
c = f.read()
m = re.search(r'global\s+curVerBsCleanVirus\s*=\s*\"([^\"]+)\"', c)
if not m: sys.exit('curVerBsCleanVirus not found in BsCleanVirus.ms')
print(m.group(1))
")
TAG="v$BSKT"
echo "BSKT_VERSION=$BSKT" >> $GITHUB_OUTPUT
echo "BSCV_VERSION=$BSCV" >> $GITHUB_OUTPUT
echo "TAG=$TAG" >> $GITHUB_OUTPUT
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "SHOULD_RELEASE=false" >> $GITHUB_OUTPUT
echo "Tag $TAG 已存在,跳过发布"
else
echo "SHOULD_RELEASE=true" >> $GITHUB_OUTPUT
echo "新版本 $TAG(BsKeyTools $BSKT / BsCleanVirus $BSCV),准备发布"
fi
# ── Job 1: 构建 BsKeyTools 安装包 ─────────────────────────────────────
build-bskeytools:
needs: check-version
if: needs.check-version.outputs.should_release == 'true'
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
- name: Update NSIS versions
shell: pwsh
env:
RELEASE_VERSION: ${{ needs.check-version.outputs.bskt_version }}
run: python scripts/update_manifest.py
- name: Install NSIS
shell: pwsh
run: choco install nsis --no-progress -y
- name: Build BsKeyTools installer
shell: pwsh
working-directory: _BsKeyTools
run: makensis Setup_BsKeyTools.nsi
- name: Rename BsKeyTools installer
shell: pwsh
run: |
$v = "${{ needs.check-version.outputs.bskt_version }}"
Move-Item "_BsKeyTools\_BsKeyTools.exe" "_BsKeyTools\BsKeyTools_v$v.exe"
- name: Upload BsKeyTools artifact
uses: actions/upload-artifact@v4
with:
name: bskeytools-installer
path: "_BsKeyTools/BsKeyTools_v${{ needs.check-version.outputs.bskt_version }}.exe"
retention-days: 1
# ── Job 2: 构建 BsCleanVirus 安装包 ───────────────────────────────────
build-bscleanvirus:
needs: check-version
if: needs.check-version.outputs.should_release == 'true'
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
- name: Update NSIS versions
shell: pwsh
env:
RELEASE_VERSION: ${{ needs.check-version.outputs.bskt_version }}
run: python scripts/update_manifest.py
- name: Install NSIS
shell: pwsh
run: choco install nsis --no-progress -y
- name: Build BsCleanVirus installer
shell: pwsh
working-directory: _BsKeyTools
run: makensis Setup_BsCleanVirus.nsi
- name: Rename BsCleanVirus installer
shell: pwsh
run: |
$v = "${{ needs.check-version.outputs.bscv_version }}"
Move-Item "_BsKeyTools\BsCleanVirus_Standalone.exe" "_BsKeyTools\BsCleanVirus_v$v.exe"
- name: Upload BsCleanVirus artifact
uses: actions/upload-artifact@v4
with:
name: bscleanvirus-installer
path: "_BsKeyTools/BsCleanVirus_v${{ needs.check-version.outputs.bscv_version }}.exe"
retention-days: 1
# ── Job 3: 发布到 GitHub + Gitee,更新 version.dat,镜像 ──────────────
release:
needs: [check-version, build-bskeytools, build-bscleanvirus]
if: needs.check-version.outputs.should_release == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: dist/
merge-multiple: true
- name: Create GitHub Release(含 tag,两个安装包挂同一个 release)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BSKT="${{ needs.check-version.outputs.bskt_version }}"
BSCV="${{ needs.check-version.outputs.bscv_version }}"
TAG="${{ needs.check-version.outputs.tag }}"
# gh release create 会原子地创建 tag + release,失败时 tag 不会孤立
gh release create "$TAG" \
--target main \
--title "BsKeyTools v$BSKT" \
--notes "BsKeyTools v$BSKT | BsCleanVirus v$BSCV" \
"dist/BsKeyTools_v$BSKT.exe" \
"dist/BsCleanVirus_v$BSCV.exe"
- name: Create Gitee Release and upload installers
env:
GITEE_TOKEN: ${{ secrets.GITEE_TOKEN }}
run: |
BSKT="${{ needs.check-version.outputs.bskt_version }}"
BSCV="${{ needs.check-version.outputs.bscv_version }}"
TAG="${{ needs.check-version.outputs.tag }}"
python3 - <<PY
import json, os
payload = {
"access_token": os.environ["GITEE_TOKEN"],
"tag_name": os.environ["TAG"],
"name": f"BsKeyTools v{os.environ['BSKT']}",
"body": f"BsKeyTools v{os.environ['BSKT']} | BsCleanVirus v{os.environ['BSCV']}",
"target_commitish": "main",
}
with open("gitee_payload.json", "w", encoding="utf-8") as f:
json.dump(payload, f, ensure_ascii=False)
PY
RESP=$(curl -s -X POST "https://gitee.com/api/v5/repos/acebullet/BsKeyTools/releases" \
-H "Content-Type: application/json" \
--data-binary @gitee_payload.json)
RELEASE_ID=$(echo "$RESP" | python3 -c "
import sys, json
data = json.load(sys.stdin)
if 'id' not in data:
sys.exit(f'Gitee Release 创建失败: {data}')
print(data['id'])
")
upload_to_gitee() {
local label="$1" file="$2"
local resp http_code body
resp=$(curl -s -w "\n%{http_code}" -X POST \
"https://gitee.com/api/v5/repos/acebullet/BsKeyTools/releases/${RELEASE_ID}/attach_files" \
-F "access_token=${GITEE_TOKEN}" \
-F "file=@$file")
http_code=$(echo "$resp" | tail -1)
body=$(echo "$resp" | head -n -1)
if [ "$http_code" != "201" ]; then
echo "❌ $label 上传失败 (HTTP $http_code): $body"
exit 1
fi
echo "✅ $label 上传成功 (HTTP $http_code)"
}
upload_to_gitee "BsKeyTools 安装包" "dist/BsKeyTools_v${BSKT}.exe"
upload_to_gitee "BsCleanVirus 安装包" "dist/BsCleanVirus_v${BSCV}.exe"
echo "✅ Gitee Release v${BSKT} 发布完成(含两个安装包)"
- name: Update version.dat and commit to main
run: |
python3 scripts/update_manifest.py
git add _BsKeyTools/version.dat _BsKeyTools/Setup_BsKeyTools.nsi _BsKeyTools/Setup_BsCleanVirus.nsi
if ! git diff --staged --quiet; then
BSKT="${{ needs.check-version.outputs.bskt_version }}"
git commit -m "chore: update version files → BsKeyTools $BSKT [skip ci]"
git push origin HEAD:main
fi
- name: Mirror to Gitee
uses: wearerequired/git-mirror-action@master
env:
SSH_PRIVATE_KEY: ${{ secrets.GITEE_SSH_PRIVATE_KEY }}
with:
source-repo: "git@github.com:AniBullet/BsKeyTools.git"
destination-repo: "git@gitee.com:acebullet/BsKeyTools.git"