#!/bin/bash # Copyright 2015 The Kubernetes Authors. # # 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 # As of go 1.6, the vendor experiment is enabled by default. export GO15VENDOREXPERIMENT=1 #### HACK #### # Sometimes godep just can't handle things. This lets use manually put # some deps in place first, so godep won't fall over. proc preload-dep { global org := $1 global project := $2 global sha := $3 # project_dir ($4) is optional, if unset we will generate it if [[ -z ${4:-} ]] { global project_dir := ""$(GOPATH)/src/$(org)/$(project).git"" } else { global project_dir := $(4) } echo "**HACK** preloading dep for $(org) $(project) at $(sha) into $(project_dir)" git clone "https://$(org)/$(project)" $(project_dir) > /dev/null !2 > !1 pushd $(project_dir) > /dev/null git checkout $(sha) popd > /dev/null } global KUBE_ROOT := "$[dirname $(BASH_SOURCE)]/.." source "$(KUBE_ROOT)/hack/lib/init.shsetconst global FOO = "bar"" readonly branch = $(1:-${KUBE_VERIFY_GIT_BRANCH:-master}) if ! [[ ${KUBE_FORCE_VERIFY_CHECKS:-} =~ ^[yY]$ ]] && \ ! kube::util::has_changes_against_upstream_branch $(branch) 'Godeps/' && \ ! kube::util::has_changes_against_upstream_branch $(branch) 'vendor/' && \ ! kube::util::has_changes_against_upstream_branch $(branch) 'hack/.*godep' { exit 0 } if [[ -z ${TMP_GOPATH:-} ]] { # Create a nice clean place to put our new godeps global _tmpdir := $[mktemp -d -t gopath.XXXXXX] } else { # reuse what we might have saved previously global _tmpdir := $(TMP_GOPATH) } if [[ -z ${KEEP_TMP:-} ]] { global KEEP_TMP := 'false' } proc cleanup { if test $(KEEP_TMP) == "true" { echo "Leaving $(_tmpdir) for you to examine or copy. Please delete it manually when finished. (rm -rf $(_tmpdir))" } else { echo "Removing $(_tmpdir)" rm -rf $(_tmpdir) } export GODEP="" } trap cleanup EXIT # Copy the contents of the kube directory into the nice clean place global _kubetmp := ""$(_tmpdir)/src/k8s.io"" mkdir -p $(_kubetmp) # should create ${_kubectmp}/kubernetes git archive --format=tar --prefix=kubernetes/ $[git write-tree] | shell {cd $(_kubetmp) && tar xf -} global _kubetmp := ""$(_kubetmp)/kubernetes"" # Do all our work in the new GOPATH export GOPATH="$(_tmpdir)" pushd $(_kubetmp) !2 > !1 > /dev/null # Restore the Godeps into our temp directory hack/godep-restore.sh # Destroy deps in the copy of the kube tree rm -rf ./Godeps ./vendor # For some reason the kube tree needs to be a git repo for the godep tool to # run. Doesn't make sense. git init > /dev/null !2 > !1 # Recreate the Godeps using the nice clean set we just downloaded hack/godep-save.sh popd !2 > !1 > /dev/null global ret := '0' pushd $(KUBE_ROOT) !2 > !1 > /dev/null # Test for diffs if ! global _out := $[diff -Naupr --ignore-matching-lines='^\s*\"GoVersion\":' --ignore-matching-line='^\s*\"GodepVersion\":' --ignore-matching-lines='^\s*\"Comment\":' Godeps/Godeps.json $(_kubetmp)/Godeps/Godeps.json] { echo "Your Godeps.json is different:" echo $(_out) echo "Godeps Verify failed." echo $(_out) > godepdiff.patch echo "If you're seeing this locally, run the below command to fix your Godeps.json:" echo "patch -p0 < godepdiff.patch" echo "(The above output can be saved as godepdiff.patch if you're not running this locally)" echo "(The patch file should also be exported as a build artifact if run through CI)" global KEEP_TMP := 'true' if [[ -f godepdiff.patch && -d "${ARTIFACTS_DIR:-}" ]] { echo "Copying patch to artifacts.." cp godepdiff.patch "$(ARTIFACTS_DIR:-)/" } global ret := '1' } if ! global _out := $[diff -Naupr -x "BUILD" -x "AUTHORS*" -x "CONTRIBUTORS*" vendor $(_kubetmp)/vendor] { echo "Your vendored results are different:" echo $(_out) echo "Godeps Verify failed." echo $(_out) > vendordiff.patch echo "If you're seeing this locally, run the below command to fix your directories:" echo "patch -p0 < vendordiff.patch" echo "(The above output can be saved as godepdiff.patch if you're not running this locally)" echo "(The patch file should also be exported as a build artifact if run through CI)" global KEEP_TMP := 'true' if [[ -f vendordiff.patch && -d "${ARTIFACTS_DIR:-}" ]] { echo "Copying patch to artifacts.." cp vendordiff.patch "$(ARTIFACTS_DIR:-)/" } global ret := '1' } popd !2 > !1 > /dev/null if [[ ${ret} > 0 ]] { exit $(ret) } echo "Godeps Verified." # ex: ts=2 sw=2 et filetype=sh (CommandList children: [ (C {(set)} {(-o)} {(errexit)}) (C {(set)} {(-o)} {(nounset)}) (C {(set)} {(-o)} {(pipefail)}) (C {(export)} {(Lit_VarLike "GO15VENDOREXPERIMENT=") (1)}) (FuncDef name: preload-dep body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:org) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [88] ) ] spids: [88] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:project) op: Equal rhs: {(DQ ($ VSub_Number "$2"))} spids: [94] ) ] spids: [94] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:sha) op: Equal rhs: {(DQ ($ VSub_Number "$3"))} spids: [100] ) ] spids: [100] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_z child: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{}) spids: [116 119] ) } ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:project_dir) op: Equal rhs: { (DQ (${ VSub_Name GOPATH) (/src/) (${ VSub_Name org) (/) (${ VSub_Name project) (.git) ) } spids: [127] ) ] spids: [127] ) ] spids: [-1 124] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:project_dir) op: Equal rhs: {(DQ (${ VSub_Number 4))} spids: [147] ) ] spids: [147] ) ] spids: [144 155] ) (C {(echo)} { (DQ ("**HACK** preloading dep for ") (${ VSub_Name org) (" ") (${ VSub_Name project) (" at ") (${ VSub_Name sha) (" into ") (${ VSub_Name project_dir) ) } ) (SimpleCommand words: [ {(git)} {(clone)} {(DQ ("https://") (${ VSub_Name org) (/) (${ VSub_Name project))} {(DQ (${ VSub_Name project_dir))} ] redirects: [ (Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[202]) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[206]) ] ) (SimpleCommand words: [{(pushd)} {(DQ (${ VSub_Name project_dir))}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[218])] ) (C {(git)} {(checkout)} {(DQ (${ VSub_Name sha))}) (SimpleCommand words: [{(popd)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[236])] ) ] spids: [85] ) spids: [81 84] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_ROOT) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {(DQ (${ VSub_Name BASH_SOURCE))})] ) left_token: spids: [244 252] ) (/..) } spids: [243] ) ] spids: [243] ) (C {(source)} {(DQ (${ VSub_Name KUBE_ROOT) (/hack/lib/init.sh))}) (Assignment keyword: Assign_Readonly pairs: [ (assign_pair lhs: (LhsName name:branch) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonHyphen arg_word: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(master)}) spids: [271 275] ) } ) spids: [268 276] ) } spids: [267] ) ] spids: [265] ) (If arms: [ (if_arm cond: [ (Sentence child: (AndOr children: [ (Pipeline children: [ (DBracket expr: (BoolBinary op_id: BoolBinary_EqualTilde left: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{}) spids: [284 287] ) } right: {(Lit_Other "^") (Lit_Other "[") (yY) (Lit_Other "]") (Lit_Other "$")} ) ) ] negated: True ) (AndOr children: [ (Pipeline children: [ (C {(kube) (Lit_Other ":") (Lit_Other ":") (util) (Lit_Other ":") (Lit_Other ":") (has_changes_against_upstream_branch) } {(DQ (${ VSub_Name branch))} {(SQ )} ) ] negated: True ) (AndOr children: [ (Pipeline children: [ (C {(kube) (Lit_Other ":") (Lit_Other ":") (util) (Lit_Other ":") (Lit_Other ":") (has_changes_against_upstream_branch) } {(DQ (${ VSub_Name branch))} {(SQ )} ) ] negated: True ) (Pipeline children: [ (C {(kube) (Lit_Other ":") (Lit_Other ":") (util) (Lit_Other ":") (Lit_Other ":") (has_changes_against_upstream_branch) } {(DQ (${ VSub_Name branch))} {(SQ <"hack/.*godep">)} ) ] negated: True ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) terminator: ) ] action: [(C {(exit)} {(0)})] spids: [-1 372] ) ] spids: [-1 379] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_z child: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{}) spids: [388 391] ) } ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:_tmpdir) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [(C {(mktemp)} {(-d)} {(-t)} {(gopath.XXXXXX)})] ) left_token: spids: [405 413] ) ) } spids: [403] ) ] spids: [403] ) ] spids: [-1 396] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:_tmpdir) op: Equal rhs: {(DQ (${ VSub_Name TMP_GOPATH))} spids: [423] ) ] spids: [423] ) ] spids: [416 430] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_z child: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{}) spids: [439 442] ) } ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:KEEP_TMP) op:Equal rhs:{(false)} spids:[450])] spids: [450] ) ] spids: [-1 447] ) ] spids: [-1 453] ) (FuncDef name: cleanup body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ (${ VSub_Name KEEP_TMP))} {(Lit_Other "=") (Lit_Other "=")} {(DQ (true))} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(echo)} { (DQ ("Leaving ") (${ VSub_Name _tmpdir) ( " for you to examine or copy. Please delete it manually when finished. (rm -rf " ) (${ VSub_Name _tmpdir) (")") ) } ) ] spids: [-1 482] ) ] else_action: [ (C {(echo)} {(DQ ("Removing ") (${ VSub_Name _tmpdir))}) (C {(rm)} {(-rf)} {(DQ (${ VSub_Name _tmpdir))}) ] spids: [500 524] ) (C {(export)} {(Lit_VarLike "GODEP=") (DQ )}) ] spids: [459] ) spids: [455 458] ) (C {(trap)} {(cleanup)} {(EXIT)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:_kubetmp) op: Equal rhs: {(DQ (${ VSub_Name _tmpdir) (/src/k8s.io))} spids: [545] ) ] spids: [545] ) (C {(mkdir)} {(-p)} {(DQ (${ VSub_Name _kubetmp))}) (Pipeline children: [ (C {(git)} {(archive)} {(--format) (Lit_Other "=") (tar)} {(--prefix) (Lit_Other "=") (kubernetes/)} { (CommandSubPart command_list: (CommandList children:[(C {(git)} {(write-tree)})]) left_token: spids: [578 582] ) } ) (Subshell child: (AndOr children: [(C {(cd)} {(DQ (${ VSub_Name _kubetmp))}) (C {(tar)} {(xf)} {(-)})] op_id: Op_DAmp ) spids: [586 602] ) ] negated: False ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:_kubetmp) op: Equal rhs: {(DQ (${ VSub_Name _kubetmp) (/kubernetes))} spids: [604] ) ] spids: [604] ) (C {(export)} {(Lit_VarLike "GOPATH=") (DQ (${ VSub_Name _tmpdir))}) (SimpleCommand words: [{(pushd)} {(DQ (${ VSub_Name _kubetmp))}] redirects: [ (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[634]) (Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[637]) ] ) (C {(hack/godep-restore.sh)}) (C {(rm)} {(-rf)} {(./Godeps)} {(./vendor)}) (SimpleCommand words: [{(git)} {(init)}] redirects: [ (Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[676]) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[680]) ] ) (C {(hack/godep-save.sh)}) (SimpleCommand words: [{(popd)}] redirects: [ (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[693]) (Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[696]) ] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:ret) op:Equal rhs:{(0)} spids:[701])] spids: [701] ) (SimpleCommand words: [{(pushd)} {(DQ (${ VSub_Name KUBE_ROOT))}] redirects: [ (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[713]) (Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[716]) ] ) (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:_out) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(diff)} {(-Naupr)} {(--ignore-matching-lines) (Lit_Other "=") (SQ <"^\\s*\\\"GoVersion\\\":">) } {(--ignore-matching-line) (Lit_Other "=") (SQ <"^\\s*\\\"GodepVersion\\\":">)} {(--ignore-matching-lines) (Lit_Other "=") (SQ <"^\\s*\\\"Comment\\\":">) } {(Godeps/Godeps.json)} {(${ VSub_Name _kubetmp) (/Godeps/Godeps.json)} ) ] ) left_token: spids: [731 760] ) ) } spids: [729] ) ] spids: [729] ) ] negated: True ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Your Godeps.json is different:"))}) (C {(echo)} {(DQ (${ VSub_Name _out))}) (C {(echo)} {(DQ ("Godeps Verify failed."))}) (SimpleCommand words: [{(echo)} {(DQ (${ VSub_Name _out))}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(godepdiff.patch)} spids:[798])] ) (C {(echo)} { (DQ ("If you're seeing this locally, run the below command to fix your Godeps.json:")) } ) (C {(echo)} {(DQ ("patch -p0 < godepdiff.patch"))}) (C {(echo)} { (DQ ( "(The above output can be saved as godepdiff.patch if you're not running this locally)" ) ) } ) (C {(echo)} { (DQ ( "(The patch file should also be exported as a build artifact if run through CI)" ) ) } ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:KEEP_TMP) op:Equal rhs:{(true)} spids:[831])] spids: [831] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalAnd left: (BoolUnary op_id:BoolUnary_f child:{(godepdiff.patch)}) right: (BoolUnary op_id: BoolUnary_d child: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ )}) spids: [848 851] ) ) } ) ) ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Copying patch to artifacts.."))}) (C {(cp)} {(godepdiff.patch)} { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ )}) spids: [872 875] ) (/) ) } ) ] spids: [-1 857] ) ] spids: [-1 880] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:ret) op:Equal rhs:{(1)} spids:[883])] spids: [883] ) ] spids: [-1 764] ) ] spids: [-1 887] ) (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:_out) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(diff)} {(-Naupr)} {(-x)} {(DQ (BUILD))} {(-x)} {(DQ ("AUTHORS*"))} {(-x)} {(DQ ("CONTRIBUTORS*"))} {(vendor)} {(${ VSub_Name _kubetmp) (/vendor)} ) ] ) left_token: spids: [897 926] ) ) } spids: [895] ) ] spids: [895] ) ] negated: True ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Your vendored results are different:"))}) (C {(echo)} {(DQ (${ VSub_Name _out))}) (C {(echo)} {(DQ ("Godeps Verify failed."))}) (SimpleCommand words: [{(echo)} {(DQ (${ VSub_Name _out))}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(vendordiff.patch)} spids:[964])] ) (C {(echo)} { (DQ ("If you're seeing this locally, run the below command to fix your directories:")) } ) (C {(echo)} {(DQ ("patch -p0 < vendordiff.patch"))}) (C {(echo)} { (DQ ( "(The above output can be saved as godepdiff.patch if you're not running this locally)" ) ) } ) (C {(echo)} { (DQ ( "(The patch file should also be exported as a build artifact if run through CI)" ) ) } ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:KEEP_TMP) op:Equal rhs:{(true)} spids:[997])] spids: [997] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalAnd left: (BoolUnary op_id:BoolUnary_f child:{(vendordiff.patch)}) right: (BoolUnary op_id: BoolUnary_d child: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ )}) spids: [1014 1017] ) ) } ) ) ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Copying patch to artifacts.."))}) (C {(cp)} {(vendordiff.patch)} { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ )}) spids: [1038 1041] ) (/) ) } ) ] spids: [-1 1023] ) ] spids: [-1 1046] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:ret) op:Equal rhs:{(1)} spids:[1049])] spids: [1049] ) ] spids: [-1 930] ) ] spids: [-1 1053] ) (SimpleCommand words: [{(popd)}] redirects: [ (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[1057]) (Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[1060]) ] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id:Redir_Great left:{(${ VSub_Name ret)} right:{(0)}) ) terminator: ) ] action: [(C {(exit)} {(${ VSub_Name ret)})] spids: [-1 1080] ) ] spids: [-1 1089] ) (C {(echo)} {(DQ ("Godeps Verified."))}) ] )