Skip to content

Commit

Permalink
Chore: Only reset to upstream/master for major/minor releases (#750)
Browse files Browse the repository at this point in the history
* Chore: Only reset to upstream/master for major/minor releases
* Chore: Ensure that the release script never pushes a blank release
* Chore: Add log statements to clarify where script is resetting to
  • Loading branch information
pramodsum authored Mar 30, 2018
1 parent a90bc73 commit aa2b8ab
Showing 1 changed file with 54 additions and 6 deletions.
60 changes: 54 additions & 6 deletions build/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ major_release=false
minor_release=false
patch_release=false


reset_to_master() {
# Update to latest code on GitHub master
git checkout master || return 1

reset_tags() {
# Wipe tags
echo "----------------------------------------------------------------------"
echo "Wiping local tags"
echo "----------------------------------------------------------------------"
git tag -l | xargs git tag -d || return 1

# Add the upstream remote if it is not present
Expand All @@ -26,9 +25,44 @@ reset_to_master() {
fi

# Fetch latest code with tags
echo "----------------------------------------------------------------------"
echo "Fetching latest upstream code + tags"
echo "----------------------------------------------------------------------"
git fetch --tags github-upstream || return 1;
}


reset_to_previous_version() {
if OLD_VERSION === "XXX"; then
echo "----------------------------------------------------------------------"
echo "Error while cleaning workspace!"
echo "----------------------------------------------------------------------"
return 1;
fi

# Reset and fetch upstream with tags
reset_tags || return 1;

# Reset to previous release version and clear unstashed changes
echo "----------------------------------------------------------------------"
echo "Resetting to v" $OLD_VERSION
echo "----------------------------------------------------------------------"
git reset --hard OLD_VERSION || return 1
git clean -f || return 1
}


reset_to_master() {
# Update to latest code on GitHub master
git checkout master || return 1

# Reset and fetch upstream with tags
reset_tags || return 1;

# Reset to latest code and clear unstashed changes
echo "----------------------------------------------------------------------"
echo "Resetting to upstream/master"
echo "----------------------------------------------------------------------"
git reset --hard github-upstream/master || return 1
git clean -f || return 1
}
Expand All @@ -44,6 +78,14 @@ increment_version() {
# Old version
OLD_VERSION=$(./build/current_version.sh)

# The current branch should not match the previous release tag
if [[ $(git log --oneline ...v$OLD_VERSION) == "" ]] ; then
echo "----------------------------------------------------"
echo "Your release has no new commits!"
echo "----------------------------------------------------"
exit 1
fi

if $major_release; then
echo "----------------------------------------------------------------------"
echo "Bumping major version..."
Expand Down Expand Up @@ -205,7 +247,13 @@ if ! push_new_release; then
echo "Cleaning workspace by checking out master and removing tags"
echo "----------------------------------------------------------------------"

if ! reset_to_master; then

if $patch_release; then
# Only reset to previous version for patch releases
reset_to_previous_version || return 1

# Reset to upstream/master for major/minor releases
else if ! reset_to_master; then
echo "----------------------------------------------------------------------"
echo "Error while cleaning workspace!"
echo "----------------------------------------------------------------------"
Expand Down

0 comments on commit aa2b8ab

Please sign in to comment.