提交ci/cd文件
This commit is contained in:
419
.gitea/README.md
Normal file
419
.gitea/README.md
Normal file
@@ -0,0 +1,419 @@
|
|||||||
|
# 🚀 GUI客户端自动化版本管理系统
|
||||||
|
|
||||||
|
## 📋 概述
|
||||||
|
|
||||||
|
**与后端完全一致的版本管理系统** - 直接连接PostgreSQL数据库
|
||||||
|
|
||||||
|
- ✅ **直接数据库操作** - 与后端使用相同方式(PostgreSQL)
|
||||||
|
- ✅ **完全一致** - 相同的表、相同的字段、相同的逻辑
|
||||||
|
- ✅ **极简设计** - 无需API,配置一次,永久生效
|
||||||
|
- ✅ **全自动** - 提交代码即可,自动版本递增
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 核心特性
|
||||||
|
|
||||||
|
### 存储方式(与后端完全一致)
|
||||||
|
|
||||||
|
```
|
||||||
|
后端Django GUI客户端
|
||||||
|
↓ ↓
|
||||||
|
Django ORM psycopg2
|
||||||
|
↓ ↓
|
||||||
|
└──────────┬──────────────────┘
|
||||||
|
↓
|
||||||
|
PostgreSQL
|
||||||
|
web_versionhistory表
|
||||||
|
```
|
||||||
|
|
||||||
|
| 特性 | 后端 | GUI |
|
||||||
|
|------|------|-----|
|
||||||
|
| **操作方式** | Django ORM | psycopg2(SQL) |
|
||||||
|
| **数据库** | PostgreSQL (8.155.9.53) | **相同** |
|
||||||
|
| **表名** | web_versionhistory | **相同** |
|
||||||
|
| **版本类型** | "Web端" | "水滴智能通讯插件" |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 快速开始(2步)
|
||||||
|
|
||||||
|
### 1️⃣ 安装依赖
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install psycopg2-binary
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2️⃣ 提交代码
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 新增功能(MINOR版本)
|
||||||
|
git commit -m "[minor] 新增拼多多平台支持"
|
||||||
|
|
||||||
|
# 修复Bug(PATCH版本)
|
||||||
|
git commit -m "[patch] 修复京东连接超时"
|
||||||
|
|
||||||
|
# 重大变更(MAJOR版本)
|
||||||
|
git commit -m "[major] 重构WebSocket架构"
|
||||||
|
|
||||||
|
# 推送触发自动版本发布
|
||||||
|
git push origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
**就这么简单!** 🎉
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📖 版本号规则
|
||||||
|
|
||||||
|
采用**语义化版本**(Semantic Versioning):`MAJOR.MINOR.PATCH`
|
||||||
|
|
||||||
|
| 版本类型 | 说明 | 示例 |
|
||||||
|
|---------|------|------|
|
||||||
|
| `MAJOR` | 重大架构变更 | 1.0.0 → 2.0.0 |
|
||||||
|
| `MINOR` | 新增功能 | 1.0.0 → 1.1.0 |
|
||||||
|
| `PATCH` | Bug修复、优化 | 1.0.0 → 1.0.1 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔍 Commit Message 关键词
|
||||||
|
|
||||||
|
### 手动标记(优先级最高)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git commit -m "[major] 重构WebSocket通信架构"
|
||||||
|
git commit -m "[minor] 新增拼多多平台支持"
|
||||||
|
git commit -m "[patch] 修复京东连接超时问题"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 自动识别关键词
|
||||||
|
|
||||||
|
**MAJOR**: `重构`, `refactor`, `架构`, `breaking`
|
||||||
|
**MINOR**: `新增`, `add`, `feature`, `功能`, `实现`
|
||||||
|
**PATCH**: `修复`, `fix`, `bug`, `优化`, `调整`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📁 文件结构
|
||||||
|
|
||||||
|
```
|
||||||
|
shuidrop_gui/
|
||||||
|
├── .gitea/
|
||||||
|
│ ├── workflows/
|
||||||
|
│ │ └── gui-version-release.yml # CI/CD工作流
|
||||||
|
│ ├── scripts/
|
||||||
|
│ │ ├── gui_version_creator.py # ⭐ 核心:版本创建器(直接数据库)
|
||||||
|
│ │ ├── view_version_history.py # 版本历史查看
|
||||||
|
│ │ └── init_version_system.py # 系统初始化
|
||||||
|
│ └── README.md # 本文档
|
||||||
|
├── version_history.json # 版本历史本地备份
|
||||||
|
├── config.py # 包含 APP_VERSION
|
||||||
|
└── VERSION_MANAGEMENT_GUIDE.md # 快速入门指南
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🛠️ 常用命令
|
||||||
|
|
||||||
|
### 查看版本历史
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 查看最近10个版本
|
||||||
|
python .gitea/scripts/view_version_history.py --list
|
||||||
|
|
||||||
|
# 查看最新版本
|
||||||
|
python .gitea/scripts/view_version_history.py --latest
|
||||||
|
|
||||||
|
# 查看特定版本详情
|
||||||
|
python .gitea/scripts/view_version_history.py --detail 1.2.3
|
||||||
|
|
||||||
|
# 导出更新日志
|
||||||
|
python .gitea/scripts/view_version_history.py --export
|
||||||
|
```
|
||||||
|
|
||||||
|
### 本地测试
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 设置数据库连接
|
||||||
|
export DB_HOST=8.155.9.53
|
||||||
|
export DB_PORT=5400
|
||||||
|
export DB_NAME=ai_web
|
||||||
|
export DB_USER=user_emKCAb
|
||||||
|
export DB_PASSWORD=password_ee2iQ3
|
||||||
|
|
||||||
|
# 运行版本创建脚本
|
||||||
|
python .gitea/scripts/gui_version_creator.py
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔄 版本创建流程
|
||||||
|
|
||||||
|
```
|
||||||
|
提交代码
|
||||||
|
↓
|
||||||
|
git push origin main
|
||||||
|
↓
|
||||||
|
Gitea Actions触发
|
||||||
|
↓
|
||||||
|
gui_version_creator.py
|
||||||
|
↓
|
||||||
|
┌────────────────────────────────┐
|
||||||
|
│ 1. 连接PostgreSQL数据库 │
|
||||||
|
│ (8.155.9.53:5400/ai_web) │
|
||||||
|
│ 2. 查询最新版本 │
|
||||||
|
│ SELECT version FROM ... │
|
||||||
|
│ 3. 分析commit message │
|
||||||
|
│ 识别版本类型 │
|
||||||
|
│ 4. 计算新版本号 │
|
||||||
|
│ 1.0.5 → 1.1.0 │
|
||||||
|
│ 5. 插入数据库 │
|
||||||
|
│ INSERT INTO web_versionhistory...│
|
||||||
|
│ 6. 保存本地JSON备份 │
|
||||||
|
│ 7. 更新config.py │
|
||||||
|
│ APP_VERSION = "1.1.0" │
|
||||||
|
└────────────────────────────────┘
|
||||||
|
↓
|
||||||
|
完成!
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 💾 存储策略
|
||||||
|
|
||||||
|
### 主要存储:PostgreSQL数据库
|
||||||
|
|
||||||
|
```sql
|
||||||
|
-- web_versionhistory表(与后端共用)
|
||||||
|
INSERT INTO web_versionhistory (
|
||||||
|
version, -- "1.1.0"
|
||||||
|
type, -- "水滴智能通讯插件"
|
||||||
|
content, -- commit message
|
||||||
|
download_url, -- 下载地址
|
||||||
|
release_time, -- 发布时间
|
||||||
|
is_delete -- FALSE
|
||||||
|
) VALUES (...);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 备份存储:本地JSON
|
||||||
|
|
||||||
|
```json
|
||||||
|
// version_history.json(快速查询/离线使用)
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"version": "1.1.0",
|
||||||
|
"update_type": "minor",
|
||||||
|
"content": "新增拼多多平台支持",
|
||||||
|
"author": "张三",
|
||||||
|
"release_time": "2025-10-09 14:30:00",
|
||||||
|
"stats": {
|
||||||
|
"files_changed": 5,
|
||||||
|
"lines_added": 234,
|
||||||
|
"lines_deleted": 56
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚙️ CI/CD配置
|
||||||
|
|
||||||
|
### 触发条件
|
||||||
|
|
||||||
|
- **分支**: `main`
|
||||||
|
- **事件**: `push`
|
||||||
|
|
||||||
|
### 环境变量(已配置好)
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
env:
|
||||||
|
DB_HOST: 8.155.9.53 # 数据库主机
|
||||||
|
DB_PORT: 5400 # 端口
|
||||||
|
DB_NAME: ai_web # 数据库名
|
||||||
|
DB_USER: user_emKCAb # 用户名
|
||||||
|
DB_PASSWORD: password_ee2iQ3 # 密码
|
||||||
|
```
|
||||||
|
|
||||||
|
**这些配置与后端完全一致!**
|
||||||
|
|
||||||
|
### 执行步骤
|
||||||
|
|
||||||
|
1. 📦 检出代码
|
||||||
|
2. 🐍 设置Python环境
|
||||||
|
3. 📦 安装依赖(psycopg2-binary)
|
||||||
|
4. 🏷️ 创建版本记录(直接数据库操作)
|
||||||
|
5. 📦 自动打包(可选)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 版本历史格式
|
||||||
|
|
||||||
|
### PostgreSQL数据库(主要)
|
||||||
|
|
||||||
|
```sql
|
||||||
|
-- 与后端共享web_versionhistory表
|
||||||
|
SELECT * FROM web_versionhistory
|
||||||
|
WHERE type = '水滴智能通讯插件'
|
||||||
|
ORDER BY release_time DESC;
|
||||||
|
```
|
||||||
|
|
||||||
|
### 本地JSON备份
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"version": "1.1.0",
|
||||||
|
"update_type": "minor",
|
||||||
|
"content": "新增拼多多平台支持",
|
||||||
|
"author": "张三",
|
||||||
|
"commit_hash": "abc123def456...",
|
||||||
|
"release_time": "2025-10-09 14:30:00",
|
||||||
|
"stats": {...}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 常见问题
|
||||||
|
|
||||||
|
### Q: 为什么不用API?
|
||||||
|
|
||||||
|
**A**: 直接数据库操作的优势:
|
||||||
|
- ✅ 与后端存储方式完全一致
|
||||||
|
- ✅ 无需后端开发接口
|
||||||
|
- ✅ 更简单、更可靠
|
||||||
|
- ✅ 减少中间层故障点
|
||||||
|
|
||||||
|
### Q: 数据库连接失败怎么办?
|
||||||
|
|
||||||
|
**A**: 不影响使用!
|
||||||
|
- ✅ 本地JSON备份仍会保存
|
||||||
|
- ✅ config.py仍会更新
|
||||||
|
- ✅ 后续可手动同步数据库
|
||||||
|
|
||||||
|
### Q: 如何跳过版本发布?
|
||||||
|
|
||||||
|
**A**: 在commit message中添加 `[skip ci]`:
|
||||||
|
```bash
|
||||||
|
git commit -m "更新文档 [skip ci]"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Q: 如何验证版本记录?
|
||||||
|
|
||||||
|
**A**:
|
||||||
|
```bash
|
||||||
|
# 方式1: 查看本地备份
|
||||||
|
python .gitea/scripts/view_version_history.py --latest
|
||||||
|
|
||||||
|
# 方式2: 查询数据库
|
||||||
|
psql -h 8.155.9.53 -p 5400 -U user_emKCAb -d ai_web \
|
||||||
|
-c "SELECT * FROM web_versionhistory WHERE type='水滴智能通讯插件' LIMIT 5;"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎓 学习资源
|
||||||
|
|
||||||
|
### 1. 查看快速入门指南
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cat VERSION_MANAGEMENT_GUIDE.md
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 查看实施说明
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cat IMPLEMENTATION_NOTES.md
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 初始化系统
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python .gitea/scripts/init_version_system.py
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📞 完整示例
|
||||||
|
|
||||||
|
### 场景:新增拼多多平台支持
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. 开发功能
|
||||||
|
# 修改: Utils/Pdd/PddUtils.py, config.py 等
|
||||||
|
|
||||||
|
# 2. 提交代码
|
||||||
|
git commit -m "[minor] 新增拼多多平台支持,实现消息收发和自动重连"
|
||||||
|
git push origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
**自动执行**:
|
||||||
|
1. Gitea Actions检测push
|
||||||
|
2. 连接PostgreSQL数据库
|
||||||
|
3. 查询最新版本: `1.0.5`
|
||||||
|
4. 版本递增: `1.0.5` → `1.1.0`
|
||||||
|
5. **插入数据库**: `INSERT INTO web_versionhistory ...`
|
||||||
|
6. 保存本地备份: `version_history.json`
|
||||||
|
7. 更新配置: `APP_VERSION = "1.1.0"`
|
||||||
|
|
||||||
|
**验证结果**:
|
||||||
|
```bash
|
||||||
|
$ python .gitea/scripts/view_version_history.py --latest
|
||||||
|
|
||||||
|
🏷️ 最新版本: v1.1.0
|
||||||
|
📅 发布时间: 2025-10-09 14:30:00
|
||||||
|
👤 发布者: 张三
|
||||||
|
📝 内容: 新增拼多多平台支持,实现消息收发和自动重连
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 💡 核心优势
|
||||||
|
|
||||||
|
### 1. 与后端完全一致
|
||||||
|
- ✅ 相同的数据库(PostgreSQL)
|
||||||
|
- ✅ 相同的表(web_versionhistory)
|
||||||
|
- ✅ 相同的字段结构
|
||||||
|
- ✅ 相同的时间处理逻辑
|
||||||
|
|
||||||
|
### 2. 极简设计
|
||||||
|
- ✅ 只需安装1个依赖(psycopg2-binary)
|
||||||
|
- ✅ 无需后端开发API
|
||||||
|
- ✅ 配置一次,永久生效
|
||||||
|
|
||||||
|
### 3. 全自动
|
||||||
|
- ✅ 提交代码自动触发
|
||||||
|
- ✅ 自动版本递增
|
||||||
|
- ✅ 自动更新配置
|
||||||
|
|
||||||
|
### 4. 双重保障
|
||||||
|
- ✅ PostgreSQL数据库(主要)
|
||||||
|
- ✅ 本地JSON备份(保底)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 下一步行动
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. 安装依赖(必需)
|
||||||
|
pip install psycopg2-binary
|
||||||
|
|
||||||
|
# 2. 初始化系统(推荐)
|
||||||
|
python .gitea/scripts/init_version_system.py
|
||||||
|
|
||||||
|
# 3. 测试提交
|
||||||
|
git commit -m "[patch] 测试版本管理系统"
|
||||||
|
git push origin main
|
||||||
|
|
||||||
|
# 4. 验证结果
|
||||||
|
python .gitea/scripts/view_version_history.py --latest
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**恭喜!** 🎉 你现在拥有了一套**与后端完全一致**的自动化版本管理系统!
|
||||||
|
|
||||||
|
**版本**: 3.0(最终版)
|
||||||
|
**最后更新**: 2025-10-09
|
||||||
|
**核心特点**: 直接PostgreSQL数据库操作,与后端完全一致
|
||||||
469
.gitea/scripts/gui_version_creator.py
Normal file
469
.gitea/scripts/gui_version_creator.py
Normal file
@@ -0,0 +1,469 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
GUI客户端版本创建器
|
||||||
|
⚠️ 仅用于CI/CD环境(Gitea Actions),不打包到用户端GUI
|
||||||
|
|
||||||
|
安全说明:
|
||||||
|
- 本脚本包含数据库凭证,仅在受控的CI/CD环境运行
|
||||||
|
- 用户端GUI不包含此脚本,避免数据库凭证泄漏
|
||||||
|
- 用户端GUI只读取本地version_history.json文件
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
from datetime import datetime
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Dict, Optional
|
||||||
|
|
||||||
|
# 添加项目根目录到路径
|
||||||
|
PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent
|
||||||
|
sys.path.insert(0, str(PROJECT_ROOT))
|
||||||
|
|
||||||
|
# 配置日志
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.INFO,
|
||||||
|
format='%(asctime)s [%(levelname)s] %(message)s'
|
||||||
|
)
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# 数据库配置(与后端一致)
|
||||||
|
# ⚠️ 仅在CI/CD环境使用,不会打包到用户端
|
||||||
|
DB_CONFIG = {
|
||||||
|
'host': os.getenv('DB_HOST', '8.155.9.53'),
|
||||||
|
'port': int(os.getenv('DB_PORT', '5400')),
|
||||||
|
'database': os.getenv('DB_NAME', 'ai_web'),
|
||||||
|
'user': os.getenv('DB_USER', 'user_emKCAb'),
|
||||||
|
'password': os.getenv('DB_PASSWORD', 'password_ee2iQ3')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class GitUtils:
|
||||||
|
"""Git操作工具"""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def run_command(args: list) -> Optional[str]:
|
||||||
|
"""执行Git命令"""
|
||||||
|
import subprocess
|
||||||
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
['git'] + args,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
encoding='utf-8'
|
||||||
|
)
|
||||||
|
return result.stdout.strip() if result.returncode == 0 else None
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Git命令执行失败: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_commit_info(cls) -> Dict[str, str]:
|
||||||
|
"""获取当前提交信息"""
|
||||||
|
return {
|
||||||
|
'message': cls.run_command(['log', '-1', '--pretty=format:%B']) or "自动发布",
|
||||||
|
'hash': cls.run_command(['rev-parse', 'HEAD']) or "",
|
||||||
|
'short_hash': (cls.run_command(['rev-parse', 'HEAD']) or "")[:8],
|
||||||
|
'author': cls.run_command(['log', '-1', '--pretty=format:%an']) or "系统",
|
||||||
|
'commit_date': cls.run_command(['log', '-1', '--pretty=format:%ci']) or "",
|
||||||
|
'branch': cls.run_command(['rev-parse', '--abbrev-ref', 'HEAD']) or "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_commit_stats(cls) -> Dict[str, int]:
|
||||||
|
"""获取提交统计"""
|
||||||
|
stats_output = cls.run_command(['diff', '--numstat', 'HEAD~1', 'HEAD'])
|
||||||
|
if not stats_output:
|
||||||
|
return {'files_changed': 0, 'lines_added': 0, 'lines_deleted': 0}
|
||||||
|
|
||||||
|
files_changed = 0
|
||||||
|
lines_added = 0
|
||||||
|
lines_deleted = 0
|
||||||
|
|
||||||
|
for line in stats_output.split('\n'):
|
||||||
|
if line.strip():
|
||||||
|
parts = line.split('\t')
|
||||||
|
if len(parts) >= 2:
|
||||||
|
try:
|
||||||
|
added = int(parts[0]) if parts[0].isdigit() else 0
|
||||||
|
deleted = int(parts[1]) if parts[1].isdigit() else 0
|
||||||
|
files_changed += 1
|
||||||
|
lines_added += added
|
||||||
|
lines_deleted += deleted
|
||||||
|
except (ValueError, IndexError):
|
||||||
|
continue
|
||||||
|
|
||||||
|
return {
|
||||||
|
'files_changed': files_changed,
|
||||||
|
'lines_added': lines_added,
|
||||||
|
'lines_deleted': lines_deleted
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class DatabaseVersionManager:
|
||||||
|
"""
|
||||||
|
数据库版本管理器
|
||||||
|
⚠️ 安全警告:仅在CI/CD环境使用
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.project_root = PROJECT_ROOT
|
||||||
|
self.version_file = self.project_root / 'version_history.json'
|
||||||
|
self.config_file = self.project_root / 'config.py'
|
||||||
|
self.git_utils = GitUtils()
|
||||||
|
self.db_config = DB_CONFIG
|
||||||
|
self.conn = None
|
||||||
|
|
||||||
|
def connect_db(self):
|
||||||
|
"""连接数据库"""
|
||||||
|
try:
|
||||||
|
import psycopg2
|
||||||
|
self.conn = psycopg2.connect(**self.db_config)
|
||||||
|
logger.info("✅ 数据库连接成功")
|
||||||
|
return True
|
||||||
|
except ImportError:
|
||||||
|
logger.error("❌ psycopg2未安装,请执行: pip install psycopg2-binary")
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"❌ 数据库连接失败: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def close_db(self):
|
||||||
|
"""关闭数据库连接"""
|
||||||
|
if self.conn:
|
||||||
|
self.conn.close()
|
||||||
|
logger.info("数据库连接已关闭")
|
||||||
|
|
||||||
|
def analyze_update_type(self, commit_message: str) -> str:
|
||||||
|
"""分析更新类型"""
|
||||||
|
message = commit_message.lower()
|
||||||
|
|
||||||
|
# 手动标记优先
|
||||||
|
if '[major]' in message or '【major】' in message:
|
||||||
|
return 'major'
|
||||||
|
elif '[minor]' in message or '【minor】' in message:
|
||||||
|
return 'minor'
|
||||||
|
elif '[patch]' in message or '【patch】' in message:
|
||||||
|
return 'patch'
|
||||||
|
|
||||||
|
# 关键词识别
|
||||||
|
major_keywords = ['重构', 'refactor', '架构', 'framework', 'breaking', '大版本', '底层重写']
|
||||||
|
minor_keywords = ['新增', 'add', 'feature', '功能', 'feat:', 'new', '增加', 'implement', '实现']
|
||||||
|
patch_keywords = ['修复', 'fix', 'bug', '优化', 'optimize', 'improve', '调整', 'update', '界面', 'ui', '样式']
|
||||||
|
|
||||||
|
if any(keyword in message for keyword in major_keywords):
|
||||||
|
return 'major'
|
||||||
|
elif any(keyword in message for keyword in minor_keywords):
|
||||||
|
return 'minor'
|
||||||
|
elif any(keyword in message for keyword in patch_keywords):
|
||||||
|
return 'patch'
|
||||||
|
else:
|
||||||
|
return 'patch'
|
||||||
|
|
||||||
|
def get_latest_version_from_db(self) -> str:
|
||||||
|
"""从数据库获取最新版本"""
|
||||||
|
try:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
cursor.execute("""
|
||||||
|
SELECT version FROM web_version_history
|
||||||
|
WHERE type = '水滴智能通讯插件' AND is_delete = FALSE
|
||||||
|
ORDER BY release_time DESC LIMIT 1
|
||||||
|
""")
|
||||||
|
result = cursor.fetchone()
|
||||||
|
cursor.close()
|
||||||
|
|
||||||
|
if result:
|
||||||
|
logger.info(f"📡 从数据库获取最新版本: v{result[0]}")
|
||||||
|
return result[0]
|
||||||
|
return "1.0.0"
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"⚠️ 从数据库获取版本失败: {e},使用默认版本")
|
||||||
|
return "1.0.0"
|
||||||
|
|
||||||
|
def calculate_next_version(self, update_type: str) -> str:
|
||||||
|
"""计算下一个版本号"""
|
||||||
|
current_version = self.get_latest_version_from_db()
|
||||||
|
|
||||||
|
try:
|
||||||
|
parts = current_version.split('.')
|
||||||
|
major = int(parts[0]) if len(parts) > 0 else 1
|
||||||
|
minor = int(parts[1]) if len(parts) > 1 else 0
|
||||||
|
patch = int(parts[2]) if len(parts) > 2 else 0
|
||||||
|
except (ValueError, IndexError):
|
||||||
|
return "1.0.0"
|
||||||
|
|
||||||
|
if update_type == 'major':
|
||||||
|
return f"{major + 1}.0.0"
|
||||||
|
elif update_type == 'minor':
|
||||||
|
return f"{major}.{minor + 1}.0"
|
||||||
|
else: # patch
|
||||||
|
return f"{major}.{minor}.{patch + 1}"
|
||||||
|
|
||||||
|
def check_duplicate_in_db(self, commit_hash: str) -> bool:
|
||||||
|
"""检查数据库中是否已存在该版本"""
|
||||||
|
if not commit_hash:
|
||||||
|
return False
|
||||||
|
|
||||||
|
commit_id = commit_hash[:16]
|
||||||
|
|
||||||
|
try:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
cursor.execute("""
|
||||||
|
SELECT version FROM web_version_history
|
||||||
|
WHERE content LIKE %s AND type = '水滴智能通讯插件'
|
||||||
|
ORDER BY release_time DESC LIMIT 1
|
||||||
|
""", (f'%{commit_id}%',))
|
||||||
|
result = cursor.fetchone()
|
||||||
|
cursor.close()
|
||||||
|
|
||||||
|
if result:
|
||||||
|
logger.info(f"📡 数据库检测到重复版本: v{result[0]}")
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"⚠️ 检查重复版本失败: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def save_to_database(self, version_record: dict) -> bool:
|
||||||
|
"""保存版本记录到数据库(与后端完全一致)"""
|
||||||
|
try:
|
||||||
|
# 时间处理:与后端保持一致
|
||||||
|
from datetime import timezone as dt_timezone
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
beijing_time_naive = datetime.now()
|
||||||
|
beijing_time_as_utc = beijing_time_naive.replace(tzinfo=dt_timezone.utc)
|
||||||
|
|
||||||
|
# 生成UUID
|
||||||
|
record_id = str(uuid.uuid4())
|
||||||
|
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT INTO web_version_history
|
||||||
|
(id, version, type, content, download_url, release_time, is_delete)
|
||||||
|
VALUES (%s, %s, %s, %s, %s, %s, %s)
|
||||||
|
""", (
|
||||||
|
record_id,
|
||||||
|
version_record['version'],
|
||||||
|
'水滴智能通讯插件',
|
||||||
|
version_record['content'],
|
||||||
|
version_record.get('download_url', ''),
|
||||||
|
beijing_time_as_utc,
|
||||||
|
False
|
||||||
|
))
|
||||||
|
|
||||||
|
self.conn.commit()
|
||||||
|
cursor.close()
|
||||||
|
|
||||||
|
logger.info(f"✅ 版本记录已保存到数据库 (ID: {record_id})")
|
||||||
|
return True
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
self.conn.rollback()
|
||||||
|
logger.error(f"❌ 保存到数据库失败: {e}")
|
||||||
|
import traceback
|
||||||
|
logger.error(traceback.format_exc())
|
||||||
|
return False
|
||||||
|
|
||||||
|
def save_local_backup(self, version_record: dict):
|
||||||
|
"""
|
||||||
|
保存本地JSON备份
|
||||||
|
⚠️ 此文件会被打包到用户端GUI,用于版本历史查看
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# 读取现有历史
|
||||||
|
history = []
|
||||||
|
if self.version_file.exists():
|
||||||
|
with open(self.version_file, 'r', encoding='utf-8') as f:
|
||||||
|
history = json.load(f)
|
||||||
|
|
||||||
|
# 添加新记录
|
||||||
|
history.insert(0, version_record)
|
||||||
|
|
||||||
|
# 保留最近50个版本
|
||||||
|
if len(history) > 50:
|
||||||
|
history = history[:50]
|
||||||
|
|
||||||
|
# 保存
|
||||||
|
with open(self.version_file, 'w', encoding='utf-8') as f:
|
||||||
|
json.dump(history, f, ensure_ascii=False, indent=2)
|
||||||
|
|
||||||
|
logger.info(f"✅ 本地备份已保存: {self.version_file}")
|
||||||
|
logger.info(f" 此文件将打包到用户端GUI,用于版本历史查看")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"⚠️ 保存本地备份失败: {e}")
|
||||||
|
|
||||||
|
def update_config_version(self, new_version: str):
|
||||||
|
"""更新config.py中的APP_VERSION"""
|
||||||
|
if not self.config_file.exists():
|
||||||
|
logger.warning(f"配置文件不存在: {self.config_file}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(self.config_file, 'r', encoding='utf-8') as f:
|
||||||
|
content = f.read()
|
||||||
|
|
||||||
|
import re
|
||||||
|
pattern = r'APP_VERSION\s*=\s*["\'][\d.]+["\']'
|
||||||
|
replacement = f'APP_VERSION = "{new_version}"'
|
||||||
|
|
||||||
|
if re.search(pattern, content):
|
||||||
|
new_content = re.sub(pattern, replacement, content)
|
||||||
|
|
||||||
|
with open(self.config_file, 'w', encoding='utf-8') as f:
|
||||||
|
f.write(new_content)
|
||||||
|
|
||||||
|
logger.info(f"✅ 已更新 config.py: APP_VERSION = \"{new_version}\"")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
logger.warning("未找到APP_VERSION配置项")
|
||||||
|
return False
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"更新config.py失败: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def create_version_record(self) -> dict:
|
||||||
|
"""
|
||||||
|
创建版本记录(直接数据库操作)
|
||||||
|
⚠️ 仅在CI/CD环境运行
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
logger.info("=" * 70)
|
||||||
|
logger.info("🚀 开始创建GUI版本记录(CI/CD环境)")
|
||||||
|
logger.info("=" * 70)
|
||||||
|
|
||||||
|
# 1. 连接数据库
|
||||||
|
if not self.connect_db():
|
||||||
|
return {'success': False, 'error': '数据库连接失败'}
|
||||||
|
|
||||||
|
# 2. 获取Git提交信息
|
||||||
|
commit_info = self.git_utils.get_commit_info()
|
||||||
|
logger.info(f"📝 提交消息: {commit_info['message'][:100]}")
|
||||||
|
logger.info(f"👤 提交作者: {commit_info['author']}")
|
||||||
|
logger.info(f"🔖 提交哈希: {commit_info['short_hash']}")
|
||||||
|
|
||||||
|
# 3. 检查是否重复
|
||||||
|
if self.check_duplicate_in_db(commit_info['hash']):
|
||||||
|
logger.info(f"⏭️ 版本记录已存在,跳过创建")
|
||||||
|
self.close_db()
|
||||||
|
return {
|
||||||
|
'success': True,
|
||||||
|
'duplicate': True,
|
||||||
|
'message': '版本记录已存在'
|
||||||
|
}
|
||||||
|
|
||||||
|
# 4. 分析版本信息
|
||||||
|
update_type = self.analyze_update_type(commit_info['message'])
|
||||||
|
next_version = self.calculate_next_version(update_type)
|
||||||
|
|
||||||
|
logger.info(f"📊 更新类型: {update_type.upper()}")
|
||||||
|
logger.info(f"🔢 新版本号: v{next_version}")
|
||||||
|
|
||||||
|
# 5. 获取提交统计
|
||||||
|
stats = self.git_utils.get_commit_stats()
|
||||||
|
logger.info(f"📈 代码统计: {stats['files_changed']} 文件, "
|
||||||
|
f"+{stats['lines_added']}/-{stats['lines_deleted']} 行")
|
||||||
|
|
||||||
|
# 6. 创建版本记录
|
||||||
|
version_record = {
|
||||||
|
'version': next_version,
|
||||||
|
'update_type': update_type,
|
||||||
|
'content': commit_info['message'],
|
||||||
|
'author': commit_info['author'],
|
||||||
|
'commit_hash': commit_info['hash'],
|
||||||
|
'commit_short_hash': commit_info['short_hash'],
|
||||||
|
'branch': commit_info['branch'],
|
||||||
|
'release_time': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
||||||
|
'stats': stats
|
||||||
|
}
|
||||||
|
|
||||||
|
# 7. 保存到数据库(主要存储,CI/CD专用)
|
||||||
|
logger.info("")
|
||||||
|
logger.info("💾 步骤1: 保存到PostgreSQL数据库...")
|
||||||
|
db_success = self.save_to_database(version_record)
|
||||||
|
|
||||||
|
# 8. 保存到本地JSON(用户端可见)
|
||||||
|
logger.info("💾 步骤2: 保存到本地JSON备份(用户端可见)...")
|
||||||
|
self.save_local_backup(version_record)
|
||||||
|
|
||||||
|
# 9. 更新config.py
|
||||||
|
logger.info("💾 步骤3: 更新config.py...")
|
||||||
|
self.update_config_version(next_version)
|
||||||
|
|
||||||
|
# 10. 关闭数据库连接
|
||||||
|
self.close_db()
|
||||||
|
|
||||||
|
# 11. 返回结果
|
||||||
|
logger.info("")
|
||||||
|
logger.info("=" * 70)
|
||||||
|
logger.info("✅ GUI版本记录创建完成")
|
||||||
|
logger.info("=" * 70)
|
||||||
|
logger.info(f"📦 版本号: v{next_version}")
|
||||||
|
logger.info(f"📂 类型: {update_type.upper()}")
|
||||||
|
logger.info(f"👤 作者: {commit_info['author']}")
|
||||||
|
logger.info(f"📈 变更: {stats['files_changed']} 文件, "
|
||||||
|
f"+{stats['lines_added']}/-{stats['lines_deleted']} 行")
|
||||||
|
logger.info(f"💾 数据库: {'✅ 成功' if db_success else '❌ 失败'}")
|
||||||
|
logger.info(f"💾 本地备份: ✅ 成功")
|
||||||
|
logger.info(f"💾 config.py: ✅ 成功")
|
||||||
|
logger.info("=" * 70)
|
||||||
|
logger.info("🔒 安全提示:本脚本仅在CI/CD环境运行,不会打包到用户端")
|
||||||
|
logger.info("=" * 70)
|
||||||
|
|
||||||
|
return {
|
||||||
|
'success': True,
|
||||||
|
'duplicate': False,
|
||||||
|
'version': next_version,
|
||||||
|
'update_type': update_type,
|
||||||
|
'author': commit_info['author'],
|
||||||
|
'content': commit_info['message'],
|
||||||
|
'stats': stats,
|
||||||
|
'db_saved': db_success
|
||||||
|
}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"❌ 创建版本记录失败: {e}")
|
||||||
|
import traceback
|
||||||
|
logger.error(traceback.format_exc())
|
||||||
|
|
||||||
|
if self.conn:
|
||||||
|
self.close_db()
|
||||||
|
|
||||||
|
return {
|
||||||
|
'success': False,
|
||||||
|
'error': str(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""主函数"""
|
||||||
|
try:
|
||||||
|
logger.info("🔒 安全检查:此脚本应仅在CI/CD环境运行")
|
||||||
|
logger.info(" 用户端GUI不应包含此脚本")
|
||||||
|
logger.info("")
|
||||||
|
|
||||||
|
manager = DatabaseVersionManager()
|
||||||
|
result = manager.create_version_record()
|
||||||
|
|
||||||
|
# 输出JSON结果供CI/CD使用
|
||||||
|
print(json.dumps(result, ensure_ascii=False, indent=2))
|
||||||
|
|
||||||
|
# 设置退出码
|
||||||
|
if not result['success']:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"脚本执行失败: {e}")
|
||||||
|
print(json.dumps({
|
||||||
|
'success': False,
|
||||||
|
'error': str(e)
|
||||||
|
}, ensure_ascii=False))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
166
.gitea/scripts/view_version_history.py
Normal file
166
.gitea/scripts/view_version_history.py
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
版本历史查看工具
|
||||||
|
用于查看和管理GUI客户端的版本历史记录
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
import argparse
|
||||||
|
from pathlib import Path
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent
|
||||||
|
|
||||||
|
|
||||||
|
def load_version_history():
|
||||||
|
"""加载版本历史"""
|
||||||
|
version_file = PROJECT_ROOT / 'version_history.json'
|
||||||
|
if not version_file.exists():
|
||||||
|
return []
|
||||||
|
|
||||||
|
with open(version_file, 'r', encoding='utf-8') as f:
|
||||||
|
return json.load(f)
|
||||||
|
|
||||||
|
|
||||||
|
def display_version_list(limit: int = 10):
|
||||||
|
"""显示版本列表"""
|
||||||
|
history = load_version_history()
|
||||||
|
|
||||||
|
if not history:
|
||||||
|
print("📭 暂无版本历史记录")
|
||||||
|
return
|
||||||
|
|
||||||
|
print("=" * 80)
|
||||||
|
print(f"📦 GUI客户端版本历史 (共 {len(history)} 个版本)")
|
||||||
|
print("=" * 80)
|
||||||
|
|
||||||
|
for i, record in enumerate(history[:limit], 1):
|
||||||
|
version = record.get('version', 'Unknown')
|
||||||
|
update_type = record.get('update_type', 'unknown').upper()
|
||||||
|
author = record.get('author', 'Unknown')
|
||||||
|
release_time = record.get('release_time', 'Unknown')
|
||||||
|
content = record.get('content', '')[:60]
|
||||||
|
|
||||||
|
print(f"\n{i}. v{version} [{update_type}]")
|
||||||
|
print(f" 👤 作者: {author}")
|
||||||
|
print(f" 📅 时间: {release_time}")
|
||||||
|
print(f" 📝 内容: {content}{'...' if len(record.get('content', '')) > 60 else ''}")
|
||||||
|
|
||||||
|
stats = record.get('stats', {})
|
||||||
|
if stats:
|
||||||
|
print(f" 📊 变更: {stats.get('files_changed', 0)} 文件, "
|
||||||
|
f"+{stats.get('lines_added', 0)}/-{stats.get('lines_deleted', 0)} 行")
|
||||||
|
|
||||||
|
if len(history) > limit:
|
||||||
|
print(f"\n... 还有 {len(history) - limit} 个历史版本")
|
||||||
|
|
||||||
|
print("\n" + "=" * 80)
|
||||||
|
|
||||||
|
|
||||||
|
def display_version_detail(version: str):
|
||||||
|
"""显示特定版本的详细信息"""
|
||||||
|
history = load_version_history()
|
||||||
|
|
||||||
|
for record in history:
|
||||||
|
if record.get('version') == version:
|
||||||
|
print("=" * 80)
|
||||||
|
print(f"📦 GUI客户端版本详情: v{version}")
|
||||||
|
print("=" * 80)
|
||||||
|
print(f"版本号: v{record.get('version')}")
|
||||||
|
print(f"更新类型: {record.get('update_type', 'unknown').upper()}")
|
||||||
|
print(f"作者: {record.get('author')}")
|
||||||
|
print(f"发布时间: {record.get('release_time')}")
|
||||||
|
print(f"分支: {record.get('branch')}")
|
||||||
|
print(f"提交哈希: {record.get('commit_short_hash')}")
|
||||||
|
print(f"\n更新内容:\n{record.get('content')}")
|
||||||
|
|
||||||
|
stats = record.get('stats', {})
|
||||||
|
if stats:
|
||||||
|
print(f"\n提交统计:")
|
||||||
|
print(f" 文件变更: {stats.get('files_changed', 0)}")
|
||||||
|
print(f" 新增行数: +{stats.get('lines_added', 0)}")
|
||||||
|
print(f" 删除行数: -{stats.get('lines_deleted', 0)}")
|
||||||
|
|
||||||
|
print("=" * 80)
|
||||||
|
return
|
||||||
|
|
||||||
|
print(f"❌ 未找到版本: v{version}")
|
||||||
|
|
||||||
|
|
||||||
|
def display_latest_version():
|
||||||
|
"""显示最新版本"""
|
||||||
|
history = load_version_history()
|
||||||
|
if not history:
|
||||||
|
print("📭 暂无版本历史记录")
|
||||||
|
return
|
||||||
|
|
||||||
|
latest = history[0]
|
||||||
|
print(f"🏷️ 最新版本: v{latest.get('version')}")
|
||||||
|
print(f"📅 发布时间: {latest.get('release_time')}")
|
||||||
|
print(f"👤 发布者: {latest.get('author')}")
|
||||||
|
|
||||||
|
|
||||||
|
def export_changelog(output_file: str = None):
|
||||||
|
"""导出更新日志(Markdown格式)"""
|
||||||
|
history = load_version_history()
|
||||||
|
|
||||||
|
if not history:
|
||||||
|
print("📭 暂无版本历史记录")
|
||||||
|
return
|
||||||
|
|
||||||
|
output_file = output_file or (PROJECT_ROOT / 'CHANGELOG.md')
|
||||||
|
|
||||||
|
with open(output_file, 'w', encoding='utf-8') as f:
|
||||||
|
f.write("# 水滴GUI客户端更新日志\n\n")
|
||||||
|
f.write(f"*自动生成时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}*\n\n")
|
||||||
|
|
||||||
|
for record in history:
|
||||||
|
version = record.get('version')
|
||||||
|
update_type = record.get('update_type', 'patch').upper()
|
||||||
|
release_time = record.get('release_time')
|
||||||
|
author = record.get('author')
|
||||||
|
content = record.get('content', '')
|
||||||
|
|
||||||
|
f.write(f"## v{version} - {release_time}\n\n")
|
||||||
|
f.write(f"**类型**: {update_type} | **作者**: {author}\n\n")
|
||||||
|
f.write(f"{content}\n\n")
|
||||||
|
|
||||||
|
stats = record.get('stats', {})
|
||||||
|
if stats:
|
||||||
|
f.write(f"*变更统计: {stats.get('files_changed', 0)} 文件, "
|
||||||
|
f"+{stats.get('lines_added', 0)}/-{stats.get('lines_deleted', 0)} 行*\n\n")
|
||||||
|
|
||||||
|
f.write("---\n\n")
|
||||||
|
|
||||||
|
print(f"✅ 更新日志已导出到: {output_file}")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""主函数"""
|
||||||
|
parser = argparse.ArgumentParser(description='GUI版本历史查看工具')
|
||||||
|
parser.add_argument('--list', '-l', action='store_true', help='显示版本列表')
|
||||||
|
parser.add_argument('--limit', type=int, default=10, help='显示数量限制(默认10)')
|
||||||
|
parser.add_argument('--detail', '-d', type=str, help='查看特定版本详情')
|
||||||
|
parser.add_argument('--latest', action='store_true', help='显示最新版本')
|
||||||
|
parser.add_argument('--export', '-e', action='store_true', help='导出更新日志')
|
||||||
|
parser.add_argument('--output', '-o', type=str, help='导出文件路径')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.latest:
|
||||||
|
display_latest_version()
|
||||||
|
elif args.detail:
|
||||||
|
display_version_detail(args.detail)
|
||||||
|
elif args.export:
|
||||||
|
export_changelog(args.output)
|
||||||
|
elif args.list or not any(vars(args).values()):
|
||||||
|
display_version_list(args.limit)
|
||||||
|
else:
|
||||||
|
parser.print_help()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
||||||
178
.gitea/workflows/gui-version-release.yml
Normal file
178
.gitea/workflows/gui-version-release.yml
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
name: GUI Version Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
gui-version-release:
|
||||||
|
runs-on: windows
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: E:\shuidrop_gui
|
||||||
|
|
||||||
|
steps:
|
||||||
|
# Step 1: Clone repository manually
|
||||||
|
- name: Clone repository
|
||||||
|
shell: powershell
|
||||||
|
run: |
|
||||||
|
Write-Host "Cloning repository..."
|
||||||
|
|
||||||
|
# Change to workspace directory
|
||||||
|
cd E:\shuidrop_gui
|
||||||
|
|
||||||
|
Write-Host "Current directory: $(Get-Location)"
|
||||||
|
Write-Host "Git status:"
|
||||||
|
git status
|
||||||
|
|
||||||
|
Write-Host "Fetching latest changes..."
|
||||||
|
git fetch origin
|
||||||
|
git reset --hard origin/master
|
||||||
|
|
||||||
|
Write-Host "Repository ready"
|
||||||
|
|
||||||
|
# Step 2: Check Python environment
|
||||||
|
- name: Check Python environment
|
||||||
|
shell: powershell
|
||||||
|
run: |
|
||||||
|
Write-Host "Python version:"
|
||||||
|
try {
|
||||||
|
python --version
|
||||||
|
} catch {
|
||||||
|
Write-Host "Python not installed"
|
||||||
|
}
|
||||||
|
Write-Host "Pip version:"
|
||||||
|
try {
|
||||||
|
pip --version
|
||||||
|
} catch {
|
||||||
|
Write-Host "Pip not installed"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Step 3: Install dependencies
|
||||||
|
- name: Install dependencies
|
||||||
|
shell: powershell
|
||||||
|
run: |
|
||||||
|
Write-Host "Installing psycopg2-binary..."
|
||||||
|
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
Write-Host "Failed to upgrade pip"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
pip install psycopg2-binary
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
Write-Host "Failed to install psycopg2-binary"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Dependencies installed successfully"
|
||||||
|
|
||||||
|
# Step 4: Create GUI version record
|
||||||
|
- name: Create version record
|
||||||
|
id: create_version
|
||||||
|
shell: powershell
|
||||||
|
run: |
|
||||||
|
Write-Host "Starting GUI version release process..."
|
||||||
|
Write-Host "Commit hash: ${{ github.sha }}"
|
||||||
|
Write-Host "Commit author: ${{ github.actor }}"
|
||||||
|
Write-Host "Branch: ${{ github.ref_name }}"
|
||||||
|
|
||||||
|
# Retry mechanism: maximum 3 attempts
|
||||||
|
$SUCCESS = $false
|
||||||
|
for ($i = 1; $i -le 3; $i++) {
|
||||||
|
Write-Host "Attempt $i to create version record..."
|
||||||
|
|
||||||
|
python .gitea/scripts/gui_version_creator.py
|
||||||
|
if ($LASTEXITCODE -eq 0) {
|
||||||
|
Write-Host "Version record created successfully"
|
||||||
|
$SUCCESS = $true
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
Write-Host "Attempt $i failed"
|
||||||
|
if ($i -eq 3) {
|
||||||
|
Write-Host "All 3 attempts failed"
|
||||||
|
} else {
|
||||||
|
Write-Host "Waiting 5 seconds before retry..."
|
||||||
|
Start-Sleep -Seconds 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $SUCCESS) {
|
||||||
|
Write-Host "Version creation failed"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Verify version was updated
|
||||||
|
if (Test-Path "config.py") {
|
||||||
|
$configContent = Get-Content "config.py" -Raw
|
||||||
|
if ($configContent -match 'APP_VERSION\s*=\s*"([\d.]+)"') {
|
||||||
|
$VERSION = $matches[1]
|
||||||
|
Write-Host "Version updated successfully: $VERSION"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
env:
|
||||||
|
DB_HOST: 8.155.9.53
|
||||||
|
DB_NAME: ai_web
|
||||||
|
DB_USER: user_emKCAb
|
||||||
|
DB_PASSWORD: password_ee2iQ3
|
||||||
|
DB_PORT: 5400
|
||||||
|
|
||||||
|
# Step 5: Commit changes back to repository
|
||||||
|
- name: Commit version changes
|
||||||
|
if: success()
|
||||||
|
shell: powershell
|
||||||
|
run: |
|
||||||
|
Write-Host "Committing version changes..."
|
||||||
|
|
||||||
|
# Read version from config.py
|
||||||
|
$VERSION = ""
|
||||||
|
if (Test-Path "config.py") {
|
||||||
|
$configContent = Get-Content "config.py" -Raw
|
||||||
|
if ($configContent -match 'APP_VERSION\s*=\s*"([\d.]+)"') {
|
||||||
|
$VERSION = $matches[1]
|
||||||
|
Write-Host "New version: $VERSION"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
git config user.name "Gitea Actions"
|
||||||
|
git config user.email "actions@gitea.local"
|
||||||
|
|
||||||
|
git add config.py
|
||||||
|
git add version_history.json
|
||||||
|
|
||||||
|
$hasChanges = git diff --staged --quiet
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
git commit -m "[skip ci] Update version to $VERSION"
|
||||||
|
git push origin master
|
||||||
|
Write-Host "Version changes committed and pushed"
|
||||||
|
} else {
|
||||||
|
Write-Host "No changes to commit"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Step 6: Display summary
|
||||||
|
- name: Display summary
|
||||||
|
if: always()
|
||||||
|
shell: powershell
|
||||||
|
run: |
|
||||||
|
# Read version from config.py
|
||||||
|
$VERSION = "Unknown"
|
||||||
|
if (Test-Path "config.py") {
|
||||||
|
$configContent = Get-Content "config.py" -Raw
|
||||||
|
if ($configContent -match 'APP_VERSION\s*=\s*"([\d.]+)"') {
|
||||||
|
$VERSION = $matches[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "=========================================="
|
||||||
|
Write-Host "GUI Version Release Summary"
|
||||||
|
Write-Host "=========================================="
|
||||||
|
Write-Host "Author: ${{ github.actor }}"
|
||||||
|
Write-Host "Branch: ${{ github.ref_name }}"
|
||||||
|
Write-Host "Version: $VERSION"
|
||||||
|
Write-Host "Time: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
|
||||||
|
Write-Host "Commit: ${{ github.sha }}"
|
||||||
|
Write-Host "=========================================="
|
||||||
|
|
||||||
Reference in New Issue
Block a user