|
| 1 | +#!/bin/bash -e |
| 2 | + |
| 3 | +REPO_ROOT=$(git rev-parse --show-toplevel) |
| 4 | +source $REPO_ROOT/boilerplate/_lib/common.sh |
| 5 | + |
| 6 | +cmd=${0##*/} |
| 7 | + |
| 8 | +release_repo=openshift/release |
| 9 | + |
| 10 | +usage() { |
| 11 | + cat <<EOF |
| 12 | +Usage: $cmd [PATH_TO_RELEASE_CLONE] |
| 13 | +
|
| 14 | +Creates a delta in $release_repo standardizing prow configuration for a |
| 15 | +boilerplate consumer. Must be invoked from within a local clone of a repository |
| 16 | +already subscribed to the $CONVENTION_NAME convention. |
| 17 | +
|
| 18 | +Parameters: |
| 19 | + PATH_TO_RELEASE_CLONE File system path to a local clone of |
| 20 | + https://github.com/$release_repo. If not |
| 21 | + specified, the repository will be cloned in a |
| 22 | + temporary directory. |
| 23 | +EOF |
| 24 | + exit -1 |
| 25 | +} |
| 26 | + |
| 27 | +repo_name() { |
| 28 | + (git -C $1 config --get remote.upstream.url || git -C $1 config --get remote.origin.url) | sed 's,.*:,,; s/\.git$//' |
| 29 | +} |
| 30 | + |
| 31 | +# Was a release repo clone specified? |
| 32 | +release_clone= |
| 33 | +if [[ $# -eq 1 ]]; then |
| 34 | + # Special cases for usage queries |
| 35 | + if [[ "$1" == '-'* ]] || [[ "$1" == help ]]; then |
| 36 | + usage |
| 37 | + fi |
| 38 | + |
| 39 | + [[ -d $1 ]] || err " |
| 40 | +$1: Not a directory." |
| 41 | + |
| 42 | + [[ $(repo_name $1) == "$release_repo" ]] || err " |
| 43 | +$1 is not a clone of $release_repo; or its 'origin' remote is not set properly." |
| 44 | + |
| 45 | + # Got a usable clone of openshift/release |
| 46 | + release_clone=$1 |
| 47 | + |
| 48 | +elif [[ $# -ne 0 ]]; then |
| 49 | + usage |
| 50 | +fi |
| 51 | + |
| 52 | +consumer=$(repo_name .) |
| 53 | +[[ -z "$consumer" ]] && err " |
| 54 | +Failed to determine current repository name" |
| 55 | + |
| 56 | +consumer_org=${consumer%/*} |
| 57 | +[[ -z "$consumer_org" ]] && err " |
| 58 | +Failed to determine consumer org" |
| 59 | + |
| 60 | +consumer_name=${consumer#*/} |
| 61 | +[[ -z "$consumer_name" ]] && err " |
| 62 | +Failed to determine consumer name" |
| 63 | + |
| 64 | +# This will be something like refs/remotes/origin/master |
| 65 | +default_branch=$(git symbolic-ref refs/remotes/origin/HEAD) |
| 66 | +[[ -z "$default_branch" ]] && err " |
| 67 | +Failed to determine default branch name" |
| 68 | +# Strip off refs/remotes/origin/ |
| 69 | +default_branch=${default_branch##*/} |
| 70 | +[[ -z "$default_branch" ]] && err " |
| 71 | +Failed to determine default branch name" |
| 72 | + |
| 73 | +# Make sure we were invoked from a boilerplate consumer. |
| 74 | +[[ -z "$CONVENTION_NAME" ]] && err " |
| 75 | +$cmd must be invoked from a consumer of an appropriate convention. Where did you get this script from?" |
| 76 | +# Or at least not from boilerplate itself |
| 77 | +[[ "$consumer" == "openshift/boilerplate" ]] && err " |
| 78 | +$cmd must be invoked from a boilerplate consumer, not from boilerplate itself." |
| 79 | + |
| 80 | +[[ -s $CONVENTION_ROOT/_data/last-boilerplate-commit ]] || err " |
| 81 | +$cmd must be invoked from a boilerplate consumer!" |
| 82 | + |
| 83 | +grep -E -q "^$CONVENTION_NAME(\s.*)?$" $CONVENTION_ROOT/update.cfg || err " |
| 84 | +$consumer is not subscribed to $CONVENTION_NAME!" |
| 85 | + |
| 86 | +# Due to the DPTP-1640 workaround, we need to be even stricter, since we have |
| 87 | +# to copy in the ImageStreamTag config. |
| 88 | +# TODO: Get rid of this check, and $ci_config, and its usage in the config |
| 89 | +# dump, once DPTP-1640 is resolved. |
| 90 | +ci_config=$REPO_ROOT/.ci-operator.yaml |
| 91 | +[[ -s $ci_config ]] || err " |
| 92 | +.ci-operator.yaml not found! Do you need to 'make boilerplate-update'?" |
| 93 | + |
| 94 | +# If a release repo clone wasn't specified, create one |
| 95 | +if [[ -z "$release_clone" ]]; then |
| 96 | + release_clone=$(mktemp -dt openshift_release_XXXXXXX) |
| 97 | + git clone git@github.com:${release_repo}.git $release_clone |
| 98 | +else |
| 99 | + [[ -z "$(git -C $release_clone status --porcelain)" ]] || err " |
| 100 | +Your release clone must start clean." |
| 101 | + # These will blow up if it's misconfigured |
| 102 | + git -C $release_clone checkout master |
| 103 | + git -C $release_clone pull |
| 104 | +fi |
| 105 | + |
| 106 | +cd $release_clone |
| 107 | +release_branch=$consumer_org-$consumer_name-$default_branch-boilerplate-prow-config |
| 108 | +config_dir=ci-operator/config/${consumer_org}/${consumer_name} |
| 109 | +config=${consumer_org}-${consumer_name}-${default_branch}.yaml |
| 110 | +[[ -f $config_dir/$config ]] || err " |
| 111 | +$release_repo bootstrapping is not fully supported! Recommend running 'make new-repo' first! |
| 112 | +To circumvent this warning (not recommended), run: |
| 113 | +
|
| 114 | +git -C $release_clone checkout -b $release_branch |
| 115 | +mkdir -p $release_clone/$config_dir |
| 116 | +touch $release_clone/$config_dir/$config |
| 117 | +git -C $release_clone add $config_dir/$config |
| 118 | +git -C $release_clone commit |
| 119 | +$0 $release_clone" |
| 120 | + |
| 121 | +# If we get here, the config file exists. Replace it. |
| 122 | +# TODO: Edit it instead, replacing only the relevant sections. This would allow |
| 123 | +# the consumer to preserve any additional checks they want in prow. |
| 124 | +cat <<EOF > $config_dir/$config |
| 125 | +base_images: |
| 126 | + temporarily_needed_to_make_this_image_appear_in_all_build_clusters_see_jira_dptp_1640: |
| 127 | +$(sed -n '2,5s/^/ /p' $ci_config) |
| 128 | +build_root: |
| 129 | + from_repository: true |
| 130 | +resources: |
| 131 | + '*': |
| 132 | + limits: |
| 133 | + memory: 4Gi |
| 134 | + requests: |
| 135 | + cpu: 100m |
| 136 | + memory: 200Mi |
| 137 | +tests: |
| 138 | +- as: coverage |
| 139 | + commands: | |
| 140 | + export CODECOV_TOKEN=\$(cat /tmp/secret/CODECOV_TOKEN) |
| 141 | + make coverage |
| 142 | + container: |
| 143 | + from: src |
| 144 | + secret: |
| 145 | + mount_path: /tmp/secret |
| 146 | + name: ${consumer_name}-codecov-token |
| 147 | +- as: publish-coverage |
| 148 | + commands: | |
| 149 | + export CODECOV_TOKEN=\$(cat /tmp/secret/CODECOV_TOKEN) |
| 150 | + make coverage |
| 151 | + container: |
| 152 | + from: src |
| 153 | + postsubmit: true |
| 154 | + secret: |
| 155 | + mount_path: /tmp/secret |
| 156 | + name: ${consumer_name}-codecov-token |
| 157 | +- as: lint |
| 158 | + commands: make lint |
| 159 | + container: |
| 160 | + from: src |
| 161 | +- as: test |
| 162 | + commands: make test |
| 163 | + container: |
| 164 | + from: src |
| 165 | +- as: validate |
| 166 | + commands: make validate |
| 167 | + container: |
| 168 | + from: src |
| 169 | +zz_generated_metadata: |
| 170 | + branch: ${default_branch} |
| 171 | + org: ${consumer_org} |
| 172 | + repo: ${consumer_name} |
| 173 | +EOF |
| 174 | + |
| 175 | +make jobs |
| 176 | + |
| 177 | +echo |
| 178 | +git status |
| 179 | + |
| 180 | +cat <<EOF |
| 181 | +
|
| 182 | +Ready to commit, push, and create a PR in $release_clone |
| 183 | +You may wish to: |
| 184 | +
|
| 185 | +cd $release_clone |
| 186 | +git checkout -b $release_branch |
| 187 | +git add -A |
| 188 | +git commit |
| 189 | +git push origin $release_branch |
| 190 | +EOF |
0 commit comments