Skip to content

Commit f5e0771

Browse files
authored
feat: setup npm publish workflow (#14)
* feat: add npm sdks publish workflow * fix: fix matrix * feat: 0.2.0-alpha.0 * chore: bump version * fix: fix silly issue * chore: bump version * fix: set npm dist tag * chore: bump tag * feat: bump version * fix: bump version
1 parent 857c16d commit f5e0771

5 files changed

Lines changed: 164 additions & 249 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Release npm SDKs
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: read
9+
id-token: write
10+
11+
jobs:
12+
publish:
13+
name: Publish ${{ matrix.package }}
14+
runs-on: ubuntu-latest
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
include:
19+
- package: typescript
20+
path: sdks/typescript
21+
build_command: npm run build
22+
uses_bun: false
23+
tag_prefix: sdks/typescript/
24+
- package: bun-worker
25+
path: sdks/bun-worker
26+
build_command: bun run build
27+
uses_bun: true
28+
tag_prefix: sdks/bun-worker/
29+
steps:
30+
- name: Check tag prefix
31+
id: tag_check
32+
shell: bash
33+
run: |
34+
set -euo pipefail
35+
TAG="${{ github.event.release.tag_name }}"
36+
PREFIX="${{ matrix.tag_prefix }}"
37+
if [[ "$TAG" == "$PREFIX"* ]]; then
38+
echo "match=true" >> "$GITHUB_OUTPUT"
39+
else
40+
echo "match=false" >> "$GITHUB_OUTPUT"
41+
fi
42+
- name: Checkout
43+
if: steps.tag_check.outputs.match == 'true'
44+
uses: actions/checkout@v4
45+
- name: Setup Node
46+
if: steps.tag_check.outputs.match == 'true'
47+
uses: actions/setup-node@v4
48+
with:
49+
node-version: 24
50+
registry-url: https://registry.npmjs.org
51+
- name: Setup Bun
52+
if: steps.tag_check.outputs.match == 'true' && matrix.uses_bun
53+
uses: oven-sh/setup-bun@v1
54+
with:
55+
bun-version: latest
56+
- name: Install TypeScript SDK deps
57+
if: steps.tag_check.outputs.match == 'true'
58+
run: npm install
59+
working-directory: sdks/typescript
60+
- name: Install Bun worker deps
61+
if: steps.tag_check.outputs.match == 'true' && matrix.uses_bun
62+
run: bun install
63+
working-directory: sdks/bun-worker
64+
- name: Build package
65+
if: steps.tag_check.outputs.match == 'true'
66+
run: ${{ matrix.build_command }}
67+
working-directory: ${{ matrix.path }}
68+
- name: Select npm dist-tag
69+
if: steps.tag_check.outputs.match == 'true'
70+
id: npm_tag
71+
shell: bash
72+
run: |
73+
set -euo pipefail
74+
# npm dist-tags are labels like "latest"/"next", not the git tag or version string.
75+
if [[ "${{ github.event.release.prerelease }}" == "true" ]]; then
76+
echo "tag=next" >> "$GITHUB_OUTPUT"
77+
else
78+
echo "tag=latest" >> "$GITHUB_OUTPUT"
79+
fi
80+
- name: Publish to npm (OIDC)
81+
if: steps.tag_check.outputs.match == 'true'
82+
# unsetting NODE_AUTH_TOKEN to make sure the wrong default from setup-node won't interfere
83+
# ref: https://github.com/actions/setup-node/issues/1440
84+
run: NODE_AUTH_TOKEN="" npm publish --provenance --access public --tag ${{ steps.npm_tag.outputs.tag }}
85+
working-directory: ${{ matrix.path }}

0 commit comments

Comments
 (0)