github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/cli/build.go (about) 1 package cli 2 3 import ( 4 "os" 5 6 "github.com/tilt-dev/tilt/pkg/model" 7 ) 8 9 // Version for Go-compiled builds that didn't go through goreleaser. 10 // 11 // This is mostly here to make sure that people that use `go get` don't 12 // have a completely broken experience. It controls: 13 // 14 // 1) The version data you see when you run `tilt version` 15 // 2) The web JS you download when you're in web-mode prod. 16 // 17 // For distributed binaries, version is automatically baked 18 // into the binary with goreleaser. If this doesn't get updated 19 // on every release, it's often not that big a deal. 20 const devVersion = "0.33.14" 21 22 var commitSHA string 23 var globalTiltInfo model.TiltBuild 24 25 func SetTiltInfo(info model.TiltBuild) { 26 globalTiltInfo = info 27 } 28 29 func tiltInfo() model.TiltBuild { 30 info := globalTiltInfo 31 if info.Empty() { 32 return defaultTiltInfo() 33 } 34 return info 35 } 36 37 func buildStamp() string { 38 return tiltInfo().HumanBuildStamp() 39 } 40 41 // Returns a build datestamp in the format 2018-08-30 42 func defaultBuildDate() string { 43 // TODO(nick): Add a mechanism to encode the datestamp in the binary with 44 // ldflags. This currently only works if you are building your own 45 // binaries. It won't work once we're distributing pre-built binaries. 46 path, err := os.Executable() 47 if err != nil { 48 return "[unknown]" 49 } 50 51 info, err := os.Stat(path) 52 if err != nil { 53 return "[unknown]" 54 } 55 56 modTime := info.ModTime() 57 return modTime.Format("2006-01-02") 58 } 59 60 // Returns a build datestamp in the format 2018-08-30 61 func defaultTiltInfo() model.TiltBuild { 62 return model.TiltBuild{ 63 Date: defaultBuildDate(), 64 Version: devVersion, 65 CommitSHA: commitSHA, 66 Dev: true, 67 } 68 } 69 70 func provideTiltInfo() model.TiltBuild { 71 return tiltInfo() 72 } 73 74 func provideWebVersion(b model.TiltBuild) model.WebVersion { 75 return b.WebVersion() 76 }