github.com/munnerz/test-infra@v0.0.0-20190108210205-ce3d181dc989/prow/autobump.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  # bump.sh will
    17  # * ensure there are no pending changes
    18  # * optionally activate GOOGLE_APPLICATION_CREDENTIALS and configure-docker if set
    19  # * run //prow:release-push to build and push prow images
    20  # * update all the cluster/*.yaml files to use the new image tags
    21  
    22  set -o errexit
    23  set -o nounset
    24  set -o pipefail
    25  
    26  # TODO(fejta): rewrite this in a better language REAL SOON
    27  
    28  # See https://misc.flogisoft.com/bash/tip_colors_and_formatting
    29  
    30  color-version() { # Bold blue
    31    echo -e "\x1B[1;34m${@}\x1B[0m"
    32  }
    33  
    34  cd "$(dirname "${BASH_SOURCE}")"
    35  
    36  if [[ $# -lt 2 ]]; then
    37      echo "Usage: $(basename "$0") <github-login> </path/to/github/token> [git-name] [git-email]" >&2
    38      exit 1
    39  fi
    40  user=$1
    41  token=$2
    42  shift
    43  shift
    44  ensure-config() {
    45    if [[ $# -eq 2 ]]; then
    46      echo "git config user.name=$1 user.email=$2..." >&2
    47      git config user.name "$1"
    48      git config user.email "$2"
    49    fi
    50    git config user.name &>/dev/null && git config user.email &>/dev/null && return 0
    51    echo "ERROR: git config user.name, user.email unset. No defaults provided" >&2
    52    return 1
    53  }
    54  ensure-config "$@"
    55  
    56  echo "Bumping prow to latest..." >&2
    57  ./bump.sh --latest
    58  
    59  # Convert image: gcr.io/k8s-prow/plank:v20181122-abcd to v20181122-abcd
    60  extract-version() {
    61    local v=$(grep plank:v "$@")
    62    echo ${v##*plank:}
    63  }
    64  
    65  # Convert v20181111-abcd to abcd
    66  extract-commit() {
    67    local c=$1
    68    echo ${c##*-}
    69  }
    70  
    71  old_version=$(git show HEAD:prow/cluster/plank_deployment.yaml | extract-version)
    72  version=$(cat cluster/plank_deployment.yaml | extract-version)
    73  comparison=$(extract-commit "$old_version")...$(extract-commit "$version")
    74  echo -e "Pushing $(color-version $version) to ${user}:autobump..." >&2
    75  
    76  title="Bump prow from $old_version to $version"
    77  git add -A
    78  git commit -m "$title"
    79  git push -f "git@github.com:${user}/test-infra.git" HEAD:autobump
    80  
    81  echo "Creating PR to merge ${user}:autobump into master..." >&2
    82  bazel run //robots/pr-creator -- \
    83      --github-token-path="$token" \
    84      --org=kubernetes --repo=test-infra --branch=master \
    85      --title="$title" --match-title="Bump prow to" \
    86      --body="Included changes: https://github.com/kubernetes/test-infra/compare/$comparison" \
    87      --source="${user}":autobump \
    88      --confirm