From 5e40a61a61fcac0db29bad875378d10f7ec80fb1 Mon Sep 17 00:00:00 2001 From: oraz Date: Sun, 16 Jun 2024 09:10:53 +0300 Subject: [PATCH] Add new makefile targets for go mod verification Run 'go mod' functions to search for tidy, vendor changes and verify it --- .github/workflows/ci-go.yml | 3 +-- Makefile | 16 ++++++++++++++++ hack/update-go-module-dependencies.sh | 2 -- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-go.yml b/.github/workflows/ci-go.yml index d55e55328..cade78041 100644 --- a/.github/workflows/ci-go.yml +++ b/.github/workflows/ci-go.yml @@ -37,8 +37,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - run: | - go mod vendor - go mod tidy -compat=1.20 + make go-verify hack/ci-utils/isClean.sh generate-check: diff --git a/Makefile b/Makefile index 358d8c753..50e2149e6 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,9 @@ AUTOREST_IMAGE = quay.io/openshift-on-azure/autorest:${AUTOREST_VERSION} GATEKEEPER_VERSION = v3.15.1 GOTESTSUM = gotest.tools/gotestsum@v1.11.0 +# Golang version go mod tidy compatibility +GOLANG_VERSION ?= 1.20 + ifneq ($(shell uname -s),Darwin) export CGO_CFLAGS=-Dgpgme_off_t=off_t endif @@ -334,10 +337,23 @@ admin.kubeconfig: aks.kubeconfig: hack/get-admin-aks-kubeconfig.sh +.PHONY: go-tidy +go-tidy: # Run go mod tidy - add missing and remove unused modules. + go mod tidy -compat=${GOLANG_VERSION} + +.PHONY: go-vendor +go-vendor: # Run go mod vendor - only modules that are used in the source code will be vendored in (make vendored copy of dependencies). + go mod vendor + +.PHONY: go-verify +go-verify: go-tidy go-vendor # Run go mod verify - verify dependencies have expected content + go mod verify + .PHONY: vendor vendor: # See comments in the script for background on why we need it hack/update-go-module-dependencies.sh + $(MAKE) go-verify .PHONY: install-go-tools install-go-tools: diff --git a/hack/update-go-module-dependencies.sh b/hack/update-go-module-dependencies.sh index 454a676e8..819ef5fa6 100755 --- a/hack/update-go-module-dependencies.sh +++ b/hack/update-go-module-dependencies.sh @@ -41,5 +41,3 @@ done go get -u ./... -go mod tidy -compat=1.20 -go mod vendor