From 2abf8c73dcf361f8958a1dd42d1431f807898acf Mon Sep 17 00:00:00 2001 From: huanghaoyuanhhy Date: Tue, 25 Feb 2025 19:43:51 +0800 Subject: [PATCH] *: improve build workflow (#555) Signed-off-by: huanghaoyuanhhy --- .github/workflows/release.yaml | 2 -- .goreleaser.yaml | 10 +++++----- Dockerfile | 3 +-- Makefile | 12 ++++++------ 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 5a8e0c69..24a85206 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -65,7 +65,6 @@ jobs: run: | echo "VERSION=$(git describe --tags --always)" >> $GITHUB_OUTPUT echo "COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - echo "DATE=$(date +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT - name: Build and push uses: docker/build-push-action@v6 @@ -79,4 +78,3 @@ jobs: build-args: | VERSION=${{ steps.build_info.outputs.VERSION }} COMMIT=${{ steps.build_info.outputs.COMMIT }} - DATE=${{ steps.build_info.outputs.DATE }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 5d03e152..c8282df8 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -16,12 +16,12 @@ builds: - arm64 ldflags: - -w -s - - -X main.version={{ .Version }} - - -X main.commit={{ .Commit }} - - -X main.date={{ .Date }} + - -X github.com/zilliztech/milvus-backup/version.Version={{ .Version }} + - -X github.com/zilliztech/milvus-backup/version.Commit={{ .Commit }} + - -X github.com/zilliztech/milvus-backup/version.Date={{ .Date }} archives: - - format: tar.gz + - formats: ['tar.gz'] # this name template makes the OS and Arch compatible with the results of uname. name_template: >- {{ .ProjectName }}_ @@ -33,7 +33,7 @@ archives: checksum: name_template: "checksums.txt" snapshot: - name_template: "{{ incpatch .Version }}-next" + version_template: "{{ incpatch .Version }}-next" brews: - name: milvus-backup diff --git a/Dockerfile b/Dockerfile index a6098ab6..24087e81 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,14 +4,13 @@ ENV CGO_ENABLED=0 ARG VERSION=0.0.1 ARG COMMIT=unknown -ARG DATE=unknown WORKDIR /app COPY go.mod go.sum ./ RUN go mod download COPY . . -RUN go build -ldflags="-X 'main.version=$VERSION' -X 'main.commit=$COMMIT' -X 'main.date=$DATE'" -o /app/milvus-backup +RUN make build FROM alpine:3.17 diff --git a/Makefile b/Makefile index e37d93d5..0989d82b 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ # Variables BINARY_NAME=milvus-backup PKG := github.com/zilliztech/milvus-backup -VERSION=$(shell git describe --tags --always) -COMMIT=$(shell git rev-parse --short HEAD) +BUILD_VERSION=$(if $(VERSION),$(VERSION),$(shell git describe --tags --always)) +BUILD_COMMIT=$(if $(COMMIT),$(COMMIT),$(shell git rev-parse --short HEAD)) DATE=$(shell date -u '+%Y-%m-%dT%H:%M:%SZ') -LDFLAGS += -X "$(PKG)/version.Version=$(VERSION)" -LDFLAGS += -X "$(PKG)/version.Commit=$(COMMIT)" +LDFLAGS += -X "$(PKG)/version.Version=$(BUILD_VERSION)" +LDFLAGS += -X "$(PKG)/version.Commit=$(BUILD_COMMIT)" LDFLAGS += -X "$(PKG)/version.Date=$(DATE)" # Default target @@ -19,8 +19,8 @@ test: # Build the binary build: @echo "Building Backup binary..." - @echo "Version: $(VERSION)" - @echo "Commit: $(COMMIT)" + @echo "Version: $(BUILD_VERSION)" + @echo "Commit: $(BUILD_COMMIT)" @echo "Date: $(DATE)" @GO111MODULE=on CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o $(BINARY_NAME)