diff --git a/bin/generate-npm-tag.sh b/bin/generate-npm-tag.sh new file mode 100644 index 0000000000..99f0658282 --- /dev/null +++ b/bin/generate-npm-tag.sh @@ -0,0 +1,20 @@ +#!/bin/sh +set -e + +# Get highest tag published on Github +HIGHEST_PUBLISHED_VERSION=$(git tag --list 2>/dev/null | sort -V | tail -n1 2>/dev/null | sed 's/v//g') + +# Extract tag version from ./package/package.json +CURRENT_TAG=$(node -p "require('./package/package.json').version") + +function version() { echo "$@" | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'; } + +if [ $CURRENT_TAG == $HIGHEST_PUBLISHED_VERSION ]; then + echo "⚠️ Git tag $TAG already exists. Check you have updated the version in package/package.json correctly." + exit 1 +elif [ $(version $CURRENT_TAG) -ge $(version $HIGHEST_PUBLISHED_VERSION) ]; then + NPM_TAG="latest" +else + major_version_num="${CURRENT_TAG:0:1}" + NPM_TAG="latest-$major_version_num" +fi diff --git a/bin/publish-release.sh b/bin/publish-release.sh index f278f62de4..320c94f574 100755 --- a/bin/publish-release.sh +++ b/bin/publish-release.sh @@ -1,14 +1,29 @@ #!/bin/sh set -e +source ./bin/generate-npm-tag.sh + +# Check NPM tag looks as expected +# https://npm.github.io/publishing-pkgs-docs/updating/using-tags.html#publishing-with-tags +echo "This will publish the package with the following NPM tag:" +echo $NPM_TAG +echo " " + +read -r -p "Does this look correct? [y/N] " continue_prompt + +if [[ $continue_prompt != 'y' ]]; then + read -r -p "What should the NPM tag be: " NPM_TAG +fi + echo "Starting a release..." echo " " echo "This will:" echo "- check that you're logged in to npm as the correct user" -echo "- publish the package if it has not been published already" -echo "- check that there is not already a tag published" -echo "- create a new tag" -echo "- push the tag to remote origin" +echo "- publish the package to NPM if it has not been published already" +echo "- tag the package on NPM with '$NPM_TAG'" +echo "- check that there is not already a Github tag published" +echo "- create a new Github tag" +echo "- push the Github tag to remote origin" echo "- create a zip file of the 'dist/' directory locally" echo " " @@ -34,7 +49,7 @@ echo "📦 Publishing package..." # Try publishing cd package -npm publish +[ $NPM_TAG = "latest" ] && npm publish || npm publish --tag $NPM_TAG echo "🗒 Package published!" cd ..