mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-23 12:58:55 +00:00
New script to safely publish to npm
This commit is contained in:
parent
401b501aab
commit
924abe2092
@ -1,43 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
# Check if the worktree (or submodules) are dirty.
|
||||
if ! git diff --ignore-submodules=none --no-ext-diff --quiet --exit-code HEAD; then
|
||||
echo 'Publishing requires a clean work tree!' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
GIT_AUTHOR_NAME=$(git config --get user.name)
|
||||
GIT_AUTHOR_EMAIL=$(git config --get user.email)
|
||||
GIT_ORIGIN_URL=$(git ls-remote --get-url origin)
|
||||
|
||||
# Reset these variables just in case they were inherited from the environment.
|
||||
TEMP_DIR=
|
||||
PACKAGE=
|
||||
|
||||
# Cleanup before this script exits.
|
||||
trap 'rm -rf "$TEMP_DIR" "$PACKAGE"' EXIT
|
||||
|
||||
TEMP_DIR=$(mktemp -d -t realm-js)
|
||||
PACKAGE=$(npm pack | tail -n 1)
|
||||
|
||||
tar -xf "$PACKAGE" -C "$TEMP_DIR"
|
||||
|
||||
(
|
||||
cd "$TEMP_DIR/package"
|
||||
|
||||
export GIT_AUTHOR_NAME
|
||||
export GIT_AUTHOR_EMAIL
|
||||
export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
|
||||
export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
|
||||
|
||||
git init
|
||||
git add .
|
||||
git commit -m 'Beta build'
|
||||
git remote add origin "$GIT_ORIGIN_URL"
|
||||
git push -f origin master:beta
|
||||
)
|
80
scripts/publish.sh
Executable file
80
scripts/publish.sh
Executable file
@ -0,0 +1,80 @@
|
||||
#!/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.'
|
||||
|
||||
# Get version in package.json and check if it looks semver compliant.
|
||||
VERSION=$(npm --silent run get-version)
|
||||
[[ $VERION =~ ^[0-9].[0-9]{1,2}.[0-9]{1,2}$ ]] || die "Invalid version number: $VERSION"
|
||||
|
||||
# Update Xcode project to that version and make sure nothing changed.
|
||||
xcrun agvtool new-version "$VERSION" > /dev/null
|
||||
has_clean_worktree || die "Version ($VERSION) was not properly set."
|
||||
|
||||
# Make sure the CHANGELOG has been updated.
|
||||
grep -iq "^${VERSION//./\.} Release notes" CHANGELOG.md || die 'CHANGELOG needs to be updated.'
|
||||
|
||||
# Check that the current branch is valid.
|
||||
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
[[ $BRANCH = 'master' || $BRANCH = "${VERSION%.*}.x" ]] || die "Must publish from master or ${VERSION%.*}.x branch."
|
||||
|
||||
# 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.'
|
||||
|
||||
# Run all tests that must pass before publishing.
|
||||
for test in eslint jsdoc realmjs react-example react-tests react-tests-android; do
|
||||
echo "RUNNING TEST: $test"
|
||||
echo '----------------------------------------'
|
||||
npm test "$test" || die "Test Failed: $test"
|
||||
echo
|
||||
done
|
||||
|
||||
# Double check before actually publishing.
|
||||
confirm "Are you sure you want to publish $VERSION?" || die "Aborted publishing $VERSION"
|
||||
|
||||
# This should fail if this tag already exists.
|
||||
git tag "v$VERSION"
|
||||
|
||||
# Publish to npm, informing the prepublish script to build Android modules.
|
||||
echo "Publishing $VERSION to npm..."
|
||||
REALM_BUILD_ANDROID=1 npm publish .
|
||||
|
||||
# Only push the tag to GitHub if the publish was successful.
|
||||
echo "Pushing v$VERSION tag to GitHub..."
|
||||
git push origin "v$VERSION"
|
Loading…
x
Reference in New Issue
Block a user