Skip to content

Commit 59c234e

Browse files
authored
Merge pull request #43 from JVMerkle/feature/git-describe
Use git-describe to determine the version
2 parents 2d01814 + 542ab00 commit 59c234e

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
GO ?= go
22
PODMAN ?= podman
33

4-
GITHASH := $(shell git rev-parse --short HEAD)
4+
GITDESCRIBE := $(shell git describe)
55
BUILDTIME := $(shell date -u '+%Y%m%dT%H%M%SZ')
66

7-
GOLDFLAGS += -X "github.com/JVMerkle/gemportal/app.gitHash=$(GITHASH)"
7+
GOLDFLAGS += -X "github.com/JVMerkle/gemportal/app.gitDescribe=$(GITDESCRIBE)"
88
GOLDFLAGS += -X "github.com/JVMerkle/gemportal/app.buildTime=$(BUILDTIME)"
99
GOLDFLAGS += -w -s
1010
GOFLAGS += -ldflags "$(GOLDFLAGS)"

app/config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ var (
1919

2020
// Injected with linker flags
2121
var (
22-
gitHash string
23-
buildTime string
22+
gitDescribe string
23+
buildTime string
2424
)
2525

2626
type Config struct {
@@ -47,7 +47,7 @@ func (c *Config) GetAppBuildMeta() string {
4747
}
4848

4949
// GetConfig loads and checks the application configuration
50-
func GetConfig(appVersion string) (*Config, error) {
50+
func GetConfig() (*Config, error) {
5151
var cfg Config
5252

5353
// Load environment variables from a ".env" file, if exists
@@ -58,17 +58,17 @@ func GetConfig(appVersion string) (*Config, error) {
5858
return nil, err
5959
}
6060

61-
if len(gitHash) == 0 || len(buildTime) == 0 {
62-
log.Warn("Link time definitions missing (GitHash/Buildtime)")
61+
if len(gitDescribe) == 0 || len(buildTime) == 0 {
62+
log.Warn("Link time definitions missing (gitDescribe/Buildtime)")
6363
}
6464

6565
if len(cfg.AppDesc) == 0 {
6666
cfg.AppDesc = template.HTML("<b>Simple</b> Gemini HTTP portal for port " + cfg.DefaultPort + ".")
6767
}
6868

69-
buildMeta := []string{gitHash, buildTime}
69+
buildMeta := []string{gitDescribe, buildTime}
7070

71-
cfg.appVersion = appVersion
71+
cfg.appVersion = gitDescribe
7272

7373
for i := 0; i < len(buildMeta); i++ {
7474
cfg.appBuildMeta += buildMeta[i]

main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import (
1616
"github.com/gorilla/mux"
1717
)
1818

19-
const AppVersion = "1.0.3"
20-
2119
//go:embed static/style.css
2220
//go:embed static/app.js
2321
var staticFS embed.FS
@@ -26,7 +24,7 @@ var staticFS embed.FS
2624
var templateFS embed.FS
2725

2826
func main() {
29-
cfg, err := app.GetConfig(AppVersion)
27+
cfg, err := app.GetConfig()
3028
if err != nil {
3129
log.Fatalf("Could not load config: %s", err.Error())
3230
}

templates/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ <h1><a class="title" href="{{ .Cfg.BaseHREF }}">{{ .Cfg.AppName }}</a></h1>
5151
rel="noreferrer noopener">gemportal</a>
5252
{{ if .Cfg.GetAppBuildMeta }}
5353
<span class="version"
54-
title="{{ .Cfg.GetAppVersion }}+{{ .Cfg.GetAppBuildMeta }}">v{{ .Cfg.GetAppVersion }}</span>
54+
title="{{ .Cfg.GetAppBuildMeta }}">{{ .Cfg.GetAppVersion }}</span>
5555
{{ else }}
56-
<span class="version" title="{{ .Cfg.GetAppVersion }}">v{{ .Cfg.GetAppVersion }}</span>
56+
<span class="version" title="{{ .Cfg.GetAppVersion }}">{{ .Cfg.GetAppVersion }}</span>
5757
{{ end }}
5858
</footer>
5959
</body>

0 commit comments

Comments
 (0)