Last active
June 5, 2018 08:41
-
-
Save arjun-kava/81f4b3bfed8a1667d187394d69ded3b5 to your computer and use it in GitHub Desktop.
automation of publish npm package and tag
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
# script used to publish package to npm and push new tag | |
# step 1 - change version from package json | |
# step 2 - run ./scripts/publish-npm.sh $version i.e ./scripts/publish-npm.sh 0.0.3 | |
set -e | |
if [ $# -eq 0 ] | |
then | |
echo "Please specify version." | |
exit | |
fi | |
PACKAGE_NAME="yolonode-js-build" | |
DEPENDENT_OPENCV_PACKAGE_NAME="opencvnode-js-build" | |
# if you forget to commit | |
PORCELAIN=`git status --porcelain` | |
if [ -n "$PORCELAIN" ]; then | |
echo "Please commit changes first."; | |
echo $PORCELAIN | |
exit; | |
fi | |
BRANCH=`git rev-parse --abbrev-ref HEAD` | |
ORIGIN=`git config --get remote.origin.url` | |
if [ "$BRANCH" != "master" ]; then | |
echo "Error: Switch to the master branch before publishing." | |
exit | |
fi | |
if ! [[ "$ORIGIN" =~ $PACKAGE_NAME ]]; then | |
echo "Error: Switch to the main repo ($PACKAGE_NAME) before publishing." | |
exit | |
fi | |
# Build CPU: | |
npm pack | |
npm publish | |
echo "⌛ ⌛ Published ${PACKAGE_NAME} a new package to npm." | |
# Build GPU: | |
sed -i -e "s/${PACKAGE_NAME}/${PACKAGE_NAME}-gpu/" package.json | |
sed -i -e "s/${DEPENDENT_OPENCV_PACKAGE_NAME}/${DEPENDENT_OPENCV_PACKAGE_NAME}-gpu/" package.json | |
npm pack | |
npm publish | |
echo "⌛ ⌛ Published ${PACKAGE_NAME}-gpu to npm." | |
# Revert GPU changes: | |
git checkout . | |
if [ $# -ne 0 ] | |
then | |
git push # verify everthing on cloud before creting tag | |
git tag $1 | |
git push --tags | |
rm -rf $PACKAGE_NAME-*.tgz | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment