diff --git a/Makefile b/Makefile index 5430375..3fe8704 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,8 @@ # Specify the name of your Go binary output BINARY_NAME := opengist +GIT_TAG := $(shell git describe --tags) +VERSION_PKG := github.com/thomiceli/opengist/internal/config.OpengistVersion all: clean install build @@ -20,7 +22,7 @@ build_frontend: build_backend: @echo "Building Opengist binary..." - go build -tags fs_embed -o $(BINARY_NAME) . + go build -tags fs_embed -ldflags "-X $(VERSION_PKG)=$(GIT_TAG)" -o $(BINARY_NAME) . build: build_frontend build_backend @@ -36,7 +38,7 @@ build_dev_docker: docker build -t $(BINARY_NAME)-dev:latest --target dev . run_dev_docker: - docker run -v .:/opengist -p 6157:6157 -p 16157:16157 $(BINARY_NAME)-dev:latest + docker run -v .:/opengist -p 6157:6157 -p 16157:16157 -v $(HOME)/.opengist-dev:/root/.opengist --rm $(BINARY_NAME)-dev:latest watch_frontend: @echo "Building frontend assets..." @@ -44,7 +46,7 @@ watch_frontend: watch_backend: @echo "Building Opengist binary..." - OG_DEV=1 npx nodemon --watch '**/*' -e html,yml,go,js --signal SIGTERM --exec 'go run . --config config.yml' + OG_DEV=1 npx nodemon --watch '**/*' -e html,yml,go,js --signal SIGTERM --exec 'go run -ldflags "-X $(VERSION_PKG)=$(GIT_TAG)" . --config config.yml' watch: @sh ./scripts/watch.sh diff --git a/internal/cli/main.go b/internal/cli/main.go index 31b641c..533695f 100644 --- a/internal/cli/main.go +++ b/internal/cli/main.go @@ -20,7 +20,7 @@ var CmdVersion = cli.Command{ Name: "version", Usage: "Print the version of Opengist", Action: func(c *cli.Context) error { - fmt.Println("Opengist v" + config.OpengistVersion) + fmt.Println("Opengist " + config.OpengistVersion) return nil }, } @@ -57,7 +57,7 @@ func App() error { } func Initialize(ctx *cli.Context) { - fmt.Println("Opengist v" + config.OpengistVersion) + fmt.Println("Opengist " + config.OpengistVersion) if err := config.InitConfig(ctx.String("config"), os.Stdout); err != nil { panic(err) diff --git a/internal/config/config.go b/internal/config/config.go index 7ac4e4a..6133019 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -17,7 +17,7 @@ import ( "gopkg.in/yaml.v3" ) -var OpengistVersion = "1.7.1" +var OpengistVersion = "" var C *config diff --git a/scripts/build-all.sh b/scripts/build-all.sh index fe56710..9b7f3a1 100755 --- a/scripts/build-all.sh +++ b/scripts/build-all.sh @@ -4,6 +4,7 @@ CHECKSUMS_FILE="build/checksums.txt" BINARY_NAME="opengist" TARGETS="darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 linux/armv6 linux/armv7 linux/386 windows/amd64" VERSION=$(git describe --tags | sed 's/^v//') +VERSION_PKG="github.com/thomiceli/opengist/internal/config.OpengistVersion" if [ -z "$VERSION" ]; then echo "Error: Could not retrieve version from git tags. Exiting..." @@ -38,7 +39,7 @@ for TARGET in $TARGETS; do echo "Building version $VERSION for $GOOS/$GOARCH${GOARM:+v$GOARM}..." mkdir -p $OUTPUT_DIR - env GOOS=$GOOS GOARCH=$GOARCH GOARM=$GOARM CGO_ENABLED=0 go build -tags fs_embed -o $OUTPUT_FILE + env GOOS=$GOOS GOARCH=$GOARCH GOARM=$GOARM CGO_ENABLED=0 go build -tags fs_embed -ldflags "-X $VERSION_PKG=v$VERSION" -o $OUTPUT_FILE cp README.md $OUTPUT_DIR cp LICENSE $OUTPUT_DIR cp config.yml $OUTPUT_DIR