Add test for package version already exists

This commit is contained in:
2023-01-06 10:20:18 -07:00
parent af1aee09ff
commit d77a42b36f
3 changed files with 19 additions and 7 deletions
@@ -1,7 +1,7 @@
#!/bin/bash
# Usage: build-npm-package.sh <registry-url> <publish-with-this-version>
# Note: supply the registry auth token in CERC_NPM_AUTH_TOKEN
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
if [[ -n "$CERC_SCRIPT_DEBUG" ]]; then
set -x
fi
if ! [[ $# -eq 1 || $# -eq 2 ]]; then
@@ -17,11 +17,19 @@ if [[ $# -eq 2 ]]; then
else
package_publish_version=$( cat package.json | jq -r .version )
fi
# Get the name of this package from package.json since we weren't passed that
package_name=$( cat package.json | jq -r .name )
local_npm_registry_url=$1
npm config set @lirewine:registry ${local_npm_registry_url}
npm config set @cerc-io:registry ${local_npm_registry_url}
npm config set -- ${local_npm_registry_url}:_authToken ${CERC_NPM_AUTH_TOKEN}
echo "Build and publish version ${package_publish_version}"
# First check if the version of this package we're trying to build already exists in the registry
package_exists=$( yarn info --json ${package_name}@${package_publish_version} | jq -r .data.dist.tarball )
if [[ -n "$package_exists" ]]; then
echo "${package_publish_version} of ${package_name} already exists in the registry, skipping build"
exit 0
fi
echo "Build and publish ${package_name} version ${package_publish_version}"
yarn install
yarn build
yarn publish --non-interactive --new-version ${package_publish_version} --no-git-tag-version