From 5c4c19bf196a7ddad3b0dca8962723fc1c35c232 Mon Sep 17 00:00:00 2001 From: Phillip Wittrock Date: Fri, 8 Nov 2019 15:48:06 -0800 Subject: [PATCH] Script to update pseudo references --- pseudo/update-fork-references.sh | 78 ++++++++++++++++++++++++++++++++ travis/verify-deps.sh | 24 +++++----- 2 files changed, 91 insertions(+), 11 deletions(-) create mode 100755 pseudo/update-fork-references.sh diff --git a/pseudo/update-fork-references.sh b/pseudo/update-fork-references.sh new file mode 100755 index 000000000..889d14811 --- /dev/null +++ b/pseudo/update-fork-references.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +set -e +set -o xtrace + +# replace the module name with the new module name +function replaceModuleName { + find . -name *.go | xargs sed -i -e "s!k8s.io/$1!sigs.k8s.io/kustomize/pseudo/k8s/$1!g" + find . -name *.proto | xargs sed -i -e "s!k8s.io/$1!sigs.k8s.io/kustomize/pseudo/k8s/$1!g" + find . -name *.md | xargs sed -i -e "s!k8s.io/$1!sigs.k8s.io/kustomize/pseudo/k8s/$1!g" +} + +# update the go.mod file, dropping the old module +function updateGoModFile { + go mod edit -droprequire=k8s.io/$1 || echo "" + rm go.sum || echo "" +} + +# test the module +function testGoMod { + go test ./... + gofmt -s -w . + go mod tidy +} + +# update all go.mod files +function updateAllGoModFiles { + (cd api; updateGoModFile $1 ) + (cd kustomize; updateGoModFile $1 ) + (cd hack/crawl; updateGoModFile $1 ) + (cd pluginator; updateGoModFile $1 ) + + for goMod in $(find ./plugin/builtin -name 'go.mod'); do + dir=$(dirname "${goMod}") + (cd $dir; updateGoModFile $1 ) + done + + for goMod in $(find ./plugin/someteam.example.com/v1 -name 'go.mod'); do + dir=$(dirname "${goMod}") + (cd $dir; updateGoModFile $1 ) + done +} + +# test all go modules +function testAllModules { + (cd api; testGoMod) + (cd kustomize; testGoMod) + (cd hack/crawl; testGoMod) + (cd pluginator; testGoMod ) + + for goMod in $(find ./plugin/builtin -name 'go.mod'); do + dir=$(dirname "${goMod}") + (cd $dir; testGoMod ) + done + +# Uncomment this when tests are added for this module +# for goMod in $(find ./plugin/someteam.example.com/v1 -name 'go.mod'); do +# dir=$(dirname "${goMod}") +# (cd $dir; testGoMod ) +# done +} + +# update the names of the modules +for item in api apimachinery client-go +do + replaceModuleName $item +done + +# update the go.mod files +for item in api apimachinery client-go +do + updateAllGoModFiles $item +done + +# test all of the modules still work +testAllModules + +./travis/verify-deps.sh \ No newline at end of file diff --git a/travis/verify-deps.sh b/travis/verify-deps.sh index 4a84dcda4..9277d5ff6 100755 --- a/travis/verify-deps.sh +++ b/travis/verify-deps.sh @@ -2,15 +2,17 @@ set -o xtrace -for item in api apimachinery client-go +for dir in api kustomize pseudo kyaml plugin do - if find pseudo -name 'go.*' | xargs grep "k8s.io/${item}" ; then - echo "forbidden deps" - exit 1 - fi - if find pseudo -name '*.go' | xargs grep "k8s.io/${item}" ; then - echo "forbidden deps" - exit 1 - fi -done - + for item in api apimachinery client-go + do + if find $dir -name 'go.*' | xargs grep "k8s.io/${item}" ; then + echo "forbidden deps" + exit 1 + fi + if find $dir -name '*.go' | xargs grep "k8s.io/${item}" ; then + echo "forbidden deps" + exit 1 + fi + done +done \ No newline at end of file