diff --git a/.gitignore b/.gitignore index 2b99ee5424..22f90c53a1 100644 --- a/.gitignore +++ b/.gitignore @@ -117,3 +117,6 @@ fleet_tables_*.ext .env .tool-versions .zed/ + +# Required to not make `fleet-desktop` macOS executable built with a `dirty` flag (see #35006). +Fleet\ Desktop.app \ No newline at end of file diff --git a/orbit/changes/35006-add-tmp-folder-to-.gitignore b/orbit/changes/35006-add-tmp-folder-to-.gitignore new file mode 100644 index 0000000000..18fef13c5c --- /dev/null +++ b/orbit/changes/35006-add-tmp-folder-to-.gitignore @@ -0,0 +1 @@ +* Fixed macOS `fleet-desktop` that was being displayed as dirty by `go version -m`. diff --git a/tools/desktop/desktop.go b/tools/desktop/desktop.go index e88d6bd36c..02d05083ce 100644 --- a/tools/desktop/desktop.go +++ b/tools/desktop/desktop.go @@ -4,6 +4,7 @@ import ( "archive/tar" "compress/gzip" "context" + "debug/buildinfo" "errors" "fmt" "io" @@ -11,6 +12,7 @@ import ( "os/exec" "path/filepath" "runtime" + "strings" "github.com/fleetdm/fleet/v4/orbit/pkg/constant" "github.com/fleetdm/fleet/v4/orbit/pkg/packaging" @@ -85,8 +87,10 @@ func macos() *cli.Command { }, }, Action: func(c *cli.Context) error { - if !c.Bool("verbose") { - zlog.Logger = zerolog.Nop() + if c.Bool("verbose") { + zerolog.SetGlobalLevel(zerolog.DebugLevel) + } else { + zerolog.SetGlobalLevel(zerolog.InfoLevel) } return createMacOSApp(c.String("version"), c.String("authority"), c.Bool("notarize")) }, @@ -191,6 +195,20 @@ func createMacOSApp(version, authority string, notarize bool) error { return fmt.Errorf("remove arm64 binary: %w", err) } + // Check that executable is not dirty (see #35006). + info, err := buildinfo.ReadFile(binaryPath) + if err != nil { + return fmt.Errorf("failed to read build info of %q: %w", binaryPath, err) + } + if strings.Contains(info.Main.Version, "dirty") { + gitStatus, err := exec.Command("git", "status").Output() + if err != nil { + zlog.Info().Str("command", "git status").Err(err).Msg("Failed to execute") + } + zlog.Info().Str("output", string(gitStatus)).Msg("git status") + return fmt.Errorf("detected dirty executable: %+v", info.Main) + } + if authority != "" { codeSign := exec.Command("codesign", "-s", authority, "-i", bundleIdentifier, "-f", "-v", "--timestamp", "--options", "runtime", appDir)