From 67af093753fac0c1fed6b45c17406c29e652d4cf Mon Sep 17 00:00:00 2001 From: Anna Song Date: Thu, 12 Jan 2023 11:19:45 -0800 Subject: [PATCH 1/2] Remove go module ci job --- Makefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1a1aaff581..78be684b0f 100644 --- a/Makefile +++ b/Makefile @@ -108,10 +108,19 @@ verify-kustomize-repo: \ prow-presubmit-check: \ install-tools \ test-unit-kustomize-plugins \ - test-go-mod \ build-non-plugin-all \ test-examples-kustomize-against-HEAD \ test-examples-kustomize-against-v4-release + # TODO(annasong): Find permanent solution. + # We have temporarily commented out this job because it fails for public + # cross-module changes, given that we've removed replace directives with go + # workspace and the job runs on the latest released modules. This + # complicates releases. + # This job is also less effective than intended because it only detects + # go mod tidy errors, instead of any changes to the original code that + # go mod tidy makes. + + # test-go-mod .PHONY: license license: $(MYGOBIN)/addlicense From 4a962c8e1617fe1c4e0020c1f6852bf2df4f80b6 Mon Sep 17 00:00:00 2001 From: Anna Song Date: Tue, 24 Jan 2023 15:04:57 -0800 Subject: [PATCH 2/2] Add script that runs go mod tidy with replace statements --- Makefile | 15 ++++----------- hack/dropReplace.sh | 9 +++++++++ hack/replace.sh | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 11 deletions(-) create mode 100755 hack/dropReplace.sh create mode 100755 hack/replace.sh diff --git a/Makefile b/Makefile index 78be684b0f..2acd9fe76b 100644 --- a/Makefile +++ b/Makefile @@ -108,19 +108,10 @@ verify-kustomize-repo: \ prow-presubmit-check: \ install-tools \ test-unit-kustomize-plugins \ + test-go-mod \ build-non-plugin-all \ test-examples-kustomize-against-HEAD \ test-examples-kustomize-against-v4-release - # TODO(annasong): Find permanent solution. - # We have temporarily commented out this job because it fails for public - # cross-module changes, given that we've removed replace directives with go - # workspace and the job runs on the latest released modules. This - # complicates releases. - # This job is also less effective than intended because it only detects - # go mod tidy errors, instead of any changes to the original code that - # go mod tidy makes. - - # test-go-mod .PHONY: license license: $(MYGOBIN)/addlicense @@ -161,7 +152,9 @@ functions-examples-all: done test-go-mod: - ./hack/for-each-module.sh "go list -m -json all > /dev/null && go mod tidy -v" + ./hack/for-each-module.sh $$(pwd)/hack/replace.sh; \ + ./hack/for-each-module.sh "go mod tidy -v"; \ + ./hack/for-each-module.sh $$(pwd)/hack/dropReplace.sh .PHONY: verify-kustomize-e2e: $(MYGOBIN)/mdrip $(MYGOBIN)/kind diff --git a/hack/dropReplace.sh b/hack/dropReplace.sh new file mode 100755 index 0000000000..47603464b5 --- /dev/null +++ b/hack/dropReplace.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# Copyright 2023 The Kubernetes Authors. +# SPDX-License-Identifier: Apache-2.0 + +read -a modules <<< $(go list -m) + +for i in ${!modules[@]}; do + go mod edit -dropreplace=${modules[i]} +done \ No newline at end of file diff --git a/hack/replace.sh b/hack/replace.sh new file mode 100755 index 0000000000..04e42b110a --- /dev/null +++ b/hack/replace.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Copyright 2023 The Kubernetes Authors. +# SPDX-License-Identifier: Apache-2.0 + +read -a modules <<< $(go list -m) +read -a module_paths <<< $(go list -m -f {{.Dir}}) + +for i in ${!modules[@]}; do + replace_path=$(realpath --relative-to=$(pwd) ${module_paths[i]}) + if [ $replace_path == . ]; then + continue + fi + go mod edit -replace=${modules[i]}=$replace_path +done \ No newline at end of file