From 797e3f90c744c843369e9f8ae411258fc264a85b Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Thu, 24 Oct 2024 11:55:30 +0200 Subject: [PATCH] ci: on release check git version matches release version in code Signed-off-by: Eguzki Astiz Lezaun --- .../build-images-for-tag-release.yaml | 12 +++++++++++ Makefile | 21 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-images-for-tag-release.yaml b/.github/workflows/build-images-for-tag-release.yaml index 954d706..837802a 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/Makefile b/Makefile index cad748e..ed77d9d 100644 --- a/Makefile +++ b/Makefile @@ -343,6 +343,17 @@ YQ = $(LOCALBIN)/yq GINKGO ?= $(LOCALBIN)/ginkgo GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint HELM ?= $(LOCALBIN)/helm +ifeq ($(shell uname),Darwin) +SED=$(shell which gsed) +else +SED=$(shell which sed) +endif +.PHONY: sed +sed: ## Checks if GNU sed is installed +ifeq ($(SED),) + @echo "Cannot find GNU sed installed." + exit 1 +endif ## Tool Versions KUSTOMIZE_VERSION ?= v5.0.1 @@ -532,7 +543,15 @@ prepare-release: ## Generates a makefile that will override environment variable VERSION=$(VERSION)\nREPLACES_VERSION=$(REPLACES_VERSION)" > $(RELEASE_FILE) $(MAKE) bundle $(MAKE) helm-build VERSION=$(VERSION) - sed -i -e 's/Version = ".*"/Version = "$(VERSION)"/' $(PROJECT_PATH)/internal/version/version.go + $(MAKE) update-release-version VERSION=$(VERSION) + +.PHONY: read-version +read-release-version: ## Reads release version + @$(SED) -n 's/^.*Version = "\([^"]*\)".*/\1/p' $(PROJECT_PATH)/internal/version/version.go + +.PHONY: update-release-version +update-release-version: ## Updates release version to $(VERSION) + $(SED) -i -e 's/Version = ".*"/Version = "$(VERSION)"/' $(PROJECT_PATH)/internal/version/version.go # Include last to avoid changing MAKEFILE_LIST used above include ./make/*.mk