@@ -4,19 +4,35 @@ set -eux
4
4
5
5
npm config set ' //registry.npmjs.org/:_authToken' " $NPM_TOKEN "
6
6
7
- # Build the project
8
7
yarn build
9
-
10
- # Navigate to the dist directory
11
8
cd dist
12
9
13
- # Get the version from package.json
10
+ # Get latest version from npm
11
+ #
12
+ # If the package doesn't exist, yarn will return
13
+ # {"type":"error","data":"Received invalid response from npm."}
14
+ # where .data.version doesn't exist so LAST_VERSION will be an empty string.
15
+ LAST_VERSION=" $( yarn info --json 2> /dev/null | jq -r ' .data.version' ) "
16
+
17
+ # Get current version from package.json
14
18
VERSION=" $( node -p " require('./package.json').version" ) "
15
19
16
- # Extract the pre-release tag if it exists
20
+ # Check if current version is pre-release (e.g. alpha / beta / rc)
21
+ CURRENT_IS_PRERELEASE=false
17
22
if [[ " $VERSION " =~ -([a-zA-Z]+) ]]; then
18
- # Extract the part before any dot in the pre-release identifier
19
- TAG=" ${BASH_REMATCH[1]} "
23
+ CURRENT_IS_PRERELEASE=true
24
+ CURRENT_TAG=" ${BASH_REMATCH[1]} "
25
+ fi
26
+
27
+ # Check if last version is a stable release
28
+ LAST_IS_STABLE_RELEASE=true
29
+ if [[ -z " $LAST_VERSION " || " $LAST_VERSION " =~ -([a-zA-Z]+) ]]; then
30
+ LAST_IS_STABLE_RELEASE=false
31
+ fi
32
+
33
+ # Use a corresponding alpha/beta tag if there already is a stable release and we're publishing a prerelease.
34
+ if $CURRENT_IS_PRERELEASE && $LAST_IS_STABLE_RELEASE ; then
35
+ TAG=" $CURRENT_TAG "
20
36
else
21
37
TAG=" latest"
22
38
fi
0 commit comments