openai/openai-node

Public

mirrored fromhttps://github.com/openai/openai-nodeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
main

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

bin/publish-npm

70lines · modecode

1#!/usr/bin/env bash
2
3set -eux
4
5if [[ ${NPM_TOKEN:-} ]]; then
6 npm config set '//registry.npmjs.org/:_authToken' "$NPM_TOKEN"
7elif [[ ! ${ACTIONS_ID_TOKEN_REQUEST_TOKEN:-} ]]; then
8 echo "ERROR: NPM_TOKEN must be set if not running in a Github Action with id-token permission"
9 exit 1
10fi
11
12yarn build
13cd dist
14
15# Get package name and version from package.json
16PACKAGE_NAME="$(jq -r -e '.name' ./package.json)"
17VERSION="$(jq -r -e '.version' ./package.json)"
18
19# Get latest version from npm
20#
21# If the package doesn't exist, npm will return:
22# {
23# "error": {
24# "code": "E404",
25# "summary": "Unpublished on 2025-06-05T09:54:53.528Z",
26# "detail": "'the_package' is not in this registry..."
27# }
28# }
29NPM_INFO="$(npm view "$PACKAGE_NAME" version --json 2>/dev/null || true)"
30
31# Check if we got an E404 error
32if echo "$NPM_INFO" | jq -e '.error.code == "E404"' > /dev/null 2>&1; then
33 # Package doesn't exist yet, no last version
34 LAST_VERSION=""
35elif echo "$NPM_INFO" | jq -e '.error' > /dev/null 2>&1; then
36 # Report other errors
37 echo "ERROR: npm returned unexpected data:"
38 echo "$NPM_INFO"
39 exit 1
40else
41 # Success - get the version
42 LAST_VERSION=$(echo "$NPM_INFO" | jq -r '.') # strip quotes
43fi
44
45# Check if current version is pre-release (e.g. alpha / beta / rc)
46CURRENT_IS_PRERELEASE=false
47if [[ "$VERSION" =~ -([a-zA-Z]+) ]]; then
48 CURRENT_IS_PRERELEASE=true
49 CURRENT_TAG="${BASH_REMATCH[1]}"
50fi
51
52# Check if last version is a stable release
53LAST_IS_STABLE_RELEASE=true
54if [[ -z "$LAST_VERSION" || "$LAST_VERSION" =~ -([a-zA-Z]+) ]]; then
55 LAST_IS_STABLE_RELEASE=false
56fi
57
58# Use a corresponding alpha/beta tag if there already is a stable release and we're publishing a prerelease.
59if $CURRENT_IS_PRERELEASE && $LAST_IS_STABLE_RELEASE; then
60 TAG="$CURRENT_TAG"
61else
62 TAG="latest"
63fi
64
65# Install OIDC compatible npm version
66npm install --prefix ../oidc/ npm@11.6.2
67
68# Publish with the appropriate tag
69export npm_config_registry='https://registry.npmjs.org'
70../oidc/node_modules/.bin/npm publish --tag "$TAG"
71