Skip to content

Commit e6d1269

Browse files
authored
Merge pull request #17 from mbevc1/20230902_refactor_version
feat: Refactor versioning
2 parents 1f1f40c + fe7de1c commit e6d1269

5 files changed

Lines changed: 32 additions & 15 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ react*
22
mts.yaml
33
vendor/
44
backups/
5+
dist/

.goreleaser.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ project_name: react
33
source:
44
enabled: false
55

6-
env:
7-
- GO111MODULE=on
6+
#env:
7+
#- GO111MODULE=on
88
#- GOPROXY=https://gocenter.io
99

1010
before:
@@ -32,7 +32,10 @@ builds:
3232
- GOTELEMETRY="off"
3333
flags:
3434
- -v
35-
ldflags: -X github.com/mbevc1/react/main.Version={{.Env.VERSION}}
35+
#ldflags: -X github.com/mbevc1/react/main.Version={{.Env.VERSION}}
36+
37+
upx:
38+
- enabled: true
3639

3740
archives:
3841
- id: react
@@ -62,7 +65,6 @@ release:
6265
draft: false
6366
disable: false
6467

65-
6668
checksum:
6769
#name_template: "{{ .ProjectName }}_{{ .Version }}_sha256_checksums.txt"
6870
name_template: "{{ .ProjectName }}_{{ .Version }}_sha256_checksums.txt"

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ RED=\033[31;01m
1212
VER?=dev
1313
GHASH:=$(shell git rev-parse --short HEAD)
1414
VERSION?=$(shell git describe --tags --always --dirty --match=v* 2> /dev/null || echo v0)
15+
GOTELEMETRY:= off
1516
GO:= go
1617
GO_BUILD:= go build -mod vendor -ldflags "-s -w -X main.GitCommit=${GHASH} -X main.Version=${VERSION}"
1718
#VERSION="${VERSION}" goreleaser --snapshot --rm-dist
@@ -30,7 +31,7 @@ vendor: **/*.go ## Build vendor deps
3031
GO111MODULE=on $(GO_VENDOR)
3132

3233
clean: clean-vendor ## Clean artefacts
33-
rm -rf $(BIN) $(BIN)_* $(BIN).exe go.sum
34+
rm -rf $(BIN) $(BIN)_* $(BIN).exe dist/
3435

3536
clean-vendor: ## Clean vendor folder
3637
rm -rf vendor
@@ -41,6 +42,9 @@ build: clean $(BIN) ## Build binary
4142
run:
4243
go run .
4344

45+
snapshot: clean ## Build local snapshot
46+
goreleaser build --snapshot --clean
47+
4448
dev: clean ## Dev test target
4549
go build -ldflags "-s -w -X main.Version=${VER}" -o $(BIN)
4650
upx $(BIN)

main.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,20 @@ func main() {
3131
flag.Parse()
3232

3333
if *ver {
34-
fmt.Printf("%s %v\n", Name, Version)
35-
if GitCommit != "" {
36-
fmt.Printf("Commit hash: %v\n", GitCommit)
34+
fmt.Printf("%s version %v\n", Name, version)
35+
if commit != "" {
36+
fmt.Printf("commit: %s\n", commit)
3737
}
38+
fmt.Printf("built at: %s\n", date)
39+
fmt.Printf("built by: %s\n", builtBy)
3840
os.Exit(0)
3941
} else if *cmd == "" && !*bck && !*rbt && !*upg || *hlp {
40-
fmt.Printf("%s %v\n", Name, Version)
42+
fmt.Printf("%s version %v\n", Name, version)
43+
if commit != "" {
44+
fmt.Printf("commit: %s\n", commit)
45+
}
46+
fmt.Printf("built at: %s\n", date)
47+
fmt.Printf("built by: %s\n", builtBy)
4148
flag.PrintDefaults()
4249
if *hlp {
4350
os.Exit(0)

version.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package main
22

3-
//GitCommit The git commit that was compiled. This will be filled in by the compiler.
4-
var GitCommit string
3+
// Version current app version
4+
// var Version = "dev"
5+
var (
6+
version = "dev"
7+
commit = ""
8+
date = ""
9+
builtBy = ""
10+
)
511

6-
//Version current app version
7-
var Version = "dev"
8-
9-
//Name of the app
12+
// Name of the app
1013
var Name = "ReAcT"

0 commit comments

Comments
 (0)