Skip to content

Instantly share code, notes, and snippets.

@fboes
Last active October 28, 2022 10:03
Show Gist options
  • Save fboes/a30eb35a8676bf812e5b726ef7c86ddc to your computer and use it in GitHub Desktop.
Save fboes/a30eb35a8676bf812e5b726ef7c86ddc to your computer and use it in GitHub Desktop.
Publishing project version for Git & NPM
#!/bin/bash
set -e
cd `dirname ${0}`/..
VERSION=${1}
if [[ ! "${1}" ]]; then
echo "Choose on of [patch|minor|major]"
read -r -p "Version bump [patch]: " VERSION
fi
VERSION=${VERSION:-patch}
FEATURE_BRANCH=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
MAIN_BRANCH="main"
#npm test
# On feature branch merge to main branch
if [[ "${FEATURE_BRANCH}" != "${MAIN_BRANCH}" ]]; then
git push
git checkout ${MAIN_BRANCH}
git pull
git merge ${FEATURE_BRANCH} --no-edit
fi
# Add Git Tag
npm version ${VERSION}
git push && git push --tag
# Publish NPM package with OPT
read -r -p "OTP Code: " OTPCODE
npm publish --otp ${OTPCODE}
# Back-merge main branch to feature branch
if [[ "${FEATURE_BRANCH}" != "${MAIN_BRANCH}" ]]; then
git checkout ${FEATURE_BRANCH}
git merge ${MAIN_BRANCH} --no-edit
git push
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment