mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 10:15:22 +00:00
Run test-go-mod unpinned (#5011)
* Remove go module ci job * Add script that runs go mod tidy with replace statements * Invoke one script from the makefile and pass in the command to run in the pinned context --------- Co-authored-by: Anna Song <annasong@google.com>
This commit is contained in:
2
Makefile
2
Makefile
@@ -152,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 "\$$KUSTOMIZE_ROOT/hack/with-unpinned-kust-dev.sh 'go mod tidy -v'"
|
||||
|
||||
.PHONY:
|
||||
verify-kustomize-e2e: $(MYGOBIN)/mdrip $(MYGOBIN)/kind
|
||||
|
||||
50
hack/with-unpinned-kust-dev.sh
Executable file
50
hack/with-unpinned-kust-dev.sh
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2023 The Kubernetes Authors.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
set -x
|
||||
set -e
|
||||
set -o pipefail
|
||||
set -o nounset
|
||||
|
||||
# This script uses 'replace' statements to 'unpin' local modules from module versions go.mod normally
|
||||
# requires, so that the local version will be used instead. With the advent of Workspace mode, we no longer
|
||||
# need to do this in general in between releases. However, some key commands like `go mod tidy` are not
|
||||
# Workspace-aware and thus will fail if API changes between modules exist on master. This script allows us to
|
||||
# test those commands without requiring unpin operations in our release workflow.
|
||||
|
||||
if [[ -z "${1-}" ]] ; then
|
||||
echo "Usage: $0 <cmd>"
|
||||
echo "Example: $0 'go mod tidy -v'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cmd=$1
|
||||
|
||||
# First we read in the list of all kustomize modules and their local locations. The data looks like:
|
||||
# sigs.k8s.io/kustomize/api /Users/you/src/sigs.k8s.io/kustomize/api
|
||||
# sigs.k8s.io/kustomize/cmd/config /Users/you/src/sigs.k8s.io/kustomize/cmd/config
|
||||
IFS=$'\n'
|
||||
modules=($(go list -m -f "{{.Path}} {{.Dir}}"))
|
||||
|
||||
# Next we iterate over the lines, split apart the module name and local absolute path,
|
||||
# and add a relative-path replace statement to the go.mod. A replace statement will be added
|
||||
# for each Kustomize module, whether or not the current module uses it.
|
||||
IFS=" "
|
||||
replace_args=""
|
||||
for module in "${modules[@]}"; do
|
||||
read -a module_data <<< $module
|
||||
replace_path=$(realpath --relative-to=$(pwd) ${module_data[1]})
|
||||
if [ $replace_path == . ] || [[ $replace_path == internal/* ]]; then
|
||||
continue
|
||||
fi
|
||||
replace_args+=" -replace=${module_data[0]}=$replace_path"
|
||||
done
|
||||
|
||||
go mod edit $replace_args
|
||||
|
||||
# Now that the modules are pinned, we run the command passed to this script.
|
||||
bash -c "$cmd"
|
||||
|
||||
# Finally we clean up by dropping the replace statements we added above.
|
||||
go mod edit $(sed 's/-replace/-dropreplace/g' <<< "$replace_args" | sed -E 's/=\.\.[^[:space:]]*//g')
|
||||
Reference in New Issue
Block a user