summaryrefslogtreecommitdiffhomepage
path: root/packages/sdk/bin
diff options
context:
space:
mode:
authoradamdotdevin <[email protected]>2025-07-22 11:50:51 -0500
committeradamdotdevin <[email protected]>2025-07-22 11:50:51 -0500
commit10c8b495907069461f5dc464f6285321290c8b14 (patch)
tree9fed07910dd7d99688c0261a364d810a500e21d3 /packages/sdk/bin
parent500cea5ce7fa635a924cd9abea63aaf672f7645d (diff)
downloadopencode-10c8b495907069461f5dc464f6285321290c8b14.tar.gz
opencode-10c8b495907069461f5dc464f6285321290c8b14.zip
chore: generate sdk into packages/sdk
Diffstat (limited to 'packages/sdk/bin')
-rw-r--r--packages/sdk/bin/check-release-environment22
-rw-r--r--packages/sdk/bin/publish-npm61
2 files changed, 83 insertions, 0 deletions
diff --git a/packages/sdk/bin/check-release-environment b/packages/sdk/bin/check-release-environment
new file mode 100644
index 000000000..e4b6d58ea
--- /dev/null
+++ b/packages/sdk/bin/check-release-environment
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+errors=()
+
+if [ -z "${NPM_TOKEN}" ]; then
+ errors+=("The NPM_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets")
+fi
+
+lenErrors=${#errors[@]}
+
+if [[ lenErrors -gt 0 ]]; then
+ echo -e "Found the following errors in the release environment:\n"
+
+ for error in "${errors[@]}"; do
+ echo -e "- $error\n"
+ done
+
+ exit 1
+fi
+
+echo "The environment is ready to push releases!"
+
diff --git a/packages/sdk/bin/publish-npm b/packages/sdk/bin/publish-npm
new file mode 100644
index 000000000..fa2243d24
--- /dev/null
+++ b/packages/sdk/bin/publish-npm
@@ -0,0 +1,61 @@
+#!/usr/bin/env bash
+
+set -eux
+
+npm config set '//registry.npmjs.org/:_authToken' "$NPM_TOKEN"
+
+yarn build
+cd dist
+
+# Get package name and version from package.json
+PACKAGE_NAME="$(jq -r -e '.name' ./package.json)"
+VERSION="$(jq -r -e '.version' ./package.json)"
+
+# Get latest version from npm
+#
+# If the package doesn't exist, npm will return:
+# {
+# "error": {
+# "code": "E404",
+# "summary": "Unpublished on 2025-06-05T09:54:53.528Z",
+# "detail": "'the_package' is not in this registry..."
+# }
+# }
+NPM_INFO="$(npm view "$PACKAGE_NAME" version --json 2>/dev/null || true)"
+
+# Check if we got an E404 error
+if echo "$NPM_INFO" | jq -e '.error.code == "E404"' > /dev/null 2>&1; then
+ # Package doesn't exist yet, no last version
+ LAST_VERSION=""
+elif echo "$NPM_INFO" | jq -e '.error' > /dev/null 2>&1; then
+ # Report other errors
+ echo "ERROR: npm returned unexpected data:"
+ echo "$NPM_INFO"
+ exit 1
+else
+ # Success - get the version
+ LAST_VERSION=$(echo "$NPM_INFO" | jq -r '.') # strip quotes
+fi
+
+# Check if current version is pre-release (e.g. alpha / beta / rc)
+CURRENT_IS_PRERELEASE=false
+if [[ "$VERSION" =~ -([a-zA-Z]+) ]]; then
+ CURRENT_IS_PRERELEASE=true
+ CURRENT_TAG="${BASH_REMATCH[1]}"
+fi
+
+# Check if last version is a stable release
+LAST_IS_STABLE_RELEASE=true
+if [[ -z "$LAST_VERSION" || "$LAST_VERSION" =~ -([a-zA-Z]+) ]]; then
+ LAST_IS_STABLE_RELEASE=false
+fi
+
+# Use a corresponding alpha/beta tag if there already is a stable release and we're publishing a prerelease.
+if $CURRENT_IS_PRERELEASE && $LAST_IS_STABLE_RELEASE; then
+ TAG="$CURRENT_TAG"
+else
+ TAG="latest"
+fi
+
+# Publish with the appropriate tag
+yarn publish --access public --tag "$TAG"