From b1d56a008adc9daa4ab5fc8b9a6ac32b87118daa Mon Sep 17 00:00:00 2001 From: Moritz Clasmeier Date: Sun, 19 Apr 2026 09:02:33 +0200 Subject: [PATCH 1/2] simplify version/commit injection --- .github/workflows/release.yml | 4 +--- Dockerfile | 2 -- Makefile | 11 +---------- cmd/version.go | 7 +------ flake.nix | 18 ------------------ 5 files changed, 3 insertions(+), 39 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5d8a6fc..31a9298 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,16 +29,14 @@ jobs: id: version run: | echo "version=$(make version)" >> $GITHUB_OUTPUT - echo "git_commit=$(make get-commit-hash)" >> $GITHUB_OUTPUT echo "build_date=$(make get-build-date)" >> $GITHUB_OUTPUT - name: Build binaries for multiple platforms env: VERSION: ${{ steps.version.outputs.version }} - GIT_COMMIT: ${{ steps.version.outputs.git_commit }} BUILD_DATE: ${{ steps.version.outputs.build_date }} run: | - LDFLAGS="-X main.version=${VERSION} -X main.gitCommit=${GIT_COMMIT} -X main.buildDate=${BUILD_DATE}" + LDFLAGS="-X main.version=${VERSION} -X main.buildDate=${BUILD_DATE}" # Linux amd64 GOOS=linux GOARCH=amd64 go build -ldflags "${LDFLAGS}" -o roxie-linux-amd64 ./cmd diff --git a/Dockerfile b/Dockerfile index 1abe785..c8c7799 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,13 +23,11 @@ COPY . . # Build roxie binary with version info and cross-compilation support ARG ROXIE_VERSION ARG BUILD_DATE -ARG GIT_COMMIT RUN CGO_ENABLED=0 \ GOOS=${TARGETOS} \ GOARCH=${TARGETARCH} \ ROXIE_VERSION=${ROXIE_VERSION} \ BUILD_DATE=${BUILD_DATE} \ - GIT_COMMIT=${GIT_COMMIT} \ make build # Download gcloud SDK in builder stage to avoid UBI filesystem restrictions diff --git a/Makefile b/Makefile index a90c739..be32154 100644 --- a/Makefile +++ b/Makefile @@ -17,8 +17,6 @@ PKG_LIST := $(shell $(GOCMD) list ./... | grep -v /vendor/) BUILD_DIR := . BINARY := $(BUILD_DIR)/$(BINARY_NAME) -# Version information -GIT_COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo "unknown") # Convention is that the git tags are of the form # v..--[-dirty] # or v.. @@ -31,16 +29,12 @@ GIT_COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo "unknown") # This will also become the tag of the docker images. ROXIE_VERSION ?= $(shell git describe --tags --always --dirty | sed -E 's/^v([0-9]+\.[0-9]+\.[0-9]+-[0-9]+-[a-z0-9]+(-dirty)?$$)/\1/') BUILD_DATE ?= $(shell date -u '+%Y-%m-%dT%H:%M:%SZ') -LDFLAGS := -X main.version=$(ROXIE_VERSION) -X main.gitCommit=$(GIT_COMMIT) -X main.buildDate=$(BUILD_DATE) +LDFLAGS := -X main.version=$(ROXIE_VERSION) -X main.buildDate=$(BUILD_DATE) .PHONY: get-build-date get-build-date: @echo $(BUILD_DATE) -.PHONY: get-commit-hash -get-commit-hash: - @echo $(GIT_COMMIT) - .PHONY: version version: @echo $(ROXIE_VERSION) @@ -210,7 +204,6 @@ docker-build: ## Build roxie Docker image for current platform fi $(CONTAINER_RUNTIME) build \ --build-arg ROXIE_VERSION=$(ROXIE_VERSION) \ - --build-arg GIT_COMMIT=$(GIT_COMMIT) \ --build-arg BUILD_DATE=$(BUILD_DATE) \ -t $(IMAGE_LATEST_TAG) \ -t $(IMAGE_VERSION_TAG) \ @@ -230,7 +223,6 @@ docker-build-arm64: ## Build roxie Docker image for arm64 $(CONTAINER_RUNTIME) build \ --platform linux/arm64 \ --build-arg ROXIE_VERSION=$(ROXIE_VERSION) \ - --build-arg GIT_COMMIT=$(GIT_COMMIT) \ --build-arg BUILD_DATE=$(BUILD_DATE) \ -t $(IMAGE_LATEST_TAG)-arm64 \ -t $(IMAGE_VERSION_TAG)-arm64 \ @@ -249,7 +241,6 @@ docker-build-amd64: ## Build roxie Docker image for amd64 $(CONTAINER_RUNTIME) build \ --platform linux/amd64 \ --build-arg ROXIE_VERSION=$(ROXIE_VERSION) \ - --build-arg GIT_COMMIT=$(GIT_COMMIT) \ --build-arg BUILD_DATE=$(BUILD_DATE) \ -t $(IMAGE_LATEST_TAG)-amd64 \ -t $(IMAGE_VERSION_TAG)-amd64 \ diff --git a/cmd/version.go b/cmd/version.go index cf738f3..dbe84eb 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -9,7 +9,6 @@ import ( var ( // Version information set at build time via -ldflags version = "dev" - gitCommit = "unknown" buildDate = "unknown" ) @@ -25,11 +24,7 @@ func newVersionCmd() *cobra.Command { } func runVersion(cmd *cobra.Command, args []string) { - if gitCommit != "unknown" && gitCommit != "" { - fmt.Printf("roxie version %s-%s", version, gitCommit) - } else { - fmt.Printf("roxie version %s", version) - } + fmt.Printf("roxie version %s", version) if buildDate != "unknown" && buildDate != "" { fmt.Printf(" (%s)", buildDate) diff --git a/flake.nix b/flake.nix index 8cc1238..633eafe 100644 --- a/flake.nix +++ b/flake.nix @@ -11,26 +11,9 @@ let pkgs = nixpkgs.legacyPackages.${system}; - # Get git commit hash (short version - first 8 chars) - # Uses builtins.readFile to get hash even from dirty repos - gitCommit = - let - shortRev = self.shortRev or null; - dirtyRev = builtins.readFile (pkgs.runCommand "git-hash" { - nativeBuildInputs = [ pkgs.git ]; - } '' - git -C ${./.} rev-parse --short=8 HEAD > $out 2>/dev/null || echo "unknown" > $out - ''); - cleanDirtyRev = pkgs.lib.strings.removeSuffix "\n" dirtyRev; - in - if shortRev != null then shortRev - else if self ? rev then "${cleanDirtyRev}-dirty" - else cleanDirtyRev; - # Build roxie roxie = pkgs.buildGoModule { pname = "roxie"; - version = "0.1-${gitCommit}"; src = ./.; @@ -41,7 +24,6 @@ # Inject version information at build time ldflags = [ "-X main.version=0.1" - "-X main.gitCommit=${gitCommit}" "-X main.buildDate=1970-01-01T00:00:00Z" ]; From 92e93d4de3f1ccce58bb37204e8607389ccea3dd Mon Sep 17 00:00:00 2001 From: Moritz Clasmeier Date: Mon, 20 Apr 2026 20:05:25 +0200 Subject: [PATCH 2/2] Removed references to git commit from docker build workflow --- .github/workflows/docker-build.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 92a3c24..2442925 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -46,7 +46,6 @@ jobs: id: build-meta run: | echo "version=$(make version)" >> $GITHUB_OUTPUT - echo "git_commit=$(make get-commit-hash)" >> $GITHUB_OUTPUT echo "build_date=$(make get-build-date)" >> $GITHUB_OUTPUT - name: Extract metadata (tags, labels) for Docker @@ -71,7 +70,6 @@ jobs: labels: ${{ steps.meta.outputs.labels }} build-args: | ROXIE_VERSION=${{ steps.build-meta.outputs.version }} - GIT_COMMIT=${{ steps.build-meta.outputs.git_commit }} BUILD_DATE=${{ steps.build-meta.outputs.build_date }} cache-from: | type=gha