Last active
May 15, 2021 00:10
-
-
Save brandond/1b3cb66ea012564f886e2e9982bdce42 to your computer and use it in GitHub Desktop.
K3s => RKE2 go.mod replacement sync script
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
#!/bin/bash | |
K3S_VERSION=$(go mod edit --json | jq -r '.Require[] | select(.Path | contains("rancher/k3s")) | .Version') | |
K3S_COMMIT=$(grep -oE '\w{12}$' <<< ${K3S_VERSION}) | |
K3S_GO_MOD=$(curl -qsL "https://raw.githubusercontent.com/k3s-io/k3s/${K3S_COMMIT}/go.mod") | |
echo "Updating go.mod replacements from k3s ${K3S_VERSION}" | |
for MODPATH in $(go mod edit --json | jq -r '.Replace[] | .Old.Path'); do | |
REPLACEMENT=$(go mod edit --json /dev/stdin <<<${K3S_GO_MOD} | jq -r --arg MODPATH "${MODPATH}" '.Replace[] | select(.Old.Path==$MODPATH) | .Old.Path + "=" + .New.Path + "@" + .New.Version') | |
if [ -n "${REPLACEMENT}" ]; then | |
go mod edit --replace=${REPLACEMENT} | |
fi | |
done | |
go mod tidy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment