feat: 完善远程构建恢复、工程同步与变体选择

增加持久化构建记录、历史 APK 恢复、断点下载、Gradle 缓存复用、系统代理与按工程选择服务端 JDK。

支持已有工程目录、Git 状态检查、原生忽略规则和文本换行等价比较,修复干净检出与历史同步快照不一致时的误拦截。

优化插件设备可选构建、侧栏滚动、左右日志布局、时间显示和构建变体快速选择,并补充部署与协议文档。

验证:17 项 Go 测试、22 项插件测试及 HTTP/HTTPS 两条端到端测试通过;Linux/macOS 服务端交叉编译通过。
This commit is contained in:
tongtong committed 2026-11-25 02:10:52 +08:00
1 parent 2203afde3c
commit 2cb70beb69
44 files changed
+3310 -236

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
package main
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
"time"
)
type Progress struct {
Phase string `json:"phase"`
Message string `json:"message"`
Path string `json:"path"`
Current int64 `json:"current"`
Total int64 `json:"total"`
Percent int `json:"percent"`
}
func (s *Server) persistBuild(b *Build) error {
dir := filepath.Join(s.root, "artifacts", b.ID)
if e := os.MkdirAll(dir, 0700); e != nil {
return e
}
data, e := json.Marshal(b)
if e != nil {
return e
}
target := filepath.Join(dir, "build.json")
if e = os.WriteFile(target+".tmp", data, 0600); e != nil {
return e
}
if e = os.Rename(target+".tmp", target); e == nil {
b.lastPersist = time.Now()
}
return e
}
func (s *Server) finishFailed(b *Build, e error) {
s.mu.Lock()
defer s.mu.Unlock()
b.Status = "failed"
if b.cancelled {
b.Status = "cancelled"
}
b.Logs = append(b.Logs, e.Error())
b.Progress.Phase = "finished"
s.projects[b.Project].Busy = false
_ = s.persistBuild(b)
os.Remove(filepath.Join(s.root, "projects", b.Project, "active-build"))
}
func (s *Server) recoverBuilds() {
for p, pr := range s.projects {
pr.Busy = false
marker, e := os.ReadFile(filepath.Join(s.root, "projects", p, "active-build"))
if e == nil {
pr.Busy = true
bid := strings.TrimSpace(string(marker))
if safeID.MatchString(bid) && s.builds[bid] == nil {
s.builds[bid] = &Build{ID: bid, Project: p, Revision: pr.Revision, Status: "running", Logs: []string{}, Artifacts: []Artifact{}}
}
}
}
for _, b := range s.builds {
if b.Status == "running" || b.Status == "queued" {
b.Status = "interrupted"
b.Progress.Phase = "interrupted"
b.Logs = append(b.Logs, "服务曾重启,构建已中断。若工作区仍锁定,管理员需确认残留 Gradle 进程已停止,再移除 active-build 并重启服务。")
if e := s.persistBuild(b); e != nil {
fmt.Println("build recovery persistence failed:", e)
}
}
}
}