All checks were successful
check / check (push) Successful in 3m6s
The binary reported "dev" in every deployment: main.version carried a placeholder and nothing ever set it. Neither `make build` nor the Dockerfile passed -X, so a tagged release produced an artifact that could not say which commit it was, and the upgrade procedure's "confirm the new build is live" step had nothing to confirm against. script/version is now the single source of the value: $VERSION when set, else `git describe --tags --always --dirty`, else "unknown". A clean checkout at a tag reports exactly that tag; a tree with no git metadata reports "unknown" rather than failing or naming a tag it may not be at. Nothing time- or host-dependent is stamped, so two builds of one commit stay byte-identical. The Makefile's build target composes the flags -- `-X main.version` plus whatever GO_LDFLAGS adds -- and every compile goes through it, including the Dockerfile's static relink, which now contributes its -extldflags through GO_LDFLAGS instead of replacing -ldflags wholesale. Since .dockerignore excludes .git/, the image cannot derive the version: it takes a VERSION build arg, defaulted to "unknown", that script/docker fills in from the host checkout. The UI footer needed the other half of the fix. It renders .Version, which nothing ever put in the template data, so it printed its literal "dev" fallback no matter what the binary was built as; renderTemplate now supplies the value on both the map and the wrapper path. An empty VERSION means unset in the Makefile too, not only in script/version: `make build VERSION=` and a `--build-arg VERSION=` reaching the Dockerfile's `make build VERSION="$VERSION"` both define the variable as the empty string, which the script's guard never sees and which would stamp no version at all -- putting the footer back on its "dev" fallback, the defect this change exists to remove. The guard needs `override`: a plain assignment loses to the command-line definition it exists to correct.
39 lines
953 B
Go
39 lines
953 B
Go
package handlers_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"sneak.berlin/go/webhooker/internal/globals"
|
|
"sneak.berlin/go/webhooker/internal/handlers"
|
|
"sneak.berlin/go/webhooker/internal/session"
|
|
)
|
|
|
|
// The footer in base.html falls back to the literal "dev" when the
|
|
// template data carries no version, which is what every page rendered
|
|
// while nothing supplied one. The operator uses the footer to tell
|
|
// which build is live, so it has to carry the stamped value.
|
|
func TestFooterReportsStampedVersion(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var (
|
|
h *handlers.Handlers
|
|
sess *session.Session
|
|
g *globals.Globals
|
|
)
|
|
|
|
app := newTestApp(t, &h, &sess, &g)
|
|
app.RequireStart()
|
|
|
|
t.Cleanup(app.RequireStop)
|
|
|
|
g.Version = "v9.9.9-test"
|
|
|
|
html := renderPage(t, h, sess, "login.html", map[string]any{
|
|
dataKeyError: "",
|
|
})
|
|
|
|
assert.Contains(t, html, "<span>v9.9.9-test</span>")
|
|
assert.NotContains(t, html, "<span>dev</span>")
|
|
}
|