Add godeps hack scripts

pull/1363/head
Matt Rickard 2017-04-11 15:22:01 -07:00
parent 2015d0a7d8
commit 184d9461df
4 changed files with 227 additions and 0 deletions

43
hack/godeps/godep-restore.sh Executable file
View File

@ -0,0 +1,43 @@
#!/bin/bash
# Copyright 2016 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
K8S_ORG_ROOT=${GOPATH}/src/k8s.io
MINIKUBE_ROOT=${K8S_ORG_ROOT}/minikube
KUBE_ROOT=${K8S_ORG_ROOT}/kubernetes
KUBE_VERSION=$(python ${MINIKUBE_ROOT}/hack/get_k8s_version.py --k8s-version-only 2>&1)
source ${MINIKUBE_ROOT}/hack/godeps/utils.sh
godep::ensure_godep_version v79
# We can't 'go get kubernetes' so this hack is here
mkdir -p ${K8S_ORG_ROOT}
if [ ! -d "${KUBE_ROOT}" ]; then
pushd ${#GOPATH} >/dev/null
git clone https://github.com/kubernetes/kubernetes.git
popd >/dev/null
fi
pushd ${KUBE_ROOT} >/dev/null
git checkout ${KUBE_VERSION}
godep restore ./...
popd >/dev/null
godep::sync_staging
pushd ${MINIKUBE_ROOT} >/dev/null
godep restore ./...
popd >/dev/null

33
hack/godeps/godep-save.sh Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
# Copyright 2016 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
MINIKUBE_ROOT=${GOPATH}/src/k8s.io/minikube
KUBE_ROOT=${GOPATH}/src/k8s.io/kubernetes
source ${MINIKUBE_ROOT}/hack/godeps/utils.sh
godep::ensure_godep_version v79
godep::sync_staging
rm -rf ${MINIKUBE_ROOT}/vendor ${MINIKUBE_ROOT}/Godeps
godep save ./...
godep::remove_staging_from_json
git checkout -- ${MINIKUBE_ROOT}/vendor/golang.org/x/sys/windows

View File

@ -0,0 +1,94 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"encoding/json"
"log"
"os"
"strings"
flag "github.com/spf13/pflag"
)
var (
godepsFile = flag.String("godeps-file", "", "absolute path to Godeps.json")
)
var ignoredPrefixes = []string{
"k8s.io/client-go",
"k8s.io/apimachinery",
"k8s.io/apiserver",
}
type Dependency struct {
ImportPath string
Comment string `json:",omitempty"`
Rev string
}
type Godeps struct {
ImportPath string
GoVersion string
GodepVersion string
Packages []string `json:",omitempty"` // Arguments to save, if any.
Deps []Dependency
}
func main() {
flag.Parse()
var g Godeps
if len(*godepsFile) == 0 {
log.Fatalf("absolute path to Godeps.json is required")
}
f, err := os.OpenFile(*godepsFile, os.O_RDWR, 0666)
if err != nil {
log.Fatalf("cannot open file %q: %v", *godepsFile, err)
}
defer f.Close()
err = json.NewDecoder(f).Decode(&g)
if err != nil {
log.Fatalf("Unable to parse %q: %v", *godepsFile, err)
}
i := 0
for _, dep := range g.Deps {
ignored := false
for _, ignoredPrefix := range ignoredPrefixes {
if strings.HasPrefix(dep.ImportPath, ignoredPrefix) {
ignored = true
}
}
if ignored {
continue
}
g.Deps[i] = dep
i++
}
g.Deps = g.Deps[:i]
b, err := json.MarshalIndent(g, "", "\t")
if err != nil {
log.Fatal(err)
}
n, err := f.WriteAt(append(b, '\n'), 0)
if err != nil {
log.Fatal(err)
}
if err := f.Truncate(int64(n)); err != nil {
log.Fatal(err)
}
}

57
hack/godeps/utils.sh Normal file
View File

@ -0,0 +1,57 @@
#!/bin/bash
# Copyright 2016 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
godep::ensure_godep_version() {
GODEP_VERSION=${1:-"v79"}
if [[ "$(godep version)" == *"godep ${GODEP_VERSION}"* ]]; then
return
fi
go get -d -u github.com/tools/godep 2>/dev/null
pushd "${GOPATH}/github.com/tools/godep" >/dev/null
git checkout "${GODEP_VERSION}"
go install .
popd >/dev/null
godep version
}
godep::sync_staging() {
pushd ${KUBE_ROOT} >/dev/null
KUBE_VERSION=$(git describe)
popd >/dev/null
for repo in $(ls ${KUBE_ROOT}/staging/src/k8s.io); do
rm -rf ${GOPATH}/src/k8s.io/${repo}
cp -a "${KUBE_ROOT}/staging/src/k8s.io/${repo}" "${GOPATH}/src/k8s.io/"
pushd "${GOPATH}/src/k8s.io/${repo}" >/dev/null
git init >/dev/null
git config --local user.email "nobody@k8s.io"
git config --local user.name "$0"
git add . >/dev/null
git commit -q -m "Kubernetes ${KUBE_VERSION}" >/dev/null
git tag ${KUBE_VERSION}
popd >/dev/null
done
}
godep::remove_staging_from_json() {
go run ${MINIKUBE_ROOT}/hack/godeps/godeps-json-updater.go --godeps-file ${MINIKUBE_ROOT}/Godeps/Godeps.json
}