Compare commits

...
19 Commits
Author SHA1 Message Date
yiling 02b009fbe1 Release v0.0.5 2026-06-13 10:32:59 +08:00
Yiling-J 6dcd08ae3a Merge pull request #101 from shumaiOne/feat/npm-auto-migration
feat(npm): auto deploy database migrations on package start
2026-06-13 10:27:11 +08:00
yiling d230a1fd4a feat(npm): add dotenv loading and fix variable interpolation in wrapper 2026-06-13 10:21:36 +08:00
yiling 210ed5f95a feat(npm): auto deploy database migrations on package start 2026-06-13 09:24:54 +08:00
yiling edd550b9f2 Release v0.0.4 2026-06-12 22:02:39 +08:00
Yiling-J ea71954deb Merge pull request #100 from shumaiOne/fix/npm-external-resolution
fix(cli/docker): resolve global CLI external dependencies and fix Docker 404 error
2026-06-12 21:56:22 +08:00
yiling dc63ab3eaf fix(npm): resolve binary output path mapping in build-npm script 2026-06-12 21:54:15 +08:00
yiling d06dfc0ab3 perf(npm): optimize platform binary compilation using dummy runner 2026-06-12 21:50:18 +08:00
yiling 84aa1662be fix(docker): align build output structure and fix web 404 error 2026-06-12 21:24:59 +08:00
yiling 91fedf1477 fix(cli): resolve all external module imports in global CLI package 2026-06-12 21:08:40 +08:00
yiling b0dbb56493 Release v0.0.3 2026-06-12 20:42:52 +08:00
Yiling-J f6a0577585 Merge pull request #99 from shumaiOne/fix/npm-binary-lookup
fix(cli): resolve platform binary path resolution under nested node_modules
2026-06-12 20:36:11 +08:00
yiling 1fee0f5a97 fix(cli): resolve platform binary path resolution under nested node_modules 2026-06-12 20:34:07 +08:00
Yiling-J b5c0eca2fe Merge pull request #98 from shumaiOne/fix/npm-publish-provenance
fix(npm): add repository metadata to package.json for provenance verification
2026-06-12 18:49:48 +08:00
yiling 12d8681cd1 fix(npm): add repository metadata for provenance validation 2026-06-12 18:47:28 +08:00
yiling d472be460a Release v0.0.2 2026-06-12 18:38:57 +08:00
Yiling-J bf7e5185d9 Merge pull request #97 from shumaiOne/feat/release-npm-ci
ci: add release-npm.yaml workflow
2026-06-12 16:37:05 +08:00
yiling 008d913220 ci: use npm Trusted Publisher OIDC for authentication 2026-06-12 16:29:43 +08:00
yiling ed02ea1317 ci: add release-npm.yaml workflow 2026-06-12 16:27:46 +08:00
18 changed files with 377 additions and 80 deletions
-3
View File
@@ -46,6 +46,3 @@ jobs:
- name: Test Local Release
run: |
bun run release:local --skip-check --out /tmp/shumai-local-release --force
cd /tmp/shumai-local-release/node
npx shumai-agent
npx shumai-transcode
+88
View File
@@ -0,0 +1,88 @@
name: Build, Release & Publish to NPM
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: 'Tag to build (e.g., v0.12.0)'
required: true
type: string
source_ref:
description: 'Source ref to build/publish (defaults to tag)'
required: false
type: string
permissions: {}
jobs:
release:
name: Build, Release and Publish
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
env:
RELEASE_TAG: ${{ github.event.inputs.tag || github.ref_name }}
SOURCE_REF: ${{ github.event.inputs.source_ref || github.event.inputs.tag || github.ref_name }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.SOURCE_REF }}
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
registry-url: 'https://registry.npmjs.org'
package-manager-cache: false
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y ripgrep bubblewrap socat libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev fd-find
- name: Install dependencies
run: bun install
- name: Lint
run: bun run lint
- name: Typecheck
run: bun run typecheck
- name: Test
run: bun run test
- name: Build NPM packages
run: bun run build-npm
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if gh release view "${{ env.RELEASE_TAG }}" >/dev/null 2>&1; then
gh release edit "${{ env.RELEASE_TAG }}" \
--title "${{ env.RELEASE_TAG }}" \
--generate-notes
else
gh release create "${{ env.RELEASE_TAG }}" \
--title "${{ env.RELEASE_TAG }}" \
--generate-notes
fi
- name: Upgrade npm for trusted publishing
run: |
npm install -g npm@11.16.0 --ignore-scripts
npm --version
- name: Publish to NPM
run: bun run scripts/publish.ts
+1 -1
View File
@@ -70,4 +70,4 @@ COPY --chown=bun:bun --from=builder /app/prisma.config.ts.prod ./prisma.config.t
EXPOSE 3000
# Default command: run migrations and start API server
CMD ["sh", "-c", "bun prisma migrate deploy && bun apps/web/src/index.js"]
CMD ["sh", "-c", "bun prisma migrate deploy && bun index.js"]
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/agent-app",
"version": "0.0.1",
"version": "0.0.5",
"private": true,
"type": "module",
"bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/transcode-app",
"version": "0.0.1",
"version": "0.0.5",
"private": true,
"type": "module",
"bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/web-app",
"version": "0.0.1",
"version": "0.0.5",
"private": true,
"type": "module",
"dependencies": {
+64 -17
View File
@@ -1,3 +1,4 @@
import { join } from 'node:path'
import { loadEnvConfig } from '@shumai/core/src/env-loader'
loadEnvConfig(process.cwd(), process.env.NODE_ENV !== 'production')
@@ -41,25 +42,71 @@ if (process.env.WORKFLOW_EXECUTOR === 'temporal') {
Promise.all(queuesToStart.map((q) => workflowService.startWorkers(q))).catch(console.error)
}
const server = Bun.serve({
port: 3000,
fetch: app.fetch,
maxRequestBodySize: process.env.MAX_REQUEST_BODY_SIZE
? parseInt(process.env.MAX_REQUEST_BODY_SIZE)
: 1024 * 1024 * 1024 * 10, // Default 10GB
routes: {
// Serve index.html for root
'/': index,
const isProd = process.env.NODE_ENV === 'production'
// Proxy API requests to Hono
'/api/*': app.fetch,
'/files/*': app.fetch,
const server = Bun.serve(
isProd
? {
port: 3000,
maxRequestBodySize: process.env.MAX_REQUEST_BODY_SIZE
? parseInt(process.env.MAX_REQUEST_BODY_SIZE)
: 1024 * 1024 * 1024 * 10, // Default 10GB
development: false,
async fetch(req) {
const url = new URL(req.url)
// Catch-all for SPA routing (fallback to index.html)
'/*': index,
},
development: process.env.NODE_ENV !== 'production',
})
if (!url.pathname.startsWith('/api/') && !url.pathname.startsWith('/files/')) {
const filepath = join(import.meta.dir, url.pathname)
const file = Bun.file(filepath)
if (await file.exists()) {
try {
const stat = await file.stat()
if (stat.isFile()) {
return new Response(file)
}
} catch {
// ignore stat errors
}
}
const htmlFile = Bun.file(join(import.meta.dir, 'index.html'))
if (await htmlFile.exists()) {
return new Response(htmlFile, {
headers: { 'Content-Type': 'text/html' },
})
}
const htmlFileNpm = Bun.file(join(import.meta.dir, 'shumai-app.html'))
if (await htmlFileNpm.exists()) {
return new Response(htmlFileNpm, {
headers: { 'Content-Type': 'text/html' },
})
}
}
return app.fetch(req)
},
}
: {
port: 3000,
maxRequestBodySize: process.env.MAX_REQUEST_BODY_SIZE
? parseInt(process.env.MAX_REQUEST_BODY_SIZE)
: 1024 * 1024 * 1024 * 10, // Default 10GB
development: true,
fetch: app.fetch,
routes: {
// Serve index.html for root
'/': index,
// Proxy API requests to Hono
'/api/*': app.fetch,
'/files/*': app.fetch,
// Catch-all for SPA routing (fallback to index.html)
'/*': index,
},
},
)
console.log(`🚀 Server running at ${server.url}`)
+1
View File
@@ -20,6 +20,7 @@ await Bun.build({
target: 'bun',
outdir: outdir,
minify: false,
naming: '[name].[ext]',
plugins: [
temporalWorkflow({
bundleOptions: {},
+5 -1
View File
@@ -1,8 +1,12 @@
{
"name": "shumai",
"version": "0.0.1",
"version": "0.0.5",
"private": true,
"type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/shumaiOne/shumai.git"
},
"workspaces": [
"packages/*",
"apps/*"
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/agent",
"version": "0.0.1",
"version": "0.0.5",
"private": true,
"type": "module",
"main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/api",
"version": "0.0.1",
"version": "0.0.5",
"private": true,
"type": "module",
"main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/core",
"version": "0.0.1",
"version": "0.0.5",
"private": true,
"type": "module",
"main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/db",
"version": "0.0.1",
"version": "0.0.5",
"private": true,
"type": "module",
"main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/dtos",
"version": "0.0.1",
"version": "0.0.5",
"private": true,
"type": "module",
"main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/transcode",
"version": "0.0.1",
"version": "0.0.5",
"private": true,
"type": "module",
"main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/webui",
"version": "0.0.1",
"version": "0.0.5",
"private": true,
"type": "module",
"main": "./index.html",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/workflow-core",
"version": "0.0.1",
"version": "0.0.5",
"private": true,
"type": "module",
"main": "./src/index.ts",
+207 -47
View File
@@ -1,7 +1,7 @@
import { rm, mkdir, cp, writeFile } from 'node:fs/promises'
import { existsSync } from 'node:fs'
import path from 'node:path'
import tailwindPlugin from 'bun-plugin-tailwind'
import { existsSync } from 'node:fs'
import { cp, mkdir, readdir, rm, writeFile } from 'node:fs/promises'
import path from 'node:path'
import { temporalWorkflow } from '../packages/workflow-core/src/bun-temporal-plugin'
console.log('\n🚀 Starting NPM packaging build process for all applications...\n')
@@ -16,6 +16,9 @@ if (existsSync(distDir)) {
}
await mkdir(distDir, { recursive: true })
const dummyRunnerPath = path.join(distDir, 'dummy-runner.ts')
await writeFile(dummyRunnerPath, '// Shumai Runner Stub\n', 'utf-8')
const rootPackageJson = JSON.parse(await Bun.file('package.json').text())
const version = rootPackageJson.version || '0.1.0'
@@ -112,21 +115,18 @@ async function compileApp({
process.exit(1)
}
// Rename generated binary (usually Bun names it 'src' or the folder name of the entrypoint)
const generatedFile = path.join(outdir, 'src')
const generatedFileExe = path.join(outdir, 'src.exe')
// Rename generated binary dynamically by finding the output file in outdir
const finalFile = path.join(outdir, binaryName)
const files = await readdir(outdir)
const generatedFilename = files.find((f) => f !== binaryName)
if (existsSync(generatedFile)) {
if (generatedFilename) {
const generatedPath = path.join(outdir, generatedFilename)
console.log(`➡️ Moving binary to final location: ${finalFile}`)
await cp(generatedFile, finalFile)
await rm(generatedFile)
} else if (existsSync(generatedFileExe)) {
console.log(`➡️ Moving binary to final location: ${finalFile}`)
await cp(generatedFileExe, finalFile)
await rm(generatedFileExe)
} else {
console.error(`❌ Could not find compiled binary at ${generatedFile} or ${generatedFileExe}`)
await cp(generatedPath, finalFile)
await rm(generatedPath)
} else if (!existsSync(finalFile)) {
console.error(`❌ Could not find compiled binary in ${outdir}`)
process.exit(1)
}
}
@@ -161,6 +161,7 @@ async function buildPlatformPackages(
description: `${target.platform} ${target.arch} binary for ${appName}`,
os: [target.platform],
cpu: [target.arch],
repository: rootPackageJson.repository,
}
await writeFile(
@@ -172,23 +173,68 @@ async function buildPlatformPackages(
}
// Function to build main wrapper package
async function buildMainPackage(
appName: string,
description: string,
hasPrisma: boolean,
extraDependencies: Record<string, string> = {},
) {
// Function to build main wrapper package
async function buildMainPackage({
appName,
description,
hasPrisma,
entrypoint,
plugins = [],
extraDependencies = {},
}: {
appName: string
description: string
hasPrisma: boolean
entrypoint: string
// eslint-disable-next-line @typescript-eslint/no-explicit-any
plugins?: any[]
extraDependencies?: Record<string, string>
}) {
console.log(`\n📄 Packaging wrapper app ${appName}...`)
const mainOutDir = path.join(distDir, appName)
const binOutDir = path.join(mainOutDir, 'bin')
await mkdir(binOutDir, { recursive: true })
// 1. Bundle the JS application code for wrapper
console.log(`📦 Bundling JS application code for wrapper ${appName}...`)
const appJsName = `${appName}-app.js`
const buildResult = await Bun.build({
entrypoints: [entrypoint],
root: '.',
target: 'bun',
outdir: binOutDir,
minify: true,
naming: `${appName}-app.[ext]`,
plugins,
external: commonExternal,
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
publicPath: '/',
})
if (!buildResult.success) {
console.error(`❌ JS bundling failed for ${appName}!`)
for (const log of buildResult.logs) {
console.error(log)
}
process.exit(1)
}
// Confirm that the bundle exists
const finalJsFile = path.join(binOutDir, appJsName)
if (!existsSync(finalJsFile)) {
console.error(`❌ Could not find compiled JS bundle at ${finalJsFile}`)
process.exit(1)
}
// Write JS wrapper script
const wrapperContent = `#!/usr/bin/env node
import { spawn } from 'node:child_process'
import { join, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import { existsSync } from 'node:fs'
import { existsSync, readFileSync } from 'node:fs'
const __dirname = dirname(fileURLToPath(import.meta.url))
const platform = process.platform
@@ -222,7 +268,7 @@ if (platform === 'darwin' && arch === 'arm64') {
const pathsToTry = [
join(__dirname, '..', '..', '..', pkgName, 'bin', binaryName), // Flat node_modules
join(__dirname, '..', '..', 'node_modules', pkgName, 'bin', binaryName), // Nested node_modules
join(__dirname, '..', 'node_modules', pkgName, 'bin', binaryName), // Nested node_modules
]
let binaryPath = ''
@@ -238,18 +284,95 @@ if (!binaryPath) {
process.exit(1)
}
const child = spawn(binaryPath, process.argv.slice(2), {
stdio: 'inherit',
})
const appJsPath = join(__dirname, '${appName}-app.js')
child.on('close', (code) => {
process.exit(code ?? 0)
})
function startApp() {
const child = spawn(binaryPath, ['run', appJsPath, ...process.argv.slice(2)], {
stdio: 'inherit',
env: {
...process.env,
BUN_BE_BUN: '1',
},
})
child.on('error', (err) => {
console.error(\`Failed to start child process:\`, err)
process.exit(1)
})
child.on('close', (code) => {
process.exit(code ?? 0)
})
child.on('error', (err) => {
console.error(\`Failed to start child process:\`, err)
process.exit(1)
})
}
// Simple .env parser to load env files from process.cwd()
function loadEnv() {
const envFiles = ['.env.production.local', '.env.local', '.env.production', '.env']
for (const file of envFiles) {
const envPath = join(process.cwd(), file)
if (existsSync(envPath)) {
try {
const content = readFileSync(envPath, 'utf8')
const lines = content.split(/\\r?\\n/)
for (const line of lines) {
const trimmed = line.trim()
if (!trimmed || trimmed.startsWith('#')) continue
const match = trimmed.match(/^([^=]+)=(.*)$/)
if (match) {
const key = match[1].trim()
let value = match[2].trim()
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
value = value.substring(1, value.length - 1)
}
if (process.env[key] === undefined) {
process.env[key] = value
}
}
}
} catch (err) {
console.error('⚠️ [shumai] Error reading env file:', err)
}
}
}
}
// Load env files on startup
loadEnv()
console.log(\`ℹ️ [${appName}] Running from CWD: \${process.cwd()}\`)
console.log(\`ℹ️ [${appName}] DATABASE_URL is: \${process.env.DATABASE_URL ? '(defined)' : '(undefined)'}\`)
const prismaSchemaPath = join(__dirname, '..', 'prisma', 'schema.prisma')
if (existsSync(prismaSchemaPath)) {
console.log('🔄 Running database migrations...')
const migrationProcess = spawn(
binaryPath,
['run', 'prisma', 'migrate', 'deploy', '--schema', './prisma/schema.prisma'],
{
stdio: 'inherit',
cwd: join(__dirname, '..'),
env: {
...process.env,
BUN_BE_BUN: '1',
},
}
)
migrationProcess.on('close', (code) => {
if (code !== 0) {
console.error(\`❌ Database migration failed with code \${code}. Exiting.\`)
process.exit(code ?? 1)
}
startApp()
})
migrationProcess.on('error', (err) => {
console.error('❌ Failed to run database migrations:', err)
process.exit(1)
})
} else {
startApp()
}
`
const wrapperPath = path.join(binOutDir, `${appName}.js`)
@@ -266,6 +389,21 @@ child.on('error', (err) => {
recursive: true,
})
}
// Generate prisma.config.ts in the package root
const localConfigContent = `import { defineConfig } from 'prisma/config'
export default defineConfig({
schema: './prisma/schema.prisma',
migrations: {
path: './prisma/migrations',
},
datasource: {
url: process.env.DATABASE_URL,
},
})
`
await writeFile(path.join(mainOutDir, 'prisma.config.ts'), localConfigContent, 'utf-8')
}
// Generate package.json
@@ -286,9 +424,10 @@ child.on('error', (err) => {
bin: {
[appName]: `./bin/${appName}.js`,
},
files: ['bin', ...(hasPrisma ? ['prisma'] : [])],
files: ['bin', ...(hasPrisma ? ['prisma', 'prisma.config.ts'] : [])],
dependencies,
optionalDependencies,
repository: rootPackageJson.repository,
}
await writeFile(
@@ -299,32 +438,53 @@ child.on('error', (err) => {
}
// 2. Build shumai (Main app & platform binaries)
await buildPlatformPackages('shumai', './apps/web/src/index.ts', [
const shumaiPlugins = [
temporalWorkflow({
bundleOptions: {},
}),
tailwindPlugin,
])
await buildMainPackage('shumai', 'A fullstack AI-powered media workspace and workflow engine', true)
]
await buildPlatformPackages('shumai', dummyRunnerPath)
await buildMainPackage({
appName: 'shumai',
description: 'A fullstack AI-powered media workspace and workflow engine',
hasPrisma: true,
entrypoint: './apps/web/src/index.ts',
plugins: shumaiPlugins,
})
// 3. Build shumai-agent (Agent app & platform binaries)
await buildPlatformPackages('shumai-agent', './apps/agent/src/index.ts', [
const agentPlugins = [
temporalWorkflow({
bundleOptions: {},
}),
])
await buildMainPackage('shumai-agent', 'AI worker agent for the shumai media workspace', false)
]
await buildPlatformPackages('shumai-agent', dummyRunnerPath)
await buildMainPackage({
appName: 'shumai-agent',
description: 'AI worker agent for the shumai media workspace',
hasPrisma: true,
entrypoint: './apps/agent/src/index.ts',
plugins: agentPlugins,
})
// 4. Build shumai-transcode (Transcode app & platform binaries)
await buildPlatformPackages('shumai-transcode', './apps/transcode/src/index.ts', [
const transcodePlugins = [
temporalWorkflow({
bundleOptions: {},
}),
])
await buildMainPackage(
'shumai-transcode',
'Media transcoding worker for the shumai media workspace',
false,
)
]
await buildPlatformPackages('shumai-transcode', dummyRunnerPath)
await buildMainPackage({
appName: 'shumai-transcode',
description: 'Media transcoding worker for the shumai media workspace',
hasPrisma: true,
entrypoint: './apps/transcode/src/index.ts',
plugins: transcodePlugins,
})
if (existsSync(dummyRunnerPath)) {
await rm(dummyRunnerPath)
}
console.log('\n✅ All applications and platform binaries built and packaged successfully!')