github.com/yrj2011/jx-test-infra@v0.0.0-20190529031832-7a2065ee98eb/prow/test/integration-mkpj.sh (about) 1 #!/bin/bash 2 # Copyright 2018 The Kubernetes Authors. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 # This script loads Prow configuration YAML and validates that the 17 # appropriate ProwJob is created from that configuration. 18 19 set -o errexit 20 set -o nounset 21 set -o pipefail 22 23 # We are told where the `mkpj` binary lives by Bazel 24 mkpj=$1 25 # We can either validate current behavior or update 26 # the recorded files 27 action=$2 28 if [[ "${action}" != "VALIDATE" && "${action}" != "GENERATE" ]]; then 29 echo "[ERROR] Action must be either \`VALIDATE\` or \`GENERATE\`, not ${action}" 30 exit 1 31 fi 32 33 output="$( mktemp -d )" 34 35 function cleanup() { 36 returnCode="$?" 37 rm -rf "${output}" || true 38 exit "${returnCode}" 39 } 40 trap cleanup EXIT 41 42 function validate() { 43 local expected=$1 44 local actual=$2 45 if ! difference="$( diff --ignore-matching-lines="name:" --ignore-matching-lines="startTime:" "${expected}" "${actual}" )"; then 46 echo "[ERROR] Generated incorrect ProwJob YAML for config:" 47 echo "${difference}" 48 exit 1 49 fi 50 } 51 52 for prowJob in prow/test/data/*-prow-job.yaml; do 53 prowJobName="$( basename "${prowJob}" "-prow-job.yaml" )" 54 # we always pass all possible refs but `mkpj` will use 55 # only those that are necessary for triggering the job 56 "${mkpj}" --config-path prow/test/data/test-config.yaml \ 57 --job "${prowJobName}" \ 58 --base-ref "master" --base-sha "basesha" \ 59 --pull-number "1" --pull-sha "pullsha" --pull-author "bob" > "${output}/${prowJobName}-prow-job.yaml" 60 case "${action}" in 61 "VALIDATE" ) 62 validate "${prowJob}" "${output}/${prowJobName}-prow-job.yaml" ;; 63 "GENERATE" ) 64 mv "${output}/${prowJobName}-prow-job.yaml" "${prowJob}" ;; 65 esac 66 done