Skip to content

Commit

Permalink
Set Opengist version from git tags (thomiceli#261)
Browse files Browse the repository at this point in the history
* Set Opengist version from git tags

* Add volume for docker dev container
  • Loading branch information
thomiceli committed Apr 27, 2024
1 parent 785d89d commit 3551fd7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -36,15 +38,15 @@ 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..."
npx vite -c public/vite.config.js dev --port 16157 --host

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
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"gopkg.in/yaml.v3"
)

var OpengistVersion = "1.7.1"
var OpengistVersion = ""

var C *config

Expand Down
3 changes: 2 additions & 1 deletion scripts/build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3551fd7

Please sign in to comment.