2016-03-03 11:59:52 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
die() {
|
|
|
|
echo "$@" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
confirm() {
|
|
|
|
local choice
|
|
|
|
while true; do
|
|
|
|
read -r -p "$1 (y/n) " -n 1 choice
|
|
|
|
echo
|
|
|
|
case "$choice" in
|
|
|
|
y|Y ) return 0;;
|
|
|
|
n|N ) return 1;;
|
|
|
|
* ) echo "It's a simple yes or no question!" >&2
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
has_clean_worktree() {
|
|
|
|
git diff --ignore-submodules=none --no-ext-diff --quiet --exit-code HEAD
|
|
|
|
}
|
|
|
|
|
|
|
|
has_no_untracked_files() {
|
|
|
|
test -z "$(git ls-files --others --exclude-standard)"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Start in the root directory of the project.
|
|
|
|
cd "$(dirname "$0")/.."
|
|
|
|
|
|
|
|
# Check if the worktree (or submodules) are dirty.
|
|
|
|
has_clean_worktree || die 'Publishing requires a clean working tree.'
|
|
|
|
|
|
|
|
# Check if there are untracked files that may accidentally get published.
|
|
|
|
has_no_untracked_files || die 'Publishing requires no untracked files.'
|
|
|
|
|
2016-03-16 18:19:09 +00:00
|
|
|
# Make sure all npm modules are installed and updated.
|
|
|
|
npm install > /dev/null
|
|
|
|
|
2016-03-23 22:30:46 +00:00
|
|
|
# Get version in package.json (stripping prerelease qualifier for the "release" version).
|
2016-03-03 11:59:52 +00:00
|
|
|
VERSION=$(npm --silent run get-version)
|
2016-03-23 22:30:46 +00:00
|
|
|
RELEASE_VERSION="${VERSION%%-*}"
|
2016-03-03 11:59:52 +00:00
|
|
|
|
|
|
|
# Update Xcode project to that version and make sure nothing changed.
|
2016-03-23 22:30:46 +00:00
|
|
|
npm --silent run set-version -- --force "$VERSION"
|
2016-03-16 18:19:09 +00:00
|
|
|
has_clean_worktree || die "Version $RELEASE_VERSION was not properly set on Xcode project."
|
2016-03-03 11:59:52 +00:00
|
|
|
|
|
|
|
# Make sure the CHANGELOG has been updated.
|
2016-03-16 18:19:09 +00:00
|
|
|
grep -iq "^${RELEASE_VERSION//./\.} Release notes" CHANGELOG.md || die 'CHANGELOG needs to be updated.'
|
2016-03-03 11:59:52 +00:00
|
|
|
|
|
|
|
# Check that the current branch is valid.
|
|
|
|
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
2016-03-16 18:19:09 +00:00
|
|
|
VERSION_BRANCH="${RELEASE_VERSION%.*}.x"
|
|
|
|
[[ $BRANCH = 'master' || $BRANCH = $VERSION_BRANCH ]] || die "Must publish from master or $VERSION_BRANCH branch."
|
2016-03-03 11:59:52 +00:00
|
|
|
|
|
|
|
# Check that this master branch is up to date with GitHub.
|
|
|
|
git fetch origin || die 'Failed to fetch from git origin.'
|
|
|
|
[ -z "$(git rev-list origin/$BRANCH..HEAD)" ] || die 'Local commits are not pushed to origin.'
|
|
|
|
|
|
|
|
# Double check before actually publishing.
|
2017-08-30 11:09:40 +00:00
|
|
|
confirm "Are you sure you want to publish $VERSION? (Did you run all tests)?" || die "Aborted publishing $VERSION"
|
2016-03-03 11:59:52 +00:00
|
|
|
|
|
|
|
# This should fail if this tag already exists.
|
|
|
|
git tag "v$VERSION"
|
|
|
|
|
2016-03-16 23:48:04 +00:00
|
|
|
# Delete Android build directory so no stale files are accidentally included.
|
|
|
|
rm -rf react-native/android/build
|
|
|
|
|
2016-03-03 11:59:52 +00:00
|
|
|
# Publish to npm, informing the prepublish script to build Android modules.
|
|
|
|
echo "Publishing $VERSION to npm..."
|
2016-05-26 20:31:39 +00:00
|
|
|
PRERELEASE=$(grep -Eio '[a-z]+' <<< "$VERSION" || true)
|
2016-03-16 18:19:09 +00:00
|
|
|
REALM_BUILD_ANDROID=1 npm publish ${PRERELEASE:+--tag $PRERELEASE}
|
2016-03-03 11:59:52 +00:00
|
|
|
|
|
|
|
# Only push the tag to GitHub if the publish was successful.
|
|
|
|
echo "Pushing v$VERSION tag to GitHub..."
|
|
|
|
git push origin "v$VERSION"
|
2017-08-30 11:09:40 +00:00
|
|
|
|
|
|
|
echo "Done. Now, you should update the documentation!"
|