Skip to content

Commit

Permalink
add tool for pushing vendor updates to consuming repos easier
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
  • Loading branch information
dhellmann committed Aug 26, 2020
1 parent b66cbe4 commit f07e150
Showing 1 changed file with 144 additions and 0 deletions.
144 changes: 144 additions & 0 deletions hack/push_updates.sh
@@ -0,0 +1,144 @@
#!/bin/bash
#
# Push updates that need to be vendored in other repositories.

if ! which hub 2>/dev/null 1>&2; then
echo "This tool requires the hub command line app." 1>&2
echo "Refer to https://github.com/github/hub for installation instructions." 1>&2
exit 1
fi

function show_help() {
cat <<EOF
push_updates.sh [-h]
push_updates.sh [-b BRANCH] [-n] [-r REPO] [-s SHA] [-t TITLE]
-b BRANCH
Set the release branch to be updated. Defaults to "master".
-h
Shows this help message.
-n
Dry run mode. Do not push or create a pull-request.
-r REPO
Update the given repository. May be repeated.
Defaults to updating all cluster-api-provider repositories:
EOF

for r in $DEFAULT_REPOS; do
echo " $r"
done

cat <<EOF
-s SHA
The SHA from machine-api-operator repository to push.
Defaults to HEAD of master.
-t TITLE
The commit and pull-request title to use. Defaults to
a message that includes the SHA.
Without any arguments, creates a pull request for each repository to
update the vendored version of machine-api-operator to refer to the
current HEAD commit on the master branch.
EOF
}

DEFAULT_REPOS="
cluster-api-provider-aws
cluster-api-provider-azure
cluster-api-provider-baremetal
cluster-api-provider-gcp
cluster-api-provider-openstack
cluster-api-provider-ovirt
"
TITLE=""
SHA=""
BRANCH_NAME="master"
DRY_RUN=false

while getopts "b:hnr:s:t:" OPTION; do
case $OPTION in
b)
BRANCH_NAME="$OPTARG"
;;
h)
show_help
exit 0
;;
n)
DRY_RUN=true
;;
r)
REPOS="$REPOS $OPTARG"
;;
s)
SHA="$OPTARG"
;;
t)
TITLE="$OPTARG"
;;
esac
done

REPOS=${REPOS:-${DEFAULT_REPOS}}
TMPDIR=${TMPDIR:-/tmp}
WORKING_DIR=$(mktemp -d $TMPDIR/mao-push-updates.XXXX)
cd $WORKING_DIR
echo "Working in $WORKING_DIR"

if [ -z "$SHA" ]; then
echo "Determining SHA for machine-api-operator repository..."
hub clone openshift/machine-api-operator
(cd ./machine-api-operator && git checkout origin/$BRANCH_NAME)
SHA=$(cd ./machine-api-operator && git show --format="%H")
fi
echo "Updating consumers to $SHA"

if [ -z "$TITLE" ]; then
TITLE="update machine-api-operator to $SHA"
fi

WORKING_BRANCH_NAME="mao-update-$SHA"
REMOTE_NAME="working"

set -e

for repo in $REPOS; do
echo
echo $repo

hub clone openshift/$repo
pushd ./$repo

hub fork --remote-name $REMOTE_NAME

git checkout origin/$BRANCH_NAME
git checkout -b $WORKING_BRANCH_NAME

# Use -d option to avoid build errors because we aren't going to
# build locally.
go get -d github.com/openshift/machine-api-operator@${SHA}

go mod tidy
go mod vendor
go mod verify

git add .
git commit -m "$TITLE"

PAGER= git show --name-only

if $DRY_RUN; then
echo "Not pushing to $WORKING_BRANCH_NAME or creating PR."
else
git push -u $REMOTE_NAME $WORKING_BRANCH_NAME
hub pull-request --no-edit --base openshift:$BRANCH_NAME
fi

popd
done

0 comments on commit f07e150

Please sign in to comment.