github.com/shashidharatd/test-infra@v0.0.0-20171006011030-71304e1ca560/mungegithub/mungers/publish_scripts/publish_template.sh (about) 1 #!/bin/bash 2 3 # Copyright 2017 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # This script publishes the latest changes in the ${src_branch} of 18 # k8s.io/kubernetes/staging/src/${repo} to the ${dst_branch} of 19 # k8s.io/${repo}. 20 # 21 # dependent_k8s.io_repos are expected to be separated by ",", 22 # e.g., "client-go,apimachinery". We will expand it to 23 # "repo:commit,repo:commit..." in the future. 24 # 25 # ${kubernetes_remote} is the remote url of k8s.io/kubernetes that will be used 26 # in .git/config in the local checkout of the ${repo}. 27 # 28 # is_library indicates is ${repo} is a library. 29 # 30 # The script assumes that the working directory is 31 # $GOPATH/src/k8s.io/${repo}. 32 # 33 # The script is expected to be run by other publish scripts. 34 35 set -o errexit 36 set -o nounset 37 set -o pipefail 38 39 if [ ! $# -eq 6 ]; then 40 echo "usage: $0 repo src_branch dst_branch dependent_k8s.io_repos kubernetes_remote is_library" 41 exit 1 42 fi 43 44 # the target repo 45 REPO="${1}" 46 # src branch of k8s.io/kubernetes 47 SRC_BRANCH="${2:-master}" 48 # dst branch of k8s.io/${repo} 49 DST_BRANCH="${3:-master}" 50 # dependent k8s.io repos 51 DEPS="${4}" 52 # Remote url for Kubernetes. If empty, will fetch kubernetes 53 # from https://github.com/kubernetes/kubernetes. 54 KUBERNETES_REMOTE="${5}" 55 # If ${REPO} is a library 56 IS_LIBRARY="${6}" 57 readonly SRC_BRANCH DST_BRANCH DEPS KUBERNETES_REMOTE IS_LIBRARY 58 59 SCRIPT_DIR=$(dirname "${BASH_SOURCE}") 60 source "${SCRIPT_DIR}"/util.sh 61 62 git fetch origin 63 if [ "$(git rev-parse --abbrev-ref HEAD)" = "${DST_BRANCH}" ]; then 64 git reset --hard origin/"${DST_BRANCH}" 65 else 66 git branch -D "${DST_BRANCH}" || true 67 git branch -f "${DST_BRANCH}" origin/"${DST_BRANCH}" 68 git checkout "${DST_BRANCH}" 69 fi 70 71 # sync_repo cherry-picks the commits that change 72 # k8s.io/kubernetes/staging/src/k8s.io/${REPO} to the ${DST_BRANCH} 73 sync_repo "staging/src/k8s.io/${REPO}" "${SRC_BRANCH}" "${KUBERNETES_REMOTE}" 74 75 # update_godeps_json updates the Godeps/Godeps.json to track the latest commits 76 # of k8s.io/*. 77 IFS=',' read -a deps <<< "${DEPS}" 78 dep_count=${#deps[@]} 79 for (( i=0; i<${dep_count}; i++ )); do 80 update_godeps_json "${deps[i]}" 81 done 82 83 # restore the vendor/ folder. k8s.io/* and github.com/golang/glog will be 84 # removed from the vendor folder 85 restore_vendor "${DEPS}" "${IS_LIBRARY}"