Skip to content

Publish to JSR and npm #93

Publish to JSR and npm

Publish to JSR and npm #93

Workflow file for this run

name: Publish to JSR and npm
on:
push:
tags:
- "v*"
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "latest"
registry-url: "https://registry.npmjs.org"
# - name: Run tests
# run: deno task test
- name: Type check
run: deno task build
- name: Publish to JSR
run: deno publish
- name: Run JSR to NPM conversion
run: npx -y @yaonyan/jsr2npm@latest
- name: Publish to npm
run: |
for dir in __*_*/dist; do
cd "$dir"
NAME=$(node -p "require('./package.json').name")
VERSION=$(node -p "require('./package.json').version")
if npm view "$NAME@$VERSION" version 2>/dev/null; then
echo "Skipping $NAME@$VERSION (already published)"
else
# For prerelease versions, explicitly set tag to prevent it from becoming 'latest'
if echo "$VERSION" | grep -qE '\-[a-zA-Z]'; then
TAG=$(echo "$VERSION" | sed -E 's/[^-]*-([a-zA-Z]+).*/\1/')
echo "Publishing prerelease $NAME@$VERSION with tag: $TAG"
npm publish --access public --provenance --tag "$TAG"
else
echo "Publishing stable release $NAME@$VERSION"
npm publish --access public --provenance
fi
fi
cd ../..
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: npm-package
path: __*_*/dist/
retention-days: 7