Skip to content

Commit 79e2df1

Browse files
feat: publish to jsr (#1165)
1 parent 3f3c78b commit 79e2df1

17 files changed

+88
-437
lines changed

.github/workflows/create-releases.yml

+2-20
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,12 @@ jobs:
2222
repo: ${{ github.event.repository.full_name }}
2323
stainless-api-key: ${{ secrets.STAINLESS_API_KEY }}
2424

25-
- name: Generate a token
26-
id: generate_token
27-
uses: actions/create-github-app-token@v1
28-
with:
29-
app-id: ${{ secrets.APP_ID }}
30-
private-key: ${{ secrets.APP_PRIVATE_KEY }}
31-
owner: 'openai'
32-
repositories: 'openai-node,openai-deno-build'
33-
3425
- name: Set up Node
3526
if: ${{ steps.release.outputs.releases_created }}
3627
uses: actions/setup-node@v3
3728
with:
3829
node-version: '18'
3930

40-
- name: Set up Deno
41-
if: ${{ steps.release.outputs.releases_created }}
42-
uses: denoland/setup-deno@v1
43-
with:
44-
deno-version: v1.35.1
45-
4631
- name: Install dependencies
4732
if: ${{ steps.release.outputs.releases_created }}
4833
run: |
@@ -55,11 +40,8 @@ jobs:
5540
env:
5641
NPM_TOKEN: ${{ secrets.OPENAI_NPM_TOKEN || secrets.NPM_TOKEN }}
5742

58-
- name: Publish to Deno
43+
- name: Publish to JSR
5944
if: ${{ steps.release.outputs.releases_created }}
6045
run: |
61-
bash ./scripts/git-publish-deno.sh
62-
env:
63-
DENO_PUSH_REMOTE_URL: https://username:${{ steps.generate_token.outputs.token }}@github.com/openai/openai-deno-build.git
64-
DENO_PUSH_BRANCH: main
46+
bash ./bin/publish-jsr
6547

.github/workflows/publish-deno.yml

-44
This file was deleted.

.github/workflows/publish-jsr.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# workflow for re-running publishing to JSR in case it fails for some reason
2+
# you can run this workflow by navigating to https://www.github.com/openai/openai-node/actions/workflows/publish-jsr.yml
3+
name: Publish JSR
4+
on:
5+
workflow_dispatch:
6+
7+
jobs:
8+
publish:
9+
name: publish
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write
14+
environment: publish
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Node
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: '18'
23+
24+
- name: Install dependencies
25+
run: |
26+
yarn install
27+
28+
- name: Publish to JSR
29+
run: |
30+
bash ./bin/publish-jsr

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ yarn-error.log
44
codegen.log
55
Brewfile.lock.json
66
dist
7-
/deno
7+
dist-deno
88
/*.tgz
99
.idea/
1010

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# OpenAI Node API Library
22

3-
[![NPM version](https://img.shields.io/npm/v/openai.svg)](https://npmjs.org/package/openai) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/openai)
3+
[![NPM version](https://img.shields.io/npm/v/openai.svg)](https://npmjs.org/package/openai) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/openai) [![JSR Version](https://jsr.io/badges/@openai/openai)](https://jsr.io/@openai/openai)
44

55
This library provides convenient access to the OpenAI REST API from server-side TypeScript or JavaScript.
66

@@ -12,12 +12,12 @@ The REST API documentation can be found on [platform.openai.com](https://platfor
1212
npm install openai
1313
```
1414

15-
You can import in Deno via:
15+
You can also import from jsr:
1616

1717
<!-- x-release-please-start-version -->
1818

1919
```ts
20-
import OpenAI from 'https://deno.land/x/openai@v4.47.1/mod.ts';
20+
import OpenAI from 'jsr:@openai/openai';
2121
```
2222

2323
<!-- x-release-please-end -->

bin/publish-jsr

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
5+
# Build the project
6+
yarn build
7+
8+
# Navigate to the dist directory
9+
cd dist-deno
10+
11+
npx jsr publish ${JSR_TOKEN:+"--token=$JSR_TOKEN"}

jsr.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@openai/openai",
3+
"version": "4.47.1",
4+
"exports": "./index.ts",
5+
"publish": {
6+
"exclude": ["!."]
7+
}
8+
}

release-please-config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@
6363
"extra-files": [
6464
"src/version.ts",
6565
"README.md",
66-
"scripts/build-deno"
66+
"jsr.json"
6767
]
6868
}

scripts/build-deno

+5-36
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,16 @@ set -exuo pipefail
44

55
cd "$(dirname "$0")/.."
66

7-
rm -rf deno; mkdir deno
8-
cp -rp src/* deno
7+
rm -rf dist-deno; mkdir dist-deno
8+
cp -rp src/* jsr.json dist-deno
99

10-
# x-release-please-start-version
11-
cat << EOF > deno/README.md
12-
# OpenAI Node API Library - Deno build
13-
14-
This is a build produced from https://github.com/openai/openai-node – please go there to read the source and docs, file issues, etc.
15-
16-
Usage:
17-
18-
\`\`\`ts
19-
import OpenAI from "https://deno.land/x/openai@v4.47.1/mod.ts";
20-
21-
const client = new OpenAI();
22-
\`\`\`
23-
24-
Note that in most Deno environments, you can also do this:
25-
26-
\`\`\`ts
27-
import OpenAI from "npm:openai";
28-
\`\`\`
29-
EOF
30-
# x-release-please-end
31-
32-
rm deno/_shims/auto/*-node.ts
33-
for dir in deno/_shims deno/_shims/auto; do
10+
rm dist-deno/_shims/auto/*-node.ts
11+
for dir in dist-deno/_shims dist-deno/_shims/auto; do
3412
rm "${dir}"/*.{d.ts,js,mjs}
3513
for file in "${dir}"/*-deno.ts; do
3614
mv -- "$file" "${file%-deno.ts}.ts"
3715
done
3816
done
3917
for file in LICENSE CHANGELOG.md; do
40-
if [ -e "${file}" ]; then cp "${file}" deno; fi
18+
if [ -e "${file}" ]; then cp "${file}" dist-deno; fi
4119
done
42-
npm exec ts-node -T -- scripts/utils/denoify.ts
43-
deno fmt deno
44-
deno check deno/mod.ts
45-
if [ -e deno_tests ]; then
46-
deno test deno_tests --allow-env
47-
fi
48-
49-
# make sure that nothing crashes when we load the Deno module
50-
(cd deno && deno run mod.ts)

scripts/git-publish-deno.sh

-77
This file was deleted.

0 commit comments

Comments
 (0)