diff --git a/.gitignore b/.gitignore index 294111ef25..9feebfa2b6 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,7 @@ *.generated.yaml .synclet-dev-image-tag -.#* \ No newline at end of file +.#* + +# goreleaser binaries +dist \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000000..4a6d54fe29 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,23 @@ +builds: +- env: + - CGO_ENABLED=0 + main: ./cmd/tilt/main.go + goos: + - linux +archive: + name_template: "{{ .ProjectName }}.{{ .Version }}.{{ .Os }}.{{ .Arch }}" + replacements: + darwin: mac + linux: linux + 386: i386 + amd64: x86_64 +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Tag }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/Makefile b/Makefile index 910a8eab2c..31f4c1af92 100644 --- a/Makefile +++ b/Makefile @@ -95,3 +95,6 @@ synclet-release: docker build -t $(SYNCLET_IMAGE):$(TAG) -f synclet/Dockerfile . docker push $(SYNCLET_IMAGE):$(TAG) sed -i 's/var SyncletTag = ".*"/var SyncletTag = "$(TAG)"/' internal/synclet/sidecar/sidecar.go + +release: + goreleaser --rm-dist diff --git a/cmd/tilt/main.go b/cmd/tilt/main.go index 9f8292ab7e..b6c1b7e15f 100644 --- a/cmd/tilt/main.go +++ b/cmd/tilt/main.go @@ -4,6 +4,15 @@ import ( "github.com/windmilleng/tilt/internal/cli" ) +// Magic variables set by goreleaser +var version string +var commit string +var date string + func main() { + cli.SetBuildInfo(cli.BuildInfo{ + Version: version, + Date: date, + }) cli.Execute() } diff --git a/internal/cli/build.go b/internal/cli/build.go new file mode 100644 index 0000000000..8d19eef84f --- /dev/null +++ b/internal/cli/build.go @@ -0,0 +1,63 @@ +package cli + +import ( + "fmt" + "os" + "strings" +) + +type BuildInfo struct { + Version string + Date string +} + +func (e BuildInfo) empty() bool { + return e == BuildInfo{} +} + +var globalBuildInfo BuildInfo + +func SetBuildInfo(info BuildInfo) { + globalBuildInfo = info +} + +func buildStamp() string { + info := globalBuildInfo + if info.empty() { + info = defaultBuildInfo() + } + version := info.Version + date := info.Date + timeIndex := strings.Index(date, "T") + if timeIndex != -1 { + date = date[0:timeIndex] + } + return fmt.Sprintf("v%s, built %s", version, date) +} + +// Returns a build datestamp in the format 2018-08-30 +func defaultBuildDate() string { + // TODO(nick): Add a mechanism to encode the datestamp in the binary with + // ldflags. This currently only works if you are building your own + // binaries. It won't work once we're distributing pre-built binaries. + path, err := os.Executable() + if err != nil { + return "[unknown]" + } + + info, err := os.Stat(path) + if err != nil { + return "[unknown]" + } + + modTime := info.ModTime() + return modTime.Format("2006-01-02") +} + +// Returns a build datestamp in the format 2018-08-30 +func defaultBuildInfo() BuildInfo { + return BuildInfo{ + Date: defaultBuildDate(), + Version: "0.0.0-dev", + } +} diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 8dbfdf57b9..0f2a13be3e 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -45,6 +45,7 @@ func Execute() { addCommand(rootCmd, &downCmd{}) addCommand(rootCmd, &demoCmd{}) addCommand(rootCmd, &hudCmd{}) + addCommand(rootCmd, &versionCmd{}) rootCmd.PersistentFlags().BoolVarP(&debug, "debug", "d", false, "Enable debug logging") rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging") @@ -123,22 +124,3 @@ func addCommand(parent *cobra.Command, child tiltCmd) { parent.AddCommand(cobraChild) } - -// Returns a build datestamp in the format 2018-08-30 -func buildDateStamp() string { - // TODO(nick): Add a mechanism to encode the datestamp in the binary with - // ldflags. This currently only works if you are building your own - // binaries. It won't work once we're distributing pre-built binaries. - path, err := os.Executable() - if err != nil { - return "[unknown]" - } - - info, err := os.Stat(path) - if err != nil { - return "[unknown]" - } - - modTime := info.ModTime() - return modTime.Format("2006-01-02") -} diff --git a/internal/cli/hud.go b/internal/cli/hud.go index e5fc380ba7..ccd7e52fb2 100644 --- a/internal/cli/hud.go +++ b/internal/cli/hud.go @@ -38,7 +38,7 @@ func (c *hudCmd) run(ctx context.Context, args []string) error { span.SetTag(k, v) } - logOutput(fmt.Sprintf("Starting the HUD (built %s)…\n", buildDateStamp())) + logOutput(fmt.Sprintf("Starting the HUD (%s)…\n", buildStamp())) err := client.ConnectHud(ctx) if err == context.Canceled { diff --git a/internal/cli/up.go b/internal/cli/up.go index 0310895a88..7054c58cfd 100644 --- a/internal/cli/up.go +++ b/internal/cli/up.go @@ -71,7 +71,7 @@ func (c *upCmd) run(ctx context.Context, args []string) error { span.SetTag(k, v) } - logOutput(fmt.Sprintf("Starting Tilt (built %s)…\n", buildDateStamp())) + logOutput(fmt.Sprintf("Starting Tilt (%s)…\n", buildStamp())) if trace { traceID, err := tracer.TraceID(ctx) diff --git a/internal/cli/version.go b/internal/cli/version.go new file mode 100644 index 0000000000..731fbcaf4c --- /dev/null +++ b/internal/cli/version.go @@ -0,0 +1,24 @@ +package cli + +import ( + "context" + "fmt" + + "github.com/spf13/cobra" +) + +type versionCmd struct { +} + +func (c *versionCmd) register() *cobra.Command { + cmd := &cobra.Command{ + Use: "version", + Short: "current Tilt version", + } + return cmd +} + +func (c *versionCmd) run(ctx context.Context, args []string) error { + fmt.Println(buildStamp()) + return nil +}