-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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>
- Loading branch information
1 parent
00b0bd8
commit d91e31c
Showing
2 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |