-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
55 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,19 @@ export NODE_PATH=$NODE_PATH:./node_modules | |
OLD_VERSION="XXX" | ||
VERSION="XXX" | ||
|
||
dry_run=false | ||
|
||
# Wraps mutating commands with echo if dry_run is enabled. | ||
cmd() { | ||
if $dry_run; then | ||
echo "The build script would run $*" | ||
return 0 | ||
fi | ||
|
||
eval "$@" | ||
|
||
return 0 | ||
} | ||
|
||
# Major, minor, or patch release | ||
major_release=false | ||
|
@@ -17,69 +30,65 @@ reset_tags() { | |
echo "----------------------------------------------------------------------" | ||
echo "Wiping local tags" | ||
echo "----------------------------------------------------------------------" | ||
git tag -l | xargs git tag -d || return 1 | ||
cmd git tag -l | xargs git tag -d || return 1 | ||
|
||
# Add the upstream remote if it is not present | ||
if ! git remote get-url github-upstream; then | ||
git remote add github-upstream [email protected]:box/box-content-preview.git || return 1 | ||
cmd git remote add github-upstream [email protected]:box/box-content-preview.git || return 1 | ||
fi | ||
|
||
# Fetch latest code with tags | ||
echo "----------------------------------------------------------------------" | ||
echo "Fetching latest upstream code + tags" | ||
echo "----------------------------------------------------------------------" | ||
git fetch --tags github-upstream || return 1; | ||
cmd 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; | ||
return 1 | ||
fi | ||
|
||
# Reset and fetch upstream with tags | ||
reset_tags || return 1; | ||
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 | ||
cmd git reset --hard OLD_VERSION || return 1 | ||
cmd git clean -f || return 1 | ||
} | ||
|
||
|
||
reset_to_master() { | ||
# Update to latest code on GitHub master | ||
git checkout master || return 1 | ||
cmd git checkout master || return 1 | ||
|
||
# Reset and fetch upstream with tags | ||
reset_tags || return 1; | ||
cmd 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 | ||
cmd git reset --hard github-upstream/master || return 1 | ||
cmd git clean -f || return 1 | ||
} | ||
|
||
|
||
build_lint_and_test() { | ||
# The build command includes linting | ||
yarn build && yarn test || return 1 | ||
cmd yarn build && cmd yarn test || return 1 | ||
} | ||
|
||
|
||
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 | ||
if [[ $(git log --oneline ...v$OLD_VERSION) == "" ]]; then | ||
echo "----------------------------------------------------" | ||
echo "Your release has no new commits!" | ||
echo "----------------------------------------------------" | ||
|
@@ -107,13 +116,12 @@ increment_version() { | |
VERSION=$(./build/current_version.sh) | ||
} | ||
|
||
|
||
update_changelog() { | ||
echo "----------------------------------------------------------------------" | ||
echo "Updating CHANGELOG.md" | ||
echo "----------------------------------------------------------------------" | ||
|
||
if ./node_modules/.bin/conventional-changelog -i CHANGELOG.md --same-file; then | ||
if cmd ./node_modules/.bin/conventional-changelog -i CHANGELOG.md --same-file; then | ||
echo "----------------------------------------------------------------------" | ||
echo "Updated CHANGELOG successfully" | ||
echo "----------------------------------------------------------------------" | ||
|
@@ -125,36 +133,34 @@ update_changelog() { | |
fi | ||
} | ||
|
||
|
||
update_readme() { | ||
echo "----------------------------------------------------------------------" | ||
echo "Updating README" | ||
echo "----------------------------------------------------------------------" | ||
|
||
# Replace 'v{VERSION}' string | ||
sed -i -e "s@v$OLD_VERSION@v$VERSION@g" README.md | ||
cmd sed -i -e "s@v$OLD_VERSION@v$VERSION@g" README.md | ||
|
||
# Replace 'preview/{VERSION}' string | ||
sed -i -e "s@preview/$OLD_VERSION@preview/$VERSION@g" README.md | ||
cmd sed -i -e "s@preview/$OLD_VERSION@preview/$VERSION@g" README.md | ||
|
||
rm README.md-e | ||
cmd rm README.md-e | ||
} | ||
|
||
|
||
push_to_github() { | ||
# Add new files | ||
git commit -am "chore(release): $VERSION" | ||
cmd git commit -am "chore(release): $VERSION" | ||
|
||
# Force update tag after updating files | ||
git tag -a v$VERSION -m $VERSION | ||
cmd git tag -a v$VERSION -m $VERSION | ||
|
||
echo "----------------------------------------------------------------------" | ||
echo "Master version is now at" $VERSION | ||
echo "----------------------------------------------------------------------" | ||
|
||
# Push release to GitHub | ||
if $patch_release; then | ||
if git push github-upstream v$VERSION --no-verify; then | ||
if cmd git push github-upstream v$VERSION --no-verify; then | ||
echo "----------------------------------------------------------------------" | ||
echo "Pushed version" $VERSION "to git successfully" | ||
echo "----------------------------------------------------------------------" | ||
|
@@ -165,7 +171,7 @@ push_to_github() { | |
return 1 | ||
fi | ||
else | ||
if git push github-upstream master --tags --no-verify; then | ||
if cmd git push github-upstream master --tags --no-verify; then | ||
echo "----------------------------------------------------------------------" | ||
echo "Pushed version" $VERSION "to git successfully" | ||
echo "----------------------------------------------------------------------" | ||
|
@@ -181,6 +187,12 @@ push_to_github() { | |
# Check out latest code from git, build assets, increment version, and push tags | ||
push_new_release() { | ||
# Get latest commited code and tags | ||
if $dry_run; then | ||
echo "----------------------------------------------------------------------" | ||
echo "Running in Dry Run Mode!" | ||
echo "----------------------------------------------------------------------" | ||
fi | ||
|
||
if $patch_release; then | ||
echo "----------------------------------------------------------------------" | ||
echo "Starting patch release - skipping reset to master" | ||
|
@@ -217,21 +229,26 @@ push_new_release() { | |
echo "----------------------------------------------------------------------" | ||
echo "Pushing new GitHub release" | ||
echo "----------------------------------------------------------------------" | ||
./node_modules/.bin/conventional-github-releaser | ||
cmd ./node_modules/.bin/conventional-github-releaser | ||
|
||
return 0 | ||
} | ||
|
||
|
||
# Check if we are doing major, minor, or patch release | ||
while getopts "mnp" opt; do | ||
while getopts "mnpd" opt; do | ||
case "$opt" in | ||
m ) | ||
major_release=true ;; | ||
n ) | ||
minor_release=true ;; | ||
p ) | ||
patch_release=true ;; | ||
m) | ||
major_release=true | ||
;; | ||
n) | ||
minor_release=true | ||
;; | ||
p) | ||
patch_release=true | ||
;; | ||
d) | ||
dry_run=true | ||
;; | ||
esac | ||
done | ||
|
||
|
@@ -245,7 +262,6 @@ if ! push_new_release; then | |
echo "Cleaning workspace by checking out master and removing tags" | ||
echo "----------------------------------------------------------------------" | ||
|
||
|
||
if $patch_release; then | ||
# Only reset to previous version for patch releases | ||
reset_to_previous_version || return 1 | ||
|
@@ -259,6 +275,6 @@ if ! push_new_release; then | |
echo "----------------------------------------------------------------------" | ||
echo "Workspace succesfully cleaned!" | ||
echo "----------------------------------------------------------------------" | ||
fi; | ||
fi | ||
exit 1 | ||
fi |