package main import ( "fmt" "log" "os" "path/filepath" "strings" "github.com/gin-gonic/gin" ) func main() { r := gin.Default() // POST /build -> run npm build + increment .build r.POST("/build", func(c *gin.Context) { host, err := os.Hostname() if err != nil { c.JSON(500, gin.H{"error": "Could not retrieve hostname"}) return } log.Println(host) if strings.Contains(host, "VMS") || strings.Contains(host, "vms") { c.JSON(500, gin.H{"error": "You are not allowed to run the build on a production server"}) return } // run the old builder first this will be removed once we switch fully over here and shut down the old version if err := runNpmV2Build(); err != nil { c.JSON(500, gin.H{"error": "npm build failed on lstV2", "details": err.Error()}) return } // the new builder if err := runNpmBuild(); err != nil { c.JSON(500, gin.H{"error": "npm build failed", "details": err.Error()}) return } buildNum, err := bumpBuild() if err != nil { c.JSON(500, gin.H{"error": "failed updating build counter", "details": err.Error()}) return } // run the zip includes, _ := loadIncludePatterns("../.include") // Name the archive after build number if available data, _ := os.ReadFile("../.build") buildNum1 := strings.TrimSpace(string(data)) if buildNum1 == "" { buildNum1 = "0" } buildDir, err := getBuildDir() if err != nil { log.Fatal(err) } //buildDir, err := ensureBuildDir("../builds") if err != nil { c.JSON(500, gin.H{"error": err.Error()}) return } zipPath := filepath.Join(buildDir, fmt.Sprintf("release-%d.zip", buildNum)) if err := zipProject("..", zipPath, includes); err != nil { c.JSON(500, gin.H{"error": err.Error()}) return } c.JSON(200, gin.H{ "message": "build successful", "build": buildNum, }) }) // GET /version -> read current build version r.GET("/version", func(c *gin.Context) { data, err := os.ReadFile("../.build") if err != nil { c.JSON(404, gin.H{"error": "no build info"}) return } c.JSON(200, gin.H{"build": strings.TrimSpace(string(data))}) }) r.Run(":8080") // serve API }