Merge pull request #3596 from JRBaggins/fix/tag-version-resolution

fix: source-build version resolution for release tags
This commit is contained in:
Wesley Liddick
2026-07-01 14:45:11 +08:00
committed by GitHub
10 changed files with 49 additions and 13 deletions
+2 -1
View File
@@ -15,7 +15,8 @@ RUN go mod download
COPY . .
# 构建应用
RUN go build -o main ./cmd/server/
RUN VERSION_VALUE="$(./scripts/resolve-version.sh)" && \
go build -ldflags="-s -w -X main.Version=${VERSION_VALUE}" -o main ./cmd/server/
# 暴露端口
EXPOSE 8080
+1 -1
View File
@@ -1,6 +1,6 @@
.PHONY: build generate test test-unit test-integration test-e2e
VERSION ?= $(shell tr -d '\r\n' < ./cmd/server/VERSION)
VERSION ?= $(shell ./scripts/resolve-version.sh)
LDFLAGS ?= -s -w -X main.Version=$(VERSION)
build:
+23
View File
@@ -0,0 +1,23 @@
#!/bin/sh
set -eu
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
BACKEND_DIR="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd)"
REPO_DIR="$(CDPATH= cd -- "$BACKEND_DIR/.." && pwd)"
VERSION_FILE="$BACKEND_DIR/cmd/server/VERSION"
# Prefer the exact release tag when building from a tagged checkout so
# source builds from vX.Y.Z don't inherit the previous VERSION file value.
if command -v git >/dev/null 2>&1; then
TAG="$(
git -C "$REPO_DIR" describe --tags --exact-match --match 'v[0-9]*' 2>/dev/null || \
git -C "$REPO_DIR" describe --tags --exact-match --match '[0-9]*' 2>/dev/null || \
true
)"
if [ -n "$TAG" ]; then
printf '%s\n' "${TAG#v}"
exit 0
fi
fi
printf '%s\n' "$(tr -d '\r\n' < "$VERSION_FILE")"