-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd: make tilt binary compatible with goreleaser
- Loading branch information
Showing
9 changed files
with
129 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,7 @@ | |
*.generated.yaml | ||
|
||
.synclet-dev-image-tag | ||
.#* | ||
.#* | ||
|
||
# goreleaser binaries | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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:' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |