Skip to content

Commit

Permalink
Add script that runs go mod tidy with replace statements
Browse files Browse the repository at this point in the history
  • Loading branch information
annasong20 committed Jan 24, 2023
1 parent cc72dc1 commit 7a64e19
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
13 changes: 2 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -161,7 +152,7 @@ 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/test-go-mod.sh

.PHONY:
verify-kustomize-e2e: $(MYGOBIN)/mdrip $(MYGOBIN)/kind
Expand Down
20 changes: 20 additions & 0 deletions hack/test-go-mod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/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

go mod tidy -v

for i in ${!modules[@]}; do
go mod edit -dropreplace=${modules[i]}
done

0 comments on commit 7a64e19

Please sign in to comment.