Update the release script again

Updates the release script to use the actual GOPATH directory as
previous problems with commit hashes / versions in `kompose version`.

Cleans this up in regards to all the `cd` and `cd ..` commands.

No need to `git clone`.
This commit is contained in:
Charlie Drage 2017-04-28 09:42:45 -04:00
parent 0d3a7084c2
commit f64ad32ae9
2 changed files with 70 additions and 48 deletions

1
.gitignore vendored
View File

@ -7,6 +7,7 @@ kompose
bin bin
/docker-compose.yaml /docker-compose.yaml
/docker-compose.yml /docker-compose.yml
changes.txt
# #
# GO SPECIFIC # GO SPECIFIC

View File

@ -17,6 +17,7 @@
# Constants. Enter relevant repo information here. # Constants. Enter relevant repo information here.
UPSTREAM_REPO="kubernetes-incubator" UPSTREAM_REPO="kubernetes-incubator"
CLI="kompose" CLI="kompose"
GITPATH="$GOPATH/src/github.com/kubernetes-incubator/kompose"
usage() { usage() {
echo "This will prepare $CLI for release!" echo "This will prepare $CLI for release!"
@ -34,65 +35,72 @@ usage() {
} }
requirements() { requirements() {
if [ ! -f /usr/bin/git ] && [ ! -f /usr/local/bin/git ]; then
echo "No git." if [ "$PWD" != "$GITPATH" ]; then
return 1 echo "ERROR: Must be in the $GITPATH directory"
exit 0
fi fi
if [ ! -f $GOPATH/bin/github-release ]; then if ! hash git 2>/dev/null; then
echo "No $GOPATH/bin/github-release. Please run 'go get -v github.com/aktau/github-release'" echo "ERROR: No git."
return 1 exit 0
fi fi
if [ ! -f /usr/local/bin/github_changelog_generator ]; then if ! hash github-release 2>/dev/null; then
echo "github_changelog_generator required to generate the change log. Please run 'gem install github_changelog_generator" echo "ERROR: No $GOPATH/bin/github-release. Please run 'go get -v github.com/aktau/github-release'"
return 1 exit 0
fi fi
if [ ! -f /usr/bin/hub ]; then if ! hash github_changelog_generator 2>/dev/null; then
echo "Hub needed in order to create the relevant PR's. Please install hub @ https://github.com/github/hub" echo "ERROR: github_changelog_generator required to generate the change log. Please run 'gem install github_changelog_generator"
return 1 exit 0
fi
if ! hash hub 2>/dev/null; then
echo "ERROR: Hub needed in order to create the relevant PR's. Please install hub @ https://github.com/github/hub"
exit 0
fi fi
if [[ -z "$GITHUB_TOKEN" ]]; then if [[ -z "$GITHUB_TOKEN" ]]; then
echo "export GITHUB_TOKEN=yourtoken needed for using github-release" echo "ERROR: export GITHUB_TOKEN=yourtoken needed for using github-release"
exit 0
fi fi
} }
# Clone and then change to user's upstream repo for pushing to master / opening PR's :) # Make sure that upstream had been added to the repo
clone() { init_sync() {
git clone ssh://git@github.com/$UPSTREAM_REPO/$CLI.git CURRENT_ORIGIN=`git config --get remote.origin.url`
if [ $? -eq 0 ]; then CURRENT_UPSTREAM=`git config --get remote.upstream.url`
echo OK ORIGIN="git@github.com:$ORIGIN_REPO/$CLI.git"
else UPSTREAM="git@github.com:$UPSTREAM_REPO/$CLI.git"
echo FAIL
exit if [ $CURRENT_ORIGIN != $ORIGIN ]; then
echo "Origin repo must be set to $ORIGIN"
exit 0
fi fi
cd $CLI
git remote remove origin if [ $CURRENT_UPSTREAM != $UPSTREAM ]; then
git remote add origin git@github.com:$ORIGIN_REPO/$CLI.git echo "Upstream repo must be set to $UPSTREAM"
git remote add upstream http://github.com/$UPSTREAM_REPO/$CLI exit 0
fi
git checkout master
git fetch upstream
git merge upstream/master
git checkout -b release-$1 git checkout -b release-$1
cd ..
} }
replaceversion() { replaceversion() {
cd $CLI
echo "1. Replaced version in version.go" echo "1. Replaced version in version.go"
sed -i "s/$1/$2/g" cmd/version.go sed -i "s/$1/$2/g" cmd/version.go
echo "2. Replaced README.md versioning" echo "2. Replaced README.md versioning"
sed -i "s/$1/$2/g" README.md sed -i "s/$1/$2/g" README.md
cd ..
} }
changelog() { changelog() {
cd $CLI
echo "Generating changelog using github-changelog-generator" echo "Generating changelog using github-changelog-generator"
github_changelog_generator $UPSTREAM_REPO/$CLI -t $GITHUB_TOKEN --future-release v$1 github_changelog_generator $UPSTREAM_REPO/$CLI -t $GITHUB_TOKEN --future-release v$1
cd ..
} }
changelog_github() { changelog_github() {
@ -102,14 +110,17 @@ changelog_github() {
} }
build_binaries() { build_binaries() {
cd $CLI
make cross make cross
cd .. }
create_tarballs() {
for f in $CLI/bin/*
do
tar cvzf $f.tar.gz $f
done
} }
git_commit() { git_commit() {
cd $CLI
BRANCH=`git symbolic-ref --short HEAD` BRANCH=`git symbolic-ref --short HEAD`
if [ -z "$BRANCH" ]; then if [ -z "$BRANCH" ]; then
echo "Unable to get branch name, is this even a git repo?" echo "Unable to get branch name, is this even a git repo?"
@ -122,7 +133,6 @@ git_commit() {
git push origin $BRANCH git push origin $BRANCH
hub pull-request -b $UPSTREAM_REPO/$CLI:master -h $ORIGIN_REPO/$CLI:$BRANCH hub pull-request -b $UPSTREAM_REPO/$CLI:master -h $ORIGIN_REPO/$CLI:$BRANCH
cd ..
echo "" echo ""
echo "PR opened against master to update version" echo "PR opened against master to update version"
echo "MERGE THIS BEFORE CONTINUING" echo "MERGE THIS BEFORE CONTINUING"
@ -130,18 +140,19 @@ git_commit() {
} }
git_pull() { git_pull() {
cd $CLI
git pull git pull
cd ..
} }
git_sync() { git_sync() {
cd $CLI
git fetch upstream master git fetch upstream master
git rebase upstream/master git rebase upstream/master
} }
git_tag() {
git tag v$1
}
push() { push() {
CHANGES=$(cat changes.txt) CHANGES=$(cat changes.txt)
# Release it! # Release it!
@ -160,10 +171,10 @@ push() {
exit exit
fi fi
# Upload all the binaries generated in bin/ # Upload all the binaries and tarballs generated in bin/
for f in $CLI/bin/* for f in $CLI/bin/*
do do
echo "Uploading $f binary" echo "Uploading file $f"
NAME=`echo $f | sed "s,$CLI/bin/,,g"` NAME=`echo $f | sed "s,$CLI/bin/,,g"`
github-release upload \ github-release upload \
--user $UPSTREAM_REPO \ --user $UPSTREAM_REPO \
@ -187,13 +198,15 @@ push() {
} }
clean() { clean() {
rm -rf $CLI $CLI-$1 $CLI-$1.tar.gz changes.txt rm -r $CLI changes.txt
} }
main() { main() {
local cmd=$1 local cmd=$1
usage usage
requirements
echo "What is your Github username? (location of your $CLI fork)" echo "What is your Github username? (location of your $CLI fork)"
read ORIGIN_REPO read ORIGIN_REPO
echo "You entered: $ORIGIN_REPO" echo "You entered: $ORIGIN_REPO"
@ -220,13 +233,15 @@ main() {
PS3='Please enter your choice: ' PS3='Please enter your choice: '
options=( options=(
"Git clone master" "Initial sync with upstream"
"Replace version number" "Replace version number"
"Generate changelog" "Generate changelog"
"Generate GitHub changelog" "Generate GitHub changelog"
"Create PR" "Create PR"
"Sync with master" "Sync with upstream"
"Create tag"
"Build binaries" "Build binaries"
"Create tarballs"
"Upload the binaries and push to GitHub release page" "Upload the binaries and push to GitHub release page"
"Clean" "Clean"
"Quit") "Quit")
@ -234,8 +249,8 @@ main() {
do do
echo "" echo ""
case $opt in case $opt in
"Git clone master") "Initial sync with upstream")
clone $VERSION init_sync $VERSION
;; ;;
"Replace version number") "Replace version number")
replaceversion $PREV_VERSION $VERSION replaceversion $PREV_VERSION $VERSION
@ -249,12 +264,18 @@ main() {
"Create PR") "Create PR")
git_commit $VERSION git_commit $VERSION
;; ;;
"Sync with master") "Sync with upstream")
git_sync git_sync
;; ;;
"Create tag")
git_tag $VERSION
;;
"Build binaries") "Build binaries")
build_binaries build_binaries
;; ;;
"Create tarballs")
create_tarballs
;;
"Upload the binaries and push to GitHub release page") "Upload the binaries and push to GitHub release page")
push $VERSION push $VERSION
;; ;;