#!/bin/bash # Copyright 2014 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 global KUBE_ROOT := "$[dirname $(BASH_SOURCE)]/.." source "$(KUBE_ROOT)/hack/lib/init.sh" kube::golang::setup_env make -C $(KUBE_ROOT) WHAT=cmd/linkcheck global linkcheck := $[kube::util::find-binary "linkcheck] kube::util::ensure-temp-dir global OUTPUT := ""$(KUBE_TEMP)"/linkcheck-output" proc cleanup { rm -rf $(OUTPUT) } trap "cleanup" EXIT SIGINT mkdir -p $OUTPUT global APIROOT := ""$(KUBE_ROOT)/pkg/api/"" global APISROOT := ""$(KUBE_ROOT)/pkg/apis/"" global DOCROOT := ""$(KUBE_ROOT)/docs/"" global ROOTS := '('$APIROOT $APISROOT $DOCROOT) global found_invalid := 'false' for root in [$(ROOTS[@])] { $(linkcheck) "--root-dir=$(root)" !2 > $[tee -a "$(OUTPUT)/error" > !2] && global ret := '0' || global ret := $Status if [[ $ret -eq 1 ]] { echo "Failed: found invalid links in $(root)." global found_invalid := 'true' } if [[ $ret -gt 1 ]] { echo "Error running linkcheck" exit 1 } } if test $(found_invalid) = true { echo "Summary of invalid links:" cat $(OUTPUT)/error exit 1 } # ex: ts=2 sw=2 et filetype=sh (CommandList children: [ (C {(set)} {(-o)} {(errexit)}) (C {(set)} {(-o)} {(nounset)}) (C {(set)} {(-o)} {(pipefail)}) (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: [64 72] ) (/..) } spids: [63] ) ] spids: [63] ) (C {(source)} {(DQ (${ VSub_Name KUBE_ROOT) (/hack/lib/init.sh))}) (C {(kube) (Lit_Other ":") (Lit_Other ":") (golang) (Lit_Other ":") (Lit_Other ":") (setup_env)}) (C {(make)} {(-C)} {(DQ (${ VSub_Name KUBE_ROOT))} {(Lit_VarLike "WHAT=") (cmd/linkcheck)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:linkcheck) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(kube) (Lit_Other ":") (Lit_Other ":") (util) (Lit_Other ":") (Lit_Other ":") (find-binary) } {(DQ (linkcheck))} ) ] ) left_token: spids: [109 121] ) } spids: [108] ) ] spids: [108] ) (C {(kube) (Lit_Other ":") (Lit_Other ":") (util) (Lit_Other ":") (Lit_Other ":") (ensure-temp-dir)} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:OUTPUT) op: Equal rhs: {(DQ (${ VSub_Name KUBE_TEMP)) (/linkcheck-output)} spids: [132] ) ] spids: [132] ) (FuncDef name: cleanup body: (BraceGroup children:[(C {(rm)} {(-rf)} {(DQ (${ VSub_Name OUTPUT))})] spids:[144]) spids: [140 143] ) (C {(trap)} {(DQ (cleanup))} {(EXIT)} {(SIGINT)}) (C {(mkdir)} {(-p)} {(DQ ($ VSub_Name "$OUTPUT"))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:APIROOT) op: Equal rhs: {(DQ (${ VSub_Name KUBE_ROOT) (/pkg/api/))} spids: [178] ) ] spids: [178] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:APISROOT) op: Equal rhs: {(DQ (${ VSub_Name KUBE_ROOT) (/pkg/apis/))} spids: [186] ) ] spids: [186] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:DOCROOT) op: Equal rhs: {(DQ (${ VSub_Name KUBE_ROOT) (/docs/))} spids: [194] ) ] spids: [194] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ROOTS) op: Equal rhs: { (ArrayLiteralPart words: [ {($ VSub_Name "$APIROOT")} {($ VSub_Name "$APISROOT")} {($ VSub_Name "$DOCROOT")} ] ) } spids: [202] ) ] spids: [202] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:found_invalid) op:Equal rhs:{(false)} spids:[211])] spids: [211] ) (ForEach iter_name: root iter_words: [ { (DQ (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) spids: [221 226] ) ) } ] do_arg_iter: False body: (DoGroup children: [ (AndOr children: [ (SimpleCommand words: [{(DQ (${ VSub_Name linkcheck))} {(DQ ("--root-dir=") (${ VSub_Name root))}] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: { (CommandSubPart command_list: (CommandList children: [ (SimpleCommand words: [{(tee)} {(-a)} {(DQ (${ VSub_Name OUTPUT) (/error))}] redirects: [ (Redir op_id: Redir_GreatAnd fd: -1 arg_word: {(2)} spids: [260] ) ] ) ] ) left_token: ("> spids: [248 262] ) } spids: [246] ) ] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:ret) op:Equal rhs:{(0)} spids:[266])] spids: [266] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ret) op: Equal rhs: {($ VSub_QMark "$?")} spids: [271] ) ] spids: [271] ) ] op_id: Op_DPipe ) ] op_id: Op_DAmp ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_eq left: {($ VSub_Name "$ret")} right: {(1)} ) ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Failed: found invalid links in ") (${ VSub_Name root) (.))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:found_invalid) op: Equal rhs: {(true)} spids: [302] ) ] spids: [302] ) ] spids: [-1 288] ) ] spids: [-1 306] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_gt left: {($ VSub_Name "$ret")} right: {(1)} ) ) terminator: ) ] action: [(C {(echo)} {(DQ ("Error running linkcheck"))}) (C {(exit)} {(1)})] spids: [-1 322] ) ] spids: [-1 337] ) ] spids: [230 339] ) spids: [219 228] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(${ VSub_Name found_invalid)} {(Lit_Other "=")} {(true)} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Summary of invalid links:"))}) (C {(cat)} {(${ VSub_Name OUTPUT) (/error)}) (C {(exit)} {(1)}) ] spids: [-1 357] ) ] spids: [-1 379] ) ] )