From 18f0638902c486f8195d158a928c8dd8843c3c28 Mon Sep 17 00:00:00 2001 From: oraz Date: Sun, 16 Jun 2024 09:10:53 +0300 Subject: [PATCH 1/2] 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 d55e553282b..cade78041fa 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 358d8c753de..50e2149e6af 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 454a676e82b..819ef5fa695 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 From 9bdf795c4f46e62ea5a548f256e00f33e9821c0f Mon Sep 17 00:00:00 2001 From: oraz Date: Sun, 16 Jun 2024 09:12:10 +0300 Subject: [PATCH 2/2] Update documentation on go-verify changes Update makefile and one doc file docomentation with the change of go-verify over using vendor and tidy --- docs/updating-dependencies.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/updating-dependencies.md b/docs/updating-dependencies.md index 83a574481b9..56b00bbec31 100644 --- a/docs/updating-dependencies.md +++ b/docs/updating-dependencies.md @@ -21,8 +21,7 @@ The reason for calling script instead of directly calling: ```bash go get -u ./... -go mod tidy -compat=1.20 -go mod vendor +make go-verify ``` is that packages modified in this script do not fully support modules and @@ -43,8 +42,7 @@ the PR, one can simply call go get @ OR go get -u @ -go mod tidy -compat=1.20 -go mod vendor +make go-verify ``` --- @@ -52,8 +50,8 @@ go mod vendor **NOTE** vendoring is required as ARO mirrors all dependencies locally for the CI reliability and reproducibility. -**NOTE** that when running `go mod vendor` only modules that are used in the -source code will be vendored in. +**NOTE** that running `make go-verify` adds missing (and remove unused) modules, +make a vendored copy to the *vendor* direcory and then verifies that the dependencies have expected content. **NOTE** when updating a package modified in `hack/update-go-module-dependencies.sh` changes have to be made there also. Otherwise next run of `make vendor` will