feat: 增加环境预检查与多根目录支持,调整构建操作布局
This commit is contained in:
1 parent
2cb70beb69
commit
7984785610
17 files changed
+852
-97
No files matched your search
+27
-17
@@ -76,6 +76,7 @@ type Server struct {
|
||||
projects map[string]*Project
|
||||
builds map[string]*Build
|
||||
workspaceRoot string
|
||||
workspaceRoots []string
|
||||
environmentFile string
|
||||
}
|
||||
|
||||
@@ -165,7 +166,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
parts := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
|
||||
fail := func(e error) { http.Error(w, e.Error(), 400) }
|
||||
if r.URL.Path == "/api/v1/health" {
|
||||
jsonOut(w, map[string]any{"version": "0.4.1", "textComparison": true, "jdkSelection": true, "workspaceSelection": true, "os": runtime.GOOS, "sync": "http-manifest", "recovery": true})
|
||||
jsonOut(w, map[string]any{"version": "0.4.6", "preflight": true, "textComparison": true, "jdkSelection": true, "workspaceSelection": true, "os": runtime.GOOS, "sync": "http-manifest", "recovery": true})
|
||||
return
|
||||
}
|
||||
if r.URL.Path == "/api/v1/environment" && r.Method == "GET" {
|
||||
@@ -209,7 +210,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
if pr.WorkspacePath != "" {
|
||||
if pr.WorkspacePath != "" && !(parts[4] == "builds" && r.Method == "GET") {
|
||||
if _, e := s.validateWorkspace(pr.WorkspacePath); e != nil {
|
||||
fail(e)
|
||||
return
|
||||
@@ -536,6 +537,22 @@ func (s *Server) run(b *Build) {
|
||||
_ = s.persistBuild(b)
|
||||
s.mu.Unlock()
|
||||
work := s.work(b.Project)
|
||||
cfg, configErr := s.buildEnvironment()
|
||||
if configErr != nil {
|
||||
s.finishFailed(b, configErr)
|
||||
return
|
||||
}
|
||||
if b.JavaHome != "" {
|
||||
cfg.JavaHome = b.JavaHome
|
||||
}
|
||||
report := s.preflight(work, cfg)
|
||||
for _, item := range report.Items {
|
||||
buildWriter{s, b}.Write([]byte(fmt.Sprintf("环境检查 [%s] %s:%s [%s]\n", item.Status, item.Name, item.Message, item.Path)))
|
||||
}
|
||||
if checkErr := report.failure(); checkErr != nil {
|
||||
s.finishFailed(b, checkErr)
|
||||
return
|
||||
}
|
||||
// Remove old APKs only. Retain compilation caches and all other Gradle outputs.
|
||||
err := noLinks(work)
|
||||
if err == nil {
|
||||
@@ -550,14 +567,6 @@ func (s *Server) run(b *Build) {
|
||||
})
|
||||
}
|
||||
if err == nil {
|
||||
cfg, configErr := s.buildEnvironment()
|
||||
if configErr != nil {
|
||||
s.finishFailed(b, configErr)
|
||||
return
|
||||
}
|
||||
if b.JavaHome != "" {
|
||||
cfg.JavaHome = b.JavaHome
|
||||
}
|
||||
cmd, info, prepErr := s.prepareCommand(work, b.Task, cfg)
|
||||
if prepErr != nil {
|
||||
s.finishFailed(b, prepErr)
|
||||
@@ -655,7 +664,8 @@ func main() {
|
||||
key := flag.String("tls-key", "", "PEM private key path")
|
||||
initHost := flag.String("init-tls-host", "", "generate a local certificate for this IP/hostname and exit")
|
||||
tlsDir := flag.String("tls-dir", "./tls", "certificate output directory")
|
||||
workspaceRoot := flag.String("workspace-root", "", "administrator allowed root for existing project folders; defaults to data/projects")
|
||||
var workspaceRoots workspaceRootFlags
|
||||
flag.Var(&workspaceRoots, "workspace-root", "allowed existing-project root; repeat for multiple roots; defaults to data/projects")
|
||||
environmentFile := flag.String("environment-file", "", "trusted build environment JSON; reloaded for each build")
|
||||
flag.Parse()
|
||||
if *initHost != "" {
|
||||
@@ -684,13 +694,13 @@ func main() {
|
||||
}
|
||||
s := &Server{root: abs, token: token, tasks: map[string]bool{}, projects: map[string]*Project{}, builds: map[string]*Build{}}
|
||||
s.environmentFile = *environmentFile
|
||||
s.workspaceRoot = *workspaceRoot
|
||||
if s.workspaceRoot == "" {
|
||||
s.workspaceRoots = []string(workspaceRoots)
|
||||
if len(s.workspaceRoots) > 0 {
|
||||
s.workspaceRoot = s.workspaceRoots[0]
|
||||
} else {
|
||||
s.workspaceRoot = filepath.Join(abs, "projects")
|
||||
}
|
||||
if s.workspaceRoot, e = filepath.Abs(s.workspaceRoot); e != nil {
|
||||
log.Fatal(e)
|
||||
}
|
||||
|
||||
for _, t := range strings.Split(*tasks, ",") {
|
||||
if !safeTask.MatchString(t) {
|
||||
log.Fatal("invalid task")
|
||||
@@ -710,7 +720,7 @@ func main() {
|
||||
if json.Unmarshal(data, &p) == nil {
|
||||
if p.WorkspacePath != "" {
|
||||
if _, e := s.validateWorkspace(p.WorkspacePath); e != nil {
|
||||
log.Fatalf("workspace %s: %v", entry.Name(), e)
|
||||
log.Printf("workspace %s unavailable under current root (history retained): %v", entry.Name(), e)
|
||||
}
|
||||
}
|
||||
s.projects[entry.Name()] = &p
|
||||
|
||||
Reference in new issue
Block a user