whatsapp-web.js/tools/publish

108 lines
2.1 KiB
Shell
Executable file

#!/bin/bash
set -e
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
# Note: When running in GitHub Actions with trusted publishing (OIDC),
# npm whoami won't work as OIDC auth only applies during npm publish.
# For local publishing, ensure you're logged in with 'npm login'.
if [[ -z "$CI" ]] && ! npm whoami &> /dev/null; then
echo "Not authenticated with npm. Run 'npm login' to authenticate."
exit 1
fi
if [[ -z "$CI" ]]; then
echo "Publishing as NPM user: $(npm whoami)"
else
echo "Publishing via GitHub Actions OIDC trusted publishing"
fi
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 --no-git-tag-version
NEW_VERSION=$(cat package.json | jq -r .version)
echo "New Version: $NEW_VERSION"
echo ""
echo "-----> GENERATE DOCS"
echo ""
npm install
npm run generate-docs
echo ""
echo "-----> PUSH TO NPM"
echo ""
npm publish --tag $DIST_TAG
echo ""
echo "-----> PUSH TO GIT"
echo ""
git add .
git commit -am "chore(v${NEW_VERSION}): bump version and generate docs"
git tag "v${NEW_VERSION}"
git push && git push --tags
echo ""
echo "-----> Done!"
echo "Version $NEW_VERSION published to $DIST_TAG tag"
echo ""
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "PRERELEASE=$PRERELEASE" >> $GITHUB_OUTPUT