Skip to content

Commit

Permalink
Merge pull request #278 from Kuadrant/ci-update-check-version-string
Browse files Browse the repository at this point in the history
ci: on release check version string is the expected one
  • Loading branch information
eguzki authored Oct 29, 2024
2 parents 7036b3f + f8b971f commit 2bf9520
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 28 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/build-images-for-tag-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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 (
Expand All @@ -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() {
Expand Down
21 changes: 0 additions & 21 deletions internal/version/version.go

This file was deleted.

0 comments on commit 2bf9520

Please sign in to comment.