实现更新版本管理

This commit is contained in:
Gitea Actions Bot
2025-10-11 15:46:39 +08:00
parent 95534f5304
commit 8ecec1edbe
6 changed files with 264 additions and 167 deletions

View File

@@ -398,13 +398,10 @@ class DatabaseVersionManager:
f"+{stats['lines_added']}/-{stats['lines_deleted']}")
# 6. 创建版本记录
# 生成下载地址(标准格式:指向实际安装包文件
# 生成下载地址(KS3对象存储 - 广州节点
installer_filename = f"ShuiDi_AI_Assistant_Setup_v{next_version}.exe"
download_url = f"https://shuidrop.com/download/gui/{installer_filename}"
# 完整示例: https://shuidrop.com/download/gui/ShuiDi_AI_Assistant_Setup_v1.4.12.exe
# 临时测试可以改为:
# download_url = "https://www.baidu.com"
download_url = f"https://ks3-cn-guangzhou.ksyuncs.com/shuidrop-chat-server/installers/{installer_filename}"
# 完整示例: https://ks3-cn-guangzhou.ksyuncs.com/shuidrop-chat-server/installers/ShuiDi_AI_Assistant_Setup_v1.5.0.exe
version_record = {
'version': next_version,

View File

@@ -0,0 +1,141 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Upload GUI installer to KS3 object storage
- Target directory: installers/
- Set proper HTTP headers for browser download
"""
import os
import sys
import logging
from pathlib import Path
from ks3.connection import Connection
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s [%(levelname)s] %(message)s'
)
logger = logging.getLogger(__name__)
# KS3 Configuration (using actual project config)
KS3_ACCESS_KEY = 'AKLT0Ey7Nq7ZSXykki0X0RGG'
KS3_SECRET_KEY = 'OONxkt9wwJa1FIco21vCbirs1HB6AGzDWdRyV0k2'
KS3_ENDPOINT = 'ks3-cn-guangzhou.ksyuncs.com' # Guangzhou region
KS3_BUCKET = 'shuidrop-chat-server'
KS3_IS_SECURE = True # Use HTTPS
KS3_PREFIX = 'installers/'
def get_ks3_connection():
"""Get KS3 connection"""
try:
connection = Connection(
KS3_ACCESS_KEY,
KS3_SECRET_KEY,
host=KS3_ENDPOINT,
is_secure=KS3_IS_SECURE,
timeout=300,
)
logger.info(f"KS3 connection established: {KS3_ENDPOINT}")
return connection
except Exception as e:
logger.error(f"KS3 connection failed: {e}")
return None
def find_latest_installer():
"""Find the latest generated installer"""
project_root = Path(__file__).parent.parent.parent
installer_dir = project_root / 'installer' / 'output'
if not installer_dir.exists():
logger.error(f"Installer directory not found: {installer_dir}")
return None
installers = list(installer_dir.glob('*.exe'))
if not installers:
logger.error(f"No installer files found in: {installer_dir}")
return None
latest_installer = max(installers, key=lambda p: p.stat().st_mtime)
file_size_mb = latest_installer.stat().st_size / 1024 / 1024
logger.info(f"Found installer: {latest_installer.name}")
logger.info(f"File size: {file_size_mb:.2f} MB")
return latest_installer
def upload_installer(connection, installer_path):
"""Upload installer to KS3"""
try:
bucket = connection.get_bucket(KS3_BUCKET)
ks3_key = f"{KS3_PREFIX}{installer_path.name}"
logger.info(f"Starting upload to KS3...")
logger.info(f"Target path: {ks3_key}")
key = bucket.new_key(ks3_key)
with open(installer_path, 'rb') as f:
key.set_contents_from_file(
f,
headers={
'Content-Type': 'application/octet-stream',
'Content-Disposition': f'attachment; filename="{installer_path.name}"',
'Cache-Control': 'public, max-age=3600',
'x-kss-storage-class': 'STANDARD'
}
)
key.set_acl('public-read')
# Generate download URL (using HTTPS)
protocol = 'https' if KS3_IS_SECURE else 'http'
download_url = f"{protocol}://{KS3_ENDPOINT}/{KS3_BUCKET}/{ks3_key}"
logger.info(f"Upload successful!")
logger.info(f"Download URL: {download_url}")
return download_url
except Exception as e:
logger.error(f"Upload failed: {e}")
import traceback
logger.error(traceback.format_exc())
return None
def main():
"""Main function"""
logger.info("=" * 70)
logger.info("Starting GUI installer upload to KS3")
logger.info(f"KS3 Endpoint: {KS3_ENDPOINT}")
logger.info(f"Bucket: {KS3_BUCKET}")
logger.info(f"Target directory: {KS3_PREFIX}")
logger.info("=" * 70)
installer_path = find_latest_installer()
if not installer_path:
return 1
connection = get_ks3_connection()
if not connection:
return 1
download_url = upload_installer(connection, installer_path)
if not download_url:
return 1
logger.info("=" * 70)
logger.info("Task completed successfully!")
logger.info(f"Installer: {installer_path.name}")
logger.info(f"Download URL: {download_url}")
logger.info("=" * 70)
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@@ -131,6 +131,75 @@ jobs:
DB_PASSWORD: password_ee2iQ3
DB_PORT: 5400
# Step 4.5: Build production executable
- name: Build production executable
if: success()
shell: powershell
run: |
Write-Host "==========================================";
Write-Host "Step 4.5: Build production executable";
Write-Host "==========================================";
python build_production.py;
if ($LASTEXITCODE -ne 0) {
Write-Host "Build failed";
exit 1;
}
Write-Host "Production build completed successfully";
Write-Host "";
# Step 4.6: Build NSIS installer
- name: Build NSIS installer
if: success()
shell: powershell
run: |
Write-Host "==========================================";
Write-Host "Step 4.6: Build NSIS installer";
Write-Host "==========================================";
cd installer;
python build_installer.py;
if ($LASTEXITCODE -ne 0) {
Write-Host "Installer build failed";
exit 1;
}
$installers = Get-ChildItem -Path "output" -Filter "*.exe" -ErrorAction SilentlyContinue;
if (-not $installers -or $installers.Count -eq 0) {
Write-Host "No installer file found";
exit 1;
}
$installerName = $installers[0].Name;
$installerSize = [math]::Round($installers[0].Length / 1MB, 2);
Write-Host "Installer built successfully";
Write-Host " Filename: $installerName";
Write-Host " Size: $installerSize MB";
Write-Host "";
# Step 4.7: Upload installer to KS3
- name: Upload installer to KS3
if: success()
shell: powershell
run: |
Write-Host "==========================================";
Write-Host "Step 4.7: Upload installer to KS3";
Write-Host "==========================================";
pip install ks3 2>$null;
python .gitea/scripts/upload_installer_to_ks3.py;
if ($LASTEXITCODE -ne 0) {
Write-Host "KS3 upload failed, but version release continues";
Write-Host " You can manually upload the installer later";
} else {
Write-Host "Installer uploaded to KS3 successfully";
}
Write-Host "";
# Step 5: Commit version changes
- name: Commit version changes
if: success()