diff --git a/.gitattributes b/.gitattributes index 1a91be0..5f72683 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -frontend/** linguist-documentation +VERSION export-subst diff --git a/.goreleaser.yaml b/.goreleaser.yaml index aabb09f..8dde525 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -10,7 +10,7 @@ before: - make frontend-build builds: - - id: "standard" + - id: "universal" main: ./cmd env: - CGO_ENABLED=0 @@ -24,29 +24,13 @@ builds: goarch: - amd64 - arm64 - binary: 'libredesk{{ if eq .Os "windows" }}.exe{{ end }}' - ldflags: - - -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} - hooks: - post: make stuff BIN={{ .Path }} - - - id: "arm" - main: ./cmd - env: - - CGO_ENABLED=0 - goos: - - freebsd - - linux - - netbsd - - openbsd - goarch: - arm goarm: - 6 - 7 binary: 'libredesk{{ if eq .Os "windows" }}.exe{{ end }}' ldflags: - - -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} + - -s -w -X "main.buildString={{ .Tag }} ({{ .ShortCommit }} {{ .Date }}, {{ .Os }}/{{ .Arch }})" -X "main.versionString={{ .Tag }}" hooks: post: make stuff BIN={{ .Path }} @@ -70,7 +54,7 @@ dockers: goos: linux goarch: amd64 ids: - - standard + - universal image_templates: - "{{ .Env.DOCKER_ORG }}/{{ .ProjectName }}:latest-amd64" - "{{ .Env.DOCKER_ORG }}/{{ .ProjectName }}:{{ .Tag }}-amd64" @@ -94,7 +78,7 @@ dockers: goos: linux goarch: arm64 ids: - - standard + - universal image_templates: - "{{ .Env.DOCKER_ORG }}/{{ .ProjectName }}:latest-arm64" - "{{ .Env.DOCKER_ORG }}/{{ .ProjectName }}:{{ .Tag }}-arm64" @@ -119,7 +103,7 @@ dockers: goarch: arm goarm: 6 ids: - - arm + - universal image_templates: - "{{ .Env.DOCKER_ORG }}/{{ .ProjectName }}:latest-armv6" - "{{ .Env.DOCKER_ORG }}/{{ .ProjectName }}:{{ .Tag }}-armv6" @@ -144,7 +128,7 @@ dockers: goarch: arm goarm: 7 ids: - - arm + - universal image_templates: - "{{ .Env.DOCKER_ORG }}/{{ .ProjectName }}:latest-armv7" - "{{ .Env.DOCKER_ORG }}/{{ .ProjectName }}:{{ .Tag }}-armv7" @@ -195,4 +179,4 @@ release: owner: abhinavxd name: libredesk prerelease: auto - draft: true \ No newline at end of file + draft: true diff --git a/Makefile b/Makefile index 0bc2a90..b1e5a7e 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,10 @@ -# Build variables -LAST_COMMIT := $(shell git rev-parse --short HEAD) -LAST_COMMIT_DATE := $(shell git show -s --format=%ci ${LAST_COMMIT}) -VERSION := $(shell git describe --tags) -BUILDSTR := ${VERSION} (Commit: ${LAST_COMMIT_DATE} (${LAST_COMMIT}), Build: $(shell date +"%Y-%m-%d %H:%M:%S %z")) +# Try to get the commit hash from 1) git 2) the VERSION file 3) fallback. +LAST_COMMIT := $(or $(shell git rev-parse --short HEAD 2> /dev/null),$(shell head -n 1 VERSION | grep -oP -m 1 "^[a-z0-9]+$$"), "") + +# Try to get the semver from 1) git 2) the VERSION file 3) fallback. +VERSION := $(or $(LIBREDESK_VERSION),$(shell git describe --tags --abbrev=0 2> /dev/null),$(shell grep -oP 'tag: \Kv\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+)?' VERSION),"v0.0.0") + +BUILDSTR := ${VERSION} (\#${LAST_COMMIT} $(shell date -u +"%Y-%m-%dT%H:%M:%S%z")) # Binary names and paths BIN := libredesk @@ -30,13 +32,13 @@ install-deps: $(STUFFBIN) .PHONY: frontend-build frontend-build: install-deps @echo "→ Building frontend for production..." - @cd ${FRONTEND_DIR} && pnpm build + @export VITE_APP_VERSION="${VERSION}" && cd ${FRONTEND_DIR} && pnpm build # Run the Go backend server in development mode. .PHONY: run-backend run-backend: @echo "→ Running backend..." - CGO_ENABLED=0 go run -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.frontendDir=frontend/dist'" cmd/*.go + CGO_ENABLED=0 go run -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}' -X 'main.frontendDir=frontend/dist'" cmd/*.go # Run the JS frontend server in development mode. .PHONY: run-frontend @@ -44,19 +46,19 @@ run-frontend: @echo "→ Installing frontend dependencies (if not already installed)..." @cd ${FRONTEND_DIR} && pnpm install @echo "→ Running frontend..." - @export VUE_APP_VERSION="${VERSION}" && cd ${FRONTEND_DIR} && pnpm dev + @export VITE_APP_VERSION="${VERSION}" && cd ${FRONTEND_DIR} && pnpm dev # Build the backend binary. -.PHONY: backend-build -backend-build: $(STUFFBIN) +.PHONY: build-backend +build-backend: $(STUFFBIN) @echo "→ Building backend..." @CGO_ENABLED=0 go build -a\ - -ldflags="-X 'main.buildString=${BUILDSTR}' -s -w" \ + -ldflags="-X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}' -s -w" \ -o ${BIN} cmd/*.go # Main build target: builds both frontend and backend, then stuffs static assets into the binary. .PHONY: build -build: frontend-build backend-build stuff +build: frontend-build build-backend stuff @echo "→ Build successful. Current version: $(VERSION)" # Stuff static assets into the binary using stuffbin. diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..4df4b1d --- /dev/null +++ b/VERSION @@ -0,0 +1,2 @@ +$Format:%h$ +$Format:%D$ diff --git a/go.mod b/go.mod index 2e03696..f18c0aa 100644 --- a/go.mod +++ b/go.mod @@ -35,6 +35,7 @@ require ( github.com/zerodha/simplesessions/stores/redis/v3 v3.0.0 github.com/zerodha/simplesessions/v3 v3.0.0 golang.org/x/crypto v0.31.0 + golang.org/x/mod v0.17.0 golang.org/x/oauth2 v0.21.0 ) diff --git a/go.sum b/go.sum index e814ca4..36ae56b 100644 --- a/go.sum +++ b/go.sum @@ -187,6 +187,8 @@ golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ= golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=