Skip to content

Instantly share code, notes, and snippets.

@bartoszmajsak
Last active October 25, 2022 20:17
Show Gist options
  • Save bartoszmajsak/9359068bc8cead002a2fcf1ff947ad09 to your computer and use it in GitHub Desktop.
Save bartoszmajsak/9359068bc8cead002a2fcf1ff947ad09 to your computer and use it in GitHub Desktop.
xns-informers deps update
#!/bin/bash
set -eo pipefail
die () {
echo >&2 "$@"
show_help
exit 1
}
show_help() {
local usage
usage="
$(basename "$0")
Usage:
./$(basename "$0") [flags]
Options:
--version of istio/istio upstream project from which go.mod is used
-h, --help
Help message.
Example:
./$(basename "$0") --version 1.15.2
"
echo "$usage"
}
function header {
echo -e "\n\e[92m\e[4m\e[1m${1}\e[0m\n"
}
function hasDepToReplace {
local value=$1
local deps=$2
for dep in "${deps[@]}"; do
found=$(echo "$dep" | grep "$value" || true)
if [ -n "$found" ]; then
return 0
fi
done
return 1
}
while test $# -gt 0; do
case "$1" in
-h|--help)
show_help
exit 0
;;
--version)
if [[ $1 == "--"* ]]; then
version="${2/--/}"
shift
fi
shift
;;
*)
die "$(basename "$0"): unknown flag $(echo $1 | cut -d'=' -f 1)"
exit 1
;;
esac
done
if [ -z "$version" ]; then
die "Missing version"
fi
if ! command -v curl &>/dev/null; then
echo "curl is required"
exit 1
fi
if ! command -v deptree &>/dev/null; then
echo "deptree is required. $ go install github.com/vc60er/deptree@latest"
exit 1
fi
istioDeps=$(curl -s https://raw.githubusercontent.com/istio/istio/${version}/go.mod)
mapfile -t deps < <(go mod graph | deptree -d 1 | cut -d' ' -f 2 | tr -s '\n' | sort | grep -v "tree:")
mapfile -t replaceDeps < <(echo "${istioDeps}" | grep -Po 'replace \K.*')
header "Updating deps:"
for dep in "${deps[@]}"; do
lib="${dep%@*}"
istioDep=$(echo "${istioDeps}" | grep -v "replace" | grep "${lib} " || true)
if [ -n "$istioDep" ]; then
newVersion=${istioDep#*\ }
echo "go mod edit -require=${lib}@${newVersion%"// indirect"}"
go mod edit -require=${lib}@${newVersion%"// indirect"}
fi
done
header "Adding explicit replaces:"
for dep in "${replaceDeps[@]}"; do
name=${dep%%\ *}
newVersion=${dep##*\ }
hasDepToReplace "${name}" "${deps[*]}"
if [[ $? -eq 0 ]]; then
echo "go mod edit -replace ${name}=${name}@${newVersion}"
go mod edit -replace=${name}=${name}@${newVersion}
fi
done
@bartoszmajsak
Copy link
Author

bartoszmajsak commented Oct 25, 2022

❯ ./align-deps.sh --version 1.15.2

Updating deps:

go mod edit -require=cloud.google.com/[email protected] 
go mod edit -require=github.com/Azure/go-autorest/autorest/[email protected] 
go mod edit -require=github.com/Azure/go-autorest/autorest/[email protected] 
go mod edit -require=github.com/Azure/go-autorest/[email protected] 
go mod edit -require=github.com/Azure/go-autorest/[email protected] 
go mod edit -require=github.com/Azure/go-autorest/[email protected] 
go mod edit -require=github.com/Azure/[email protected]+incompatible 
go mod edit -require=github.com/davecgh/[email protected]
go mod edit -require=github.com/evanphx/[email protected]+incompatible 
go mod edit -require=github.com/gogo/[email protected]
go mod edit -require=github.com/golang/[email protected]
go mod edit -require=github.com/go-logr/[email protected] 
go mod edit -require=github.com/google/[email protected] 
go mod edit -require=github.com/google/[email protected]
go mod edit -require=github.com/google/[email protected]
go mod edit -require=github.com/go-openapi/[email protected] 
go mod edit -require=github.com/go-openapi/[email protected] 
go mod edit -require=github.com/go-openapi/[email protected] 
go mod edit -require=github.com/imdario/[email protected] 
go mod edit -require=github.com/josharian/[email protected] 
go mod edit -require=github.com/json-iterator/[email protected] 
go mod edit -require=github.com/mailru/[email protected] 
go mod edit -require=github.com/modern-go/[email protected] 
go mod edit -require=github.com/modern-go/[email protected] 
go mod edit -require=github.com/munnerz/[email protected] 
go mod edit -require=github.com/pkg/[email protected] 
go mod edit -require=github.com/pmezard/[email protected]
go mod edit -require=github.com/PuerkitoBio/[email protected] 
go mod edit -require=github.com/PuerkitoBio/[email protected] 
go mod edit -require=github.com/spf13/[email protected]
go mod edit -require=github.com/stretchr/[email protected] 
go mod edit -require=golang.org/x/[email protected] 
go mod edit -require=golang.org/x/[email protected]
go mod edit -require=golang.org/x/[email protected] 
go mod edit -require=golang.org/x/[email protected]
go mod edit -require=golang.org/x/[email protected]
go mod edit -require=golang.org/x/[email protected]
go mod edit -require=golang.org/x/[email protected] 
go mod edit -require=golang.org/x/[email protected] 
go mod edit -require=golang.org/x/[email protected]
go mod edit -require=golang.org/x/[email protected] 
go mod edit -require=golang.org/x/[email protected] 
go mod edit -require=google.golang.org/[email protected] 
go mod edit -require=google.golang.org/[email protected]
go mod edit -require=google.golang.org/[email protected]
go mod edit -require=gopkg.in/[email protected] 
go mod edit -require=gopkg.in/[email protected]
go mod edit -require=gopkg.in/[email protected]
go mod edit -require=istio.io/[email protected]
go mod edit -require=istio.io/[email protected]
go mod edit -require=k8s.io/[email protected]
go mod edit -require=k8s.io/[email protected]
go mod edit -require=k8s.io/[email protected]
go mod edit -require=k8s.io/klog/[email protected]
go mod edit -require=k8s.io/[email protected]
go mod edit -require=k8s.io/[email protected]
go mod edit -require=sigs.k8s.io/[email protected]
go mod edit -require=sigs.k8s.io/[email protected]
go mod edit -require=sigs.k8s.io/[email protected] 
go mod edit -require=sigs.k8s.io/structured-merge-diff/[email protected] 
go mod edit -require=sigs.k8s.io/[email protected]

Adding explicit replaces:

go mod edit -replace github.com/imdario/mergo=github.com/imdario/[email protected]
go mod edit -replace sigs.k8s.io/gateway-api=sigs.k8s.io/[email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment