github.com/yrj2011/jx-test-infra@v0.0.0-20190529031832-7a2065ee98eb/prow/bump.sh (about) 1 #!/bin/bash 2 # Copyright 2016 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 set -o errexit 17 18 # See https://misc.flogisoft.com/bash/tip_colors_and_formatting 19 20 color-image() { # Bold magenta 21 echo -e "\x1B[1;35m${@}\x1B[0m" 22 } 23 24 color-version() { # Bold blue 25 echo -e "\x1B[1;34m${@}\x1B[0m" 26 } 27 28 color-error() { # Light red 29 echo -e "\x1B[91m${@}\x1B[0m" 30 } 31 32 color-target() { # Bold cyan 33 echo -e "\x1B[1;33m${@}\x1B[0m" 34 } 35 36 # darwin is great 37 SED=sed 38 if which gsed &>/dev/null; then 39 SED=gsed 40 fi 41 if ! ($SED --version 2>&1 | grep -q GNU); then 42 echo "!!! GNU sed is required. If on OS X, use 'brew install gnu-sed'." >&2 43 exit 1 44 fi 45 46 new_version="v$(date -u '+%Y%m%d')-$(git describe --tags --always --dirty)" 47 echo -e "version: $(color-version ${new_version})" >&2 48 if [[ "${new_version}" == *-dirty ]]; then 49 echo -e "$(color-error ERROR): uncommitted changes to repo" >&2 50 echo " Fix with git commit" >&2 51 exit 1 52 fi 53 54 cd "$(dirname "${BASH_SOURCE}")" 55 56 # Determine what images we need to update 57 echo -n "images: " >&2 58 images=("$@") 59 if [[ "${#images[@]}" == 0 ]]; then 60 echo "querying bazel for $(color-target :image) targets under $(color-target //prow/...) ..." >&2 61 images=($(bazel query 'filter(".*:image", //prow/...)' | cut -d : -f 1 | xargs -n 1 basename)) 62 echo -n "images: " >&2 63 fi 64 echo -e "$(color-image ${images[@]})" >&2 65 66 echo -e "Pushing $(color-version ${new_version}) via $(color-target //prow:release-push --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64) ..." >&2 67 bazel run //prow:release-push --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 68 69 echo -e "Bumping: $(color-image ${images[@]}) to $(color-version ${new_version}) ..." >&2 70 71 for i in "${images[@]}"; do 72 echo -e " $(color-image $i): $(color-version $new_version)" >&2 73 $SED -i "s/\(${i}:\)v[a-f0-9-]\+/\1${new_version}/I" cluster/*.yaml 74 done 75 76 echo "Deploy with:" >&2 77 echo -e " $(color-target bazel run //prow/cluster:production.apply --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64)"