|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2019 The Kubernetes Authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# |
| 18 | +# Script to generate vendor archive that contains vendor and Gopkg.toml for a |
| 19 | +# given project version |
| 20 | +# |
| 21 | +set -e |
| 22 | + |
| 23 | +go_workspace='' |
| 24 | +for p in ${GOPATH//:/ }; do |
| 25 | + if [[ $PWD/ = $p/* ]]; then |
| 26 | + go_workspace=$p |
| 27 | + fi |
| 28 | +done |
| 29 | + |
| 30 | +if [ -z $go_workspace ]; then |
| 31 | + echo 'Current directory is not in $GOPATH' >&2 |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | + |
| 35 | +build_kb() { |
| 36 | + rm -f /tmp/kb && \ |
| 37 | + go build -o /tmp/kb sigs.k8s.io/kubebuilder/cmd |
| 38 | +} |
| 39 | + |
| 40 | + |
| 41 | +# |
| 42 | +# generate_vendor takes project version as input and creates vendor archive |
| 43 | +# containing Go dependencies for a Kubebuilder project along with the Gopkg.lock |
| 44 | +# file. |
| 45 | +# |
| 46 | +generate_vendor() { |
| 47 | + version=$1 |
| 48 | + project_dir=${go_workspace}/src/sigs.k8s.io/kubebuilder-test |
| 49 | + mkdir -p ${project_dir} |
| 50 | + rm -rf ${project_dir}/* |
| 51 | + pushd . |
| 52 | + cd ${project_dir} |
| 53 | + /tmp/kb init --project-version $version --domain testproject.org --license apache2 --owner "The Kubernetes authors" --dep=true |
| 54 | + make |
| 55 | + tar -zcvf vendor.v$version.tgz vendor Gopkg.lock && \ |
| 56 | + echo "vendor archieve vendor.v$version.tgz is ready." |
| 57 | + popd |
| 58 | +} |
| 59 | + |
| 60 | +build_kb && \ |
| 61 | +generate_vendor $1 |
0 commit comments