Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/release-sdk-dispatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Release SDK Dispatch

on:
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g., "1.0.0" or "v1.0.0")'
required: true
type: string

jobs:
propose-release:
name: Propose SDK Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.CREATE_PR_TOKEN }}

- name: Normalize version
id: version
run: |
VERSION="${{ inputs.version }}"
VERSION="${VERSION#v}"

if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?$ ]]; then
echo "Error: invalid semver version: $VERSION"
exit 1
fi

echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"

- name: Update SDK version
env:
VERSION: ${{ steps.version.outputs.VERSION }}
run: |
node <<'EOF'
const fs = require('fs');
const path = 'torii.js/package.json';
const pkg = JSON.parse(fs.readFileSync(path, 'utf8'));
pkg.version = process.env.VERSION;
fs.writeFileSync(path, `${JSON.stringify(pkg, null, 2)}\n`);
EOF

- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.CREATE_PR_TOKEN }}
commit-message: "release(prepare): @toriijs/sdk v${{ steps.version.outputs.VERSION }}"
title: "release(prepare): @toriijs/sdk v${{ steps.version.outputs.VERSION }}"
body: |
## Release Preparation

This PR prepares **@toriijs/sdk** for version **v${{ steps.version.outputs.VERSION }}**.

### Changes
- Updated `torii.js/package.json` to `${{ steps.version.outputs.VERSION }}`

### Next Steps
Once this PR is merged, the SDK release workflow will automatically:
1. Install dependencies for `torii.js`
2. Build the publishable `dist/` artifacts
3. Validate the npm package contents with `npm pack --dry-run`
4. Publish `@toriijs/sdk` to npm
5. Create a GitHub release for `sdk-v${{ steps.version.outputs.VERSION }}`
branch: prepare-release-sdk
delete-branch: true
base: main
98 changes: 98 additions & 0 deletions .github/workflows/release-sdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Release SDK

on:
pull_request:
types: [closed]
branches: [main]
workflow_dispatch:

concurrency:
group: release-sdk-${{ github.event.pull_request.head.ref || github.ref }}
cancel-in-progress: false

jobs:
prepare:
name: Prepare SDK Release
if: github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged == true && github.event.pull_request.head.ref == 'prepare-release-sdk')
runs-on: ubuntu-latest
outputs:
version: ${{ steps.release-info.outputs.VERSION }}
tag_name: ${{ steps.release-info.outputs.TAG_NAME }}
package_name: ${{ steps.release-info.outputs.PACKAGE_NAME }}
steps:
- uses: actions/checkout@v4

- name: Extract release info
id: release-info
run: |
VERSION=$(node -p "require('./torii.js/package.json').version")
TAG_NAME="sdk-v${VERSION}"
PACKAGE_NAME=$(node -p "require('./torii.js/package.json').name")

echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
echo "TAG_NAME=$TAG_NAME" >> "$GITHUB_OUTPUT"
echo "PACKAGE_NAME=$PACKAGE_NAME" >> "$GITHUB_OUTPUT"

publish:
name: Publish ${{ needs.prepare.outputs.package_name }}
needs: prepare
runs-on: ubuntu-latest
permissions:
contents: write
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Ensure version is not already published
env:
PACKAGE_NAME: ${{ needs.prepare.outputs.package_name }}
VERSION: ${{ needs.prepare.outputs.version }}
run: |
if npm view "${PACKAGE_NAME}@${VERSION}" version >/dev/null 2>&1; then
echo "${PACKAGE_NAME}@${VERSION} is already published"
exit 1
fi

- name: Install dependencies
working-directory: torii.js
run: bun install

- name: Build SDK distribution
working-directory: torii.js
run: bun run build

- name: Typecheck SDK
working-directory: torii.js
run: bun run typecheck

- name: Validate package contents
working-directory: torii.js
run: npm pack --dry-run

- name: Publish package to npm
working-directory: torii.js
run: npm publish

- name: Create GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PACKAGE_NAME: ${{ needs.prepare.outputs.package_name }}
TAG_NAME: ${{ needs.prepare.outputs.tag_name }}
VERSION: ${{ needs.prepare.outputs.version }}
run: |
gh release create "$TAG_NAME" \
--title "${PACKAGE_NAME} v${VERSION}" \
--generate-notes \
--notes "Published ${PACKAGE_NAME} v${VERSION} to npm."
Loading