Repository navigation
Prepare the binary for installing: version, example config, config location - #43
Merged
Merged
Conversation
Users will install the binary with go install or download it from a release, and then have neither the source nor config.yaml.example. - -version prints the version Go records in the binary: the tag for a release or go install ...@vX.Y.Z, a pseudo-version for go build in a checkout, "(devel)" for go run. The startup log shows it too. - -example-config prints the built-in config.yaml.example, so a config file is one command away. - A missing config file now says how to create one. The e2e tests and the docs run the package (go run ., go build .) instead of main.go: a file list builds without the version stamp and would leave out any other file of package main.
- The page header shows which version is running: the release version (v1.0.0), otherwise the commit of the build (59b1469, -dirty with uncommitted changes), or "dev" for go run. Hovering shows the full description that -version prints. The version code moves to internal/version so the command and the server share it. - Without -config, the config file is now ~/.config/mailboxzero/config.yaml ($XDG_CONFIG_HOME/mailboxzero/ config.yaml when that is set) on every OS, instead of config.yaml in the current directory. An installed binary is run from anywhere, and an unrelated config.yaml in the current directory must not be picked up. The log names the file used, and a missing file's error says how to create the folder and the file.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Mailbox Zero will be released as v1.0.0. Users will install it with
go install github.com/taskinen/mailboxzero@latestor download a binary from the GitHub release, and then run it from anywhere, with no source and noconfig.yaml.example. This is the first of three PRs before that release:Changes
Version (new
internal/version, read from the build information Go records in every binary; no version variable or-Xlinker flags):-versionprintsmailboxzero <version> (<Go version>, <OS>/<arch>). The startup log shows the same string. The version is:v1.0.0for a release binary and forgo install …@v1.0.0;go buildin a checkout (for examplev0.0.0-20261016172523-59b1469d2f82), with+dirtyfor uncommitted changes;(devel)forgo run.v1.0.0), otherwise the build's commit (59b1469, or59b1469-dirty), ordevforgo run. Hovering shows the full-versiontext.Config file
-example-configprints the built-inconfig.yaml.example(//go:embed).-config, the file is now~/.config/mailboxzero/config.yaml, or$XDG_CONFIG_HOME/mailboxzero/config.yamlwhen that is set, on every OS.config.yamlin the current directory. An installed binary runs from anywhere, and an unrelatedconfig.yamlin the current folder must not be picked up.$XDG_CONFIG_HOMEis ignored, as the XDG spec says.config file /Users/you/.config/mailboxzero/config.yaml not found: create it withmkdir -p /Users/you/.config/mailboxzero && mailboxzero -example-config > /Users/you/.config/mailboxzero/config.yamland add your Fastmail API token, or give another file with -config: …Also
main.go, which pkg.go.dev shows as the command's description.config.yaml.example: its header names the default location and the commands.e2e/playwright.config.js: runsgo run .instead ofgo run main.go. A file list builds without the version stamp and would leave out any other file in packagemain..and the new config location, plus the version package, the header label and the new tests.Note for your current setup: your
config.yamlin the repository folder is no longer read by default. Rungo run . -config config.yaml, or move it once withmkdir -p ~/.config/mailboxzero && mv config.yaml ~/.config/mailboxzero/. The README's commands are updated in PR 3.Tests
internal/version:String()for a tag, a pseudo-version,+dirty,(devel), an empty version and no build info.Short()for:go installof a commit (the hash comes from the pseudo-version);go run;main_test.go:XDG_CONFIG_HOMEset, unset and relative;mkdir -pand the-example-configcommands, and wrapsfs.ErrNotExist;server_test.go: the index page renders the version label with its hover text.e2e/tests/version.spec.js: the header shows a version label (devundergo run) and its title.Results:
go test -race ./...andgo vet ./...pass.Checked by hand with a built binary in mock mode: the header showed
59b1469-dirtyand the hover textmailboxzero v0.0.0-20261016172523-59b1469d2f82+dirty (go1.27.2, darwin/arm64). I also checked-version,-example-config(identical toconfig.yaml.example),-h, and the missing-config message.Testing on Fastmail
mkdir -p ~/.config/mailboxzero && mv config.yaml ~/.config/mailboxzero/(or keep it and add-config config.yamlin step 2).go run .in the repository. The log showsUsing config file /Users/…/.config/mailboxzero/config.yaml. Use the app as usual; the header showsdevnext to the title.go build -o mailboxzero . && ./mailboxzero. The header shows the commit (for example1dd0957), and hovering shows the full version../mailboxzero -versionand./mailboxzero -example-config | head -6../mailboxzero -config /tmp/nothing.yamlexplains how to create a config.