Skip to content

Commit 90b91a2

Browse files
committed
Add a deploy workflow.
1 parent b092980 commit 90b91a2

2 files changed

Lines changed: 93 additions & 1 deletion

File tree

.github/workflows/sindri-ci.yaml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
branches: [master]
66
pull_request:
77
branches: [master]
8+
release:
9+
types: [published, prereleased]
810

911
jobs:
1012
lint-and-build:
@@ -71,3 +73,93 @@ jobs:
7173
test -f result/index.d.ts
7274
test -f result/sindri/index.js
7375
test -f result/sindri/index.d.ts
76+
77+
deploy:
78+
name: publish to npm on release
79+
if: github.event_name == 'release'
80+
needs: lint-and-build
81+
runs-on: ubuntu-latest
82+
permissions:
83+
contents: write # Needed to upload the .tgz to the GitHub Release.
84+
steps:
85+
- name: Checkout repository
86+
uses: actions/checkout@v4
87+
88+
- name: Setup Node.js
89+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.0.3
90+
with:
91+
node-version: '22'
92+
cache: 'yarn'
93+
registry-url: 'https://registry.npmjs.org'
94+
always-auth: true
95+
96+
- name: Install Nix
97+
uses: cachix/install-nix-action@c134e4c9e34bac6cab09cf239815f9339aaaf84e # v31
98+
with:
99+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
100+
101+
- name: Install dependencies
102+
run: |
103+
yarn install
104+
cd examples
105+
yarn install
106+
107+
- name: Build the package
108+
run: nix build
109+
110+
- name: Prepare dist and set version from release tag
111+
env:
112+
TAG_NAME: ${{ github.event.release.tag_name }}
113+
run: |
114+
set -euo pipefail
115+
rm -rf dist
116+
mkdir -p dist
117+
# Copy without preserving ownership so files are writable.
118+
cp -R result/. dist/
119+
chmod -R u+rwX dist
120+
121+
# Validate and extract semver from tag: vMAJOR.MINOR.PATCH(-prerelease)?
122+
if [[ "${TAG_NAME}" =~ ^v([0-9]+\.[0-9]+\.[0-9]+(?:-[A-Za-z0-9\.-]+)?)$ ]]; then
123+
VERSION="${BASH_REMATCH[1]}"
124+
else
125+
echo "Release tag must match ^vMAJOR.MINOR.PATCH(-prerelease)? ; got: ${TAG_NAME}"
126+
exit 1
127+
fi
128+
129+
# Sanity-check package name.
130+
NAME=$(jq -r '.name' dist/package.json)
131+
if [[ "${NAME}" != "@sindrilabs/openai" ]]; then
132+
echo "Refusing to publish unexpected package name: ${NAME}"
133+
exit 1
134+
fi
135+
136+
# Patch version.
137+
tmp=$(mktemp)
138+
jq --arg v "${VERSION}" '.version = $v' dist/package.json > "${tmp}"
139+
mv "${tmp}" dist/package.json
140+
echo "Ready to publish ${NAME}@${VERSION}"
141+
142+
- name: Pack tarball
143+
env:
144+
TAG_NAME: ${{ github.event.release.tag_name }}
145+
run: |
146+
set -euo pipefail
147+
pushd dist >/dev/null
148+
PKG_TGZ=$(npm pack)
149+
popd >/dev/null
150+
mv "dist/${PKG_TGZ}" "sindrilabs-openai.${TAG_NAME}.tgz"
151+
ls -l "sindrilabs-openai.${TAG_NAME}.tgz"
152+
153+
- name: Publish to npm
154+
env:
155+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # Used by setup-node's npm rc.
156+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
157+
run: |
158+
set -euo pipefail
159+
# Publish scoped package publicly; always tag as latest (even for pre-releases).
160+
(cd dist && npm publish --access public --tag latest)
161+
162+
- name: Attach tarball to GitHub Release
163+
uses: softprops/action-gh-release@v2
164+
with:
165+
files: sindrilabs-openai.${{ github.event.release.tag_name }}.tgz

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "openai",
2+
"name": "@sindrilabs/openai",
33
"version": "5.14.0",
44
"description": "Sindri OpenAI-Compatible JS SDK",
55
"author": "OpenAI <support@openai.com>",

0 commit comments

Comments
 (0)