Skip to content

Instantly share code, notes, and snippets.

@arjun-kava
Last active June 5, 2018 08:41
Show Gist options
  • Save arjun-kava/81f4b3bfed8a1667d187394d69ded3b5 to your computer and use it in GitHub Desktop.
Save arjun-kava/81f4b3bfed8a1667d187394d69ded3b5 to your computer and use it in GitHub Desktop.
automation of publish npm package and tag
# 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