Skip to content

Instantly share code, notes, and snippets.

@blendsdk
Last active August 1, 2018 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blendsdk/517a845162cb3ce80ae1e565837098a7 to your computer and use it in GitHub Desktop.
Save blendsdk/517a845162cb3ce80ae1e565837098a7 to your computer and use it in GitHub Desktop.
#!/bin/bash
# This bash script will try to create a new relase and publish an
# npm package at the same time
function confirm()
{
echo -n "$@ "
read -e answer
for response in y Y yes YES Yes Sure sure SURE OK ok Ok
do
if [ "_$answer" == "_$response" ]
then
return 0
fi
done
# Any answer other than the list above is considerred a "no" answer
return 1
}
function npm_publish() {
if [ ! -f ".no-publish" ]
then
echo "Publishing package"
npm publish
else
echo "Skipping NPM publish"
fi
return 0
}
branch_name=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
if [ "$branch_name" != "devel" ]
then
echo "You are not on a development branch! ($branch_name)";
exit 1;
fi
if [ ! -f "gruntfile.js" ]
then
echo "No gruntfile.js found!"
exit 1;
fi
if [ ! -f "package.json" ]
then
echo "No packahe.json found!"
exit 1;
fi
semver=${1:-patch}
confirm "Creating a $semver version. Are you sure (y/N)?"
if [ $? -eq 0 ]
then
version=$(npm version $semver --no-git-tag-version)
grunt && \
git add . && \
git commit -am "Savepoint release $version" && \
git push origin devel && \
git checkout master && \
git fetch && \
git pull && \
git merge devel --no-ff && \
grunt && \
git tag -a $version -m "Release $version" && \
git push origin master --tags && \
npm_publish && \
git checkout devel && \
echo Done releasing $version!
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment