Skip to content

Commit

Permalink
Fix build/version string handling.
Browse files Browse the repository at this point in the history
- Split build and version strings.
- Display version instead of build on the admin UI via the config API.
  • Loading branch information
knadh committed Dec 18, 2021
1 parent 0ab8992 commit 6422a2f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
LAST_COMMIT := $(shell git rev-parse --short HEAD)
VERSION := $(shell git describe --tags --abbrev=0)
BUILDSTR := ${VERSION} (\#${LAST_COMMIT} $(shell date -u +"%Y-%m-%dT%H:%M:%S%z"))
BUILDSTR := \#${LAST_COMMIT} $(shell date -u +"%Y-%m-%dT%H:%M:%S%z")

STATIC := config.sample.toml schema.sql queries.sql admin
BIN := dictpress
Expand All @@ -12,7 +12,7 @@ deps:

.PHONY: build
build:
go build -o ${BIN} -ldflags="-s -w -X 'main.buildString=${BUILDSTR}'" cmd/${BIN}/*.go
go build -o ${BIN} -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}'" cmd/${BIN}/*.go

.PHONY: run
run:
Expand Down
4 changes: 3 additions & 1 deletion admin/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
</div>
</template>
<footer class="footer">
<a href="https://dict.press">DictPress <span x-text="config.version"></span></a>
<a href="https://dict.press">
DictPress <span x-text="config.version"></span>
</a>
</footer>
</body>
</html>
Expand Down
3 changes: 2 additions & 1 deletion cmd/dictpress/admin_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ func handleGetConfig(c echo.Context) error {
RootURL string `json:"root_url"`
Languages data.LangMap `json:"languages"`
Version string `json:"version"`
}{app.constants.RootURL, app.data.Langs, buildString}
BuildStr string `json:"build"`
}{app.constants.RootURL, app.data.Langs, versionString, buildString}

return c.JSON(http.StatusOK, okResp{out})
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/dictpress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (
)

var (
buildString = "unknown"
buildString = "unknown"
versionString = "unknown"
)

// Lang represents a language's configuration.
Expand Down Expand Up @@ -80,7 +81,7 @@ func init() {
}

if ok, _ := f.GetBool("version"); ok {
fmt.Println(buildString)
fmt.Printf("%s (%s)\n", versionString, buildString)
os.Exit(0)
}

Expand Down

0 comments on commit 6422a2f

Please sign in to comment.