#!/bin/bash
set -euxo pipefail

VERSION=$(cat package.json | jq -r '.version')
NAME=$(cat package.json | jq -r '.name')

test -z "$(npm info $NAME@$VERSION)"
if [ $? -eq 0 ]; then
	set -e

	# git config --global user.email "ci@ritbit.trade"
	# git config --global user.name "gitlab_actions"
	
	npm publish

	# Get version and tag
	git tag ritbit-client-js@${VERSION}
	git push --tags
else
	echo "skipping publish, package $NAME@$VERSION already published"
fi
