diff --git a/.github/workflows/build-images-for-tag-release.yaml b/.github/workflows/build-images-for-tag-release.yaml index 954d7060..837802a3 100644 --- a/.github/workflows/build-images-for-tag-release.yaml +++ b/.github/workflows/build-images-for-tag-release.yaml @@ -21,6 +21,18 @@ jobs: - name: Check out code uses: actions/checkout@v4 + - name: Read release string version + id: release + run: | + version=`make read-release-version` + echo version=$version >> $GITHUB_OUTPUT + + - name: Print tags + run: echo "Git reference name = ${{ github.ref_name }}, release version = ${{ steps.release.outputs.version }}" + - name: Verify git reference name matches the release version + if: ${{ github.ref_name != steps.release.outputs.version }} + run: exit 1 + - name: Install qemu dependency run: | sudo apt-get update diff --git a/Dockerfile b/Dockerfile index 89a97101..5700cef2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,10 +5,11 @@ ARG TARGETARCH ARG GIT_SHA ARG DIRTY +ARG VERSION ENV GIT_SHA=${GIT_SHA:-unknown} ENV DIRTY=${DIRTY:-unknown} - +ENV VERSION=${VERSION:-unknown} WORKDIR /workspace # Copy the Go Modules manifests @@ -27,7 +28,7 @@ COPY internal/ internal/ # was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO # the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore, # by leaving it empty we can ensure that the container and binary shipped on it will have the same platform. -RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" -a -o manager cmd/main.go +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -ldflags "-X main.version=v${VERSION} -X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" -a -o manager cmd/main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details diff --git a/Makefile b/Makefile index b4097c50..97b17291 100644 --- a/Makefile +++ b/Makefile @@ -233,19 +233,19 @@ local-deploy-namespaced: docker-build kind-load-image ## Deploy the dns operator build: GIT_SHA=$(shell git rev-parse HEAD || echo "unknown") build: DIRTY=$(shell hack/check-git-dirty.sh || echo "unknown") build: manifests generate fmt vet ## Build manager binary. - go build -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" -o bin/manager cmd/main.go + go build -ldflags "-X main.version=v${VERSION} -X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" -o bin/manager cmd/main.go .PHONY: run run: GIT_SHA=$(shell git rev-parse HEAD || echo "unknown") run: DIRTY=$(shell hack/check-git-dirty.sh || echo "unknown") run: manifests generate fmt vet ## Run a controller from your host. - go run -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" --race ./cmd/main.go --zap-devel --provider inmemory,aws,google,azure + go run -ldflags "-X main.version=v${VERSION} -X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" --race ./cmd/main.go --zap-devel --provider inmemory,aws,google,azure .PHONY: run-with-probes run-with-probes: GIT_SHA=$(shell git rev-parse HEAD || echo "unknown") run-with-probes: DIRTY=$(shell hack/check-git-dirty.sh || echo "unknown") run-with-probes: manifests generate fmt vet ## Run a controller from your host. - go run -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" --race ./cmd/main.go --zap-devel --provider inmemory,aws,google,azure + go run -ldflags "-X main.version=v${VERSION} -X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" --race ./cmd/main.go --zap-devel --provider inmemory,aws,google,azure # If you wish built the manager image targeting other platforms you can use the --platform flag. # (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it. @@ -528,6 +528,9 @@ prepare-release: ## Generates a makefile that will override environment variable $(MAKE) bundle $(MAKE) helm-build VERSION=$(VERSION) +.PHONY: read-release-version +read-release-version: ## Reads release version + @echo "v$(VERSION)" # Include last to avoid changing MAKEFILE_LIST used above include ./make/*.mk diff --git a/cmd/main.go b/cmd/main.go index f8c44985..fb90b681 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -42,7 +42,6 @@ import ( _ "github.com/kuadrant/dns-operator/internal/provider/azure" _ "github.com/kuadrant/dns-operator/internal/provider/google" _ "github.com/kuadrant/dns-operator/internal/provider/inmemory" - "github.com/kuadrant/dns-operator/internal/version" //+kubebuilder:scaffold:imports ) @@ -51,6 +50,7 @@ var ( setupLog = ctrl.Log.WithName("setup") gitSHA string // pass ldflag here to display gitSHA hash dirty string // must be string as passed in by ldflag to determine display . + version string // must be string as passed in by ldflag to determine display . ) const ( @@ -67,7 +67,7 @@ func init() { } func printControllerMetaInfo() { - setupLog.Info("build information", "version", version.Version, "commit", gitSHA, "dirty", dirty) + setupLog.Info("build information", "version", version, "commit", gitSHA, "dirty", dirty) } func main() { diff --git a/internal/version/version.go b/internal/version/version.go deleted file mode 100644 index e8a5d0db..00000000 --- a/internal/version/version.go +++ /dev/null @@ -1,21 +0,0 @@ -/* -Copyright 2021 Red Hat, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package version - -var ( - // This variable is dependent on what the current release is e.g. if it is v0.10.0 then this variable, outside of releases, will be v0.10.1-dev . - Version = "0.4.0-dev" // Change as versions are released -)