fix(build): error on raw go build, require make build
Raw `go build` produces unsigned binaries that macOS kills. Add a BuiltProperly ldflag that make build sets, and check it at startup. If missing, print an error directing users to use make build. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
3
Makefile
3
Makefile
@@ -10,7 +10,8 @@ BUILD_TIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
|
|||||||
|
|
||||||
LDFLAGS := -X github.com/steveyegge/gastown/internal/cmd.Version=$(VERSION) \
|
LDFLAGS := -X github.com/steveyegge/gastown/internal/cmd.Version=$(VERSION) \
|
||||||
-X github.com/steveyegge/gastown/internal/cmd.Commit=$(COMMIT) \
|
-X github.com/steveyegge/gastown/internal/cmd.Commit=$(COMMIT) \
|
||||||
-X github.com/steveyegge/gastown/internal/cmd.BuildTime=$(BUILD_TIME)
|
-X github.com/steveyegge/gastown/internal/cmd.BuildTime=$(BUILD_TIME) \
|
||||||
|
-X github.com/steveyegge/gastown/internal/cmd.BuiltProperly=1
|
||||||
|
|
||||||
generate:
|
generate:
|
||||||
go generate ./...
|
go generate ./...
|
||||||
|
|||||||
@@ -68,6 +68,15 @@ var branchCheckExemptCommands = map[string]bool{
|
|||||||
|
|
||||||
// persistentPreRun runs before every command.
|
// persistentPreRun runs before every command.
|
||||||
func persistentPreRun(cmd *cobra.Command, args []string) error {
|
func persistentPreRun(cmd *cobra.Command, args []string) error {
|
||||||
|
// Check if binary was built properly (via make build, not raw go build).
|
||||||
|
// Raw go build produces unsigned binaries that macOS will kill.
|
||||||
|
if BuiltProperly == "" {
|
||||||
|
fmt.Fprintln(os.Stderr, "ERROR: This binary was built with 'go build' directly.")
|
||||||
|
fmt.Fprintln(os.Stderr, " Use 'make build' to create a properly signed binary.")
|
||||||
|
fmt.Fprintln(os.Stderr, " Run from: ~/gt/gastown/mayor/rig (or your rig's worktree)")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize CLI theme (dark/light mode support)
|
// Initialize CLI theme (dark/light mode support)
|
||||||
initCLITheme()
|
initCLITheme()
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ var (
|
|||||||
// Commit and Branch - the git revision the binary was built from (optional ldflag)
|
// Commit and Branch - the git revision the binary was built from (optional ldflag)
|
||||||
Commit = ""
|
Commit = ""
|
||||||
Branch = ""
|
Branch = ""
|
||||||
|
// BuiltProperly is set to "1" by `make build`. If empty, the binary was built
|
||||||
|
// with raw `go build` and is likely unsigned (will be killed on macOS).
|
||||||
|
BuiltProperly = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
var versionCmd = &cobra.Command{
|
var versionCmd = &cobra.Command{
|
||||||
|
|||||||
Reference in New Issue
Block a user