mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-24 16:05:44 +08:00
Merge pull request #3596 from JRBaggins/fix/tag-version-resolution
fix: source-build version resolution for release tags
This commit is contained in:
+2
-1
@@ -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
@@ -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:
|
||||
|
||||
Executable
+23
@@ -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")"
|
||||
Reference in New Issue
Block a user