whatsapp-web.js/tools/publish
Rajeh Taher 9847ebadb9
Make an NPM release via GitHub (#2942)
* Update release.yml

* Update publish

* Update release.yml

* Update publish

* Update publish: publish new docs before new version release

* Update publish

* Update publish

---------

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
2024-06-05 00:38:10 +03:00

99 lines
1.8 KiB
Shell
Executable file

#!/bin/bash
cd "$(dirname "$0")"
cd '..'
BRANCH=`git rev-parse --abbrev-ref HEAD`
RELEASE_MODE=$1
echo ""
echo "-----> CHECK INPUTS"
echo ""
if [[ "$RELEASE_MODE" == "alpha" ]]
then
PRERELEASE='true'
VERSION_ARGS="prerelease --preid alpha"
DIST_TAG="next"
elif [[ "$RELEASE_MODE" == "alpha-minor" ]]
then
PRERELEASE='true'
VERSION_ARGS="preminor --preid alpha"
DIST_TAG="next"
elif [[ "$RELEASE_MODE" == "alpha-major" ]]
then
PRERELEASE='true'
VERSION_ARGS="premajor --preid alpha"
DIST_TAG="next"
elif [[ "$RELEASE_MODE" == "release-patch" ]]
then
PRERELEASE='false'
VERSION_ARGS="patch"
DIST_TAG="latest"
elif [[ "$RELEASE_MODE" == "release-minor" ]]
then
PRERELEASE='false'
VERSION_ARGS="minor"
DIST_TAG="latest"
else
echo 'Release Mode required'
exit 1
fi
if [ -f ~/.npmrc ]; then
echo "Found existing .npmrc"
else
if [[ -z "$NPM_TOKEN" ]];then
echo "No NPM_TOKEN or ~/.npmrc, exiting.."
exit 1;
else
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
fi
fi
echo "Publishing as NPM user: `npm whoami`"
if [[ $BRANCH != 'main' ]]; then
echo "Not on 'main' branch. Exiting"
exit 1
fi
if [[ -n $(git status -s) ]]; then
echo "There are uncommitted changes on this branch. Exiting..."
exit 1
fi
echo ""
echo "-----> BUMP VERSION"
echo ""
npm version $VERSION_ARGS || exit 1
git push && git push --tags || exit 1
npm run generate-docs
git add .
git commit -am "chore(${NEW_VERSION}): generate docs"
git push
NEW_VERSION=`cat package.json | jq -r .version`
echo "New Version: $NEW_VERSION"
echo ""
echo "-----> PUSH TO NPM"
echo ""
npm publish --tag $DIST_TAG
echo ""
echo "-----> Done!"
echo "Version $NEW_VERSION published to $DIST_TAG tag"
echo ""
echo "::set-output name=NEW_VERSION::$NEW_VERSION"
echo "::set-output name=PRERELEASE::$PRERELEASE"
exit 0