**refactor(models): remove demo script and replace with GitHub release creation script**

- Removed `demo-optional-model-bundling.js`:
  - Obsolete demonstration of model bundling and offline loading.
  - Replaced by comprehensive documentation and tools in `@soulcraft/brainy-models`.
- Added `create-github-release.js`:
  - Automates GitHub release creation for `@soulcraft/brainy-models-package`.
  - Includes features for generating release notes, tagging, and uploading with GitHub CLI.
- Updated `package-lock.json`:
  - Reflects new dependencies and updates for GitHub release automation.

**Purpose**: Streamline repository by removing redundant scripts and introducing automated GitHub release workflows for efficient version management.
This commit is contained in:
David Snelling 2025-08-01 16:08:22 -07:00
parent d8de4083f5
commit 4e5d747a8a
5 changed files with 5619 additions and 318 deletions

5337
brainy-models-package/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{ {
"name": "@soulcraft/brainy-models", "name": "@soulcraft/brainy-models-package",
"version": "1.0.0", "version": "0.0.0",
"description": "Pre-bundled TensorFlow models for maximum reliability with Brainy vector database", "description": "Pre-bundled TensorFlow models for maximum reliability with Brainy vector database",
"main": "dist/index.js", "main": "dist/index.js",
"module": "dist/index.js", "module": "dist/index.js",
@ -12,11 +12,23 @@
"scripts": { "scripts": {
"prebuild": "npm run download-models", "prebuild": "npm run download-models",
"build": "tsc", "build": "tsc",
"download-models": "node scripts/download-full-models.js",
"compress-models": "node scripts/compress-models.js",
"test": "node test/test-models.js", "test": "node test/test-models.js",
"prepare": "npm run build", "prepare": "npm run build",
"pack": "npm pack" "download-models": "node scripts/download-full-models.js",
"compress-models": "node scripts/compress-models.js",
"_pack": "npm pack",
"_release": "standard-version",
"_release:patch": "standard-version --release-as patch",
"_release:minor": "standard-version --release-as minor",
"_release:major": "standard-version --release-as major",
"_release:dry-run": "standard-version --dry-run",
"_github-release": "node scripts/create-github-release.js",
"_workflow": "node scripts/release-workflow.js",
"_workflow:patch": "node scripts/release-workflow.js patch",
"_workflow:minor": "node scripts/release-workflow.js minor",
"_workflow:major": "node scripts/release-workflow.js major",
"_workflow:dry-run": "npm run build && npm test && npm run _release:dry-run",
"_deploy": "npm run build && npm publish"
}, },
"keywords": [ "keywords": [
"tensorflow", "tensorflow",
@ -50,13 +62,14 @@
"LICENSE" "LICENSE"
], ],
"dependencies": { "dependencies": {
"@tensorflow/tfjs": "^4.22.0", "@tensorflow-models/universal-sentence-encoder": "^1.3.3",
"@tensorflow/tfjs-node": "^4.22.0", "@tensorflow/tfjs": "^4.23.0-rc.0",
"@tensorflow-models/universal-sentence-encoder": "^1.3.3" "@tensorflow/tfjs-node": "^4.23.0-rc.0"
}, },
"devDependencies": { "devDependencies": {
"typescript": "^5.4.5", "@types/node": "^20.11.30",
"@types/node": "^20.11.30" "standard-version": "^9.5.0",
"typescript": "^5.4.5"
}, },
"peerDependencies": { "peerDependencies": {
"@soulcraft/brainy": ">=0.33.0" "@soulcraft/brainy": ">=0.33.0"

View file

@ -0,0 +1,107 @@
#!/usr/bin/env node
/**
* Create GitHub Release Script for @soulcraft/brainy-models-package
*
* This script creates a GitHub release with auto-generated release notes
* for the current version of the brainy-models-package.
*
* It uses the GitHub CLI (gh) to create the release, so the gh CLI must be installed
* and authenticated with appropriate permissions.
*
* The script:
* 1. Gets the current version from package.json
* 2. Creates a GitHub release for that version with models-package prefix
* 3. Auto-generates release notes based on commits since the last release
*
* This ensures that each npm release has a corresponding GitHub release with notes.
*/
/* global process, console */
import { execSync } from 'child_process'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
// Get the directory of the current module
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
// Path to the brainy-models-package directory
const packageDir = path.join(__dirname, '..')
const rootDir = path.join(__dirname, '..', '..')
// Path to package.json
const packageJsonPath = path.join(packageDir, 'package.json')
// Read package.json
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
const version = packageJson.version
const tagName = `models-package-v${version}`
// Check if GitHub CLI is installed
try {
execSync('gh --version', { stdio: 'ignore' })
} catch (error) {
console.error('Error: GitHub CLI (gh) is not installed or not in PATH')
console.error('Please install it from https://cli.github.com/ and authenticate with `gh auth login`')
process.exit(1)
}
// Check if the tag exists locally
let tagExistsLocally = false
try {
const tagOutput = execSync(`git tag -l ${tagName}`, { stdio: 'pipe', cwd: rootDir }).toString().trim()
tagExistsLocally = tagOutput === tagName
} catch (error) {
console.log(`Error checking if tag exists: ${error.message}`)
tagExistsLocally = false
}
// Create and push the tag if it doesn't exist
if (!tagExistsLocally) {
try {
console.log(`Creating tag ${tagName}...`)
execSync(`git tag ${tagName}`, { stdio: 'inherit', cwd: rootDir })
console.log(`Successfully created tag ${tagName}`)
} catch (error) {
console.error(`Error creating tag: ${error.message}`)
process.exit(1)
}
}
// Push the tag to remote
try {
console.log(`Pushing tag ${tagName} to remote...`)
execSync(`git push origin ${tagName}`, { stdio: 'inherit', cwd: rootDir })
console.log(`Successfully pushed tag ${tagName} to remote`)
} catch (error) {
console.error(`Error pushing tag to remote: ${error.message}`)
// Continue with release creation even if tag push fails
}
// Create the GitHub release
try {
console.log(`Creating GitHub release for @soulcraft/brainy-models-package v${version}...`)
// Create a release with auto-generated notes
// The --generate-notes flag automatically generates release notes based on PRs and commits
execSync(
`gh release create ${tagName} --title "@soulcraft/brainy-models-package v${version}" --generate-notes --notes "Release of @soulcraft/brainy-models-package v${version} - Pre-bundled TensorFlow models for maximum reliability with Brainy vector database."`,
{ stdio: 'inherit', cwd: rootDir }
)
console.log(`GitHub release ${tagName} created successfully!`)
console.log('GitHub release created with auto-generated notes')
} catch (error) {
// If the release already exists, this is not a fatal error
if (error.message.includes('already exists')) {
console.log(`GitHub release ${tagName} already exists, skipping creation.`)
console.log('GitHub release already exists with auto-generated notes')
} else {
console.error('Error creating GitHub release:', error.message)
// Don't exit with error to allow the npm publish to continue
// process.exit(1)
}
}

View file

@ -0,0 +1,152 @@
#!/usr/bin/env node
/**
* Release Workflow Script for @soulcraft/brainy-models-package
*
* This script provides a comprehensive workflow for releasing a new version:
* 1. Updates the version (major, minor, or patch)
* 2. Automatically updates the CHANGELOG.md with commit messages since the last release
* 3. Creates a GitHub release
* 4. Deploys to NPM
*
* Usage:
* node scripts/release-workflow.js [patch|minor|major]
*
* If no version type is specified, it defaults to "patch"
*/
/* global process, console */
import { execSync } from 'child_process'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import readline from 'readline'
// Get the directory of the current module
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
// Path to the brainy-models-package directory
const packageDir = path.join(__dirname, '..')
const rootDir = path.join(__dirname, '..', '..')
// Get the version type from command line arguments
const args = process.argv.slice(2)
const versionType = args[0] || 'patch'
// Validate version type
if (!['patch', 'minor', 'major'].includes(versionType)) {
// eslint-disable-next-line no-console
console.error('Error: Version type must be one of: patch, minor, major')
// eslint-disable-next-line no-process-exit
process.exit(1)
}
// Function to execute a command and log its output
function executeStep(command, description, cwd = packageDir) {
// eslint-disable-next-line no-console
console.log(`\n🚀 ${description}...\n`)
try {
execSync(command, { stdio: 'inherit', cwd })
// eslint-disable-next-line no-console
console.log(`${description} completed successfully!\n`)
return true
} catch (error) {
// eslint-disable-next-line no-console
console.error(`❌ Error during ${description.toLowerCase()}: ${error.message}`)
return false
}
}
// Main workflow
async function runReleaseWorkflow() {
// eslint-disable-next-line no-console
console.log(`\n=== Starting @soulcraft/brainy-models-package Release Workflow (${versionType}) ===\n`)
// Step 1: Build the project
if (!executeStep('npm run build', 'Building brainy-models-package')) {
// eslint-disable-next-line no-process-exit
process.exit(1)
}
// Step 2: Run tests to ensure everything is working
if (!executeStep('npm test', 'Running tests')) {
// eslint-disable-next-line no-console
console.warn('⚠️ Tests failed. This might indicate issues with the release.')
// Ask the user if they want to continue despite test failures
// eslint-disable-next-line no-console
console.log('\n⚠ Do you want to continue with the release process despite test failures? (y/N)')
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
const response = await new Promise(resolve => {
rl.question('', answer => {
rl.close()
resolve(answer.toLowerCase())
})
})
if (response !== 'y' && response !== 'yes') {
// eslint-disable-next-line no-console
console.error('Release process aborted due to test failures.')
// eslint-disable-next-line no-process-exit
process.exit(1)
}
// eslint-disable-next-line no-console
console.log('Continuing with release process despite test failures...')
}
// Step 3: Update version and generate changelog
if (!executeStep(`npm run release:${versionType}`, `Updating version (${versionType}) and generating changelog`)) {
// eslint-disable-next-line no-process-exit
process.exit(1)
}
// Step 4: Create GitHub release
if (!executeStep('npm run github-release', 'Creating GitHub release')) {
// eslint-disable-next-line no-console
console.log('Warning: GitHub release creation failed, but continuing with deployment...')
}
// Step 5: Publish to NPM
if (!executeStep('npm publish', 'Publishing to NPM')) {
// eslint-disable-next-line no-process-exit
process.exit(1)
}
// Get the new version from package.json
const packageJsonPath = path.join(packageDir, 'package.json')
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
const newVersion = packageJson.version
// eslint-disable-next-line no-console
console.log(`\n🎉 @soulcraft/brainy-models-package v${newVersion} release completed successfully! 🎉\n`)
// eslint-disable-next-line no-console
console.log('Summary of actions:')
// eslint-disable-next-line no-console
console.log(`- Package built and tested`)
// eslint-disable-next-line no-console
console.log(`- Version bumped to v${newVersion} (${versionType})`)
// eslint-disable-next-line no-console
console.log(`- CHANGELOG.md updated with recent commits`)
// eslint-disable-next-line no-console
console.log(`- GitHub release created with auto-generated notes`)
// eslint-disable-next-line no-console
console.log(`- Package published to NPM as @soulcraft/brainy-models-package`)
// eslint-disable-next-line no-console
console.log('\nThank you for using the brainy-models-package release workflow!\n')
}
// Run the workflow
runReleaseWorkflow().catch(error => {
// eslint-disable-next-line no-console
console.error('Unexpected error during release workflow:', error)
// eslint-disable-next-line no-process-exit
process.exit(1)
})

View file

@ -1,308 +0,0 @@
#!/usr/bin/env node
/* eslint-env node */
/* eslint-disable no-console */
/**
* Demonstration: Optional Model Bundling Package
*
* This script demonstrates how the @soulcraft/brainy-models package
* provides maximum reliability by eliminating network dependencies
* for model loading.
*
* Original Issue: "When the Brainy library is used by other libraries,
* there are always problems loading the model - it takes a long time to load,
* times out, or fails completely."
*
* Solution: Optional separate package @soulcraft/brainy-models for maximum reliability
*/
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
console.log('🚀 Demonstration: Optional Model Bundling Package')
console.log('='.repeat(60))
console.log()
/**
* Simulate the original problem with online model loading
*/
async function simulateOnlineModelLoadingProblems() {
console.log('❌ PROBLEM: Online Model Loading Issues')
console.log('─'.repeat(40))
const problems = [
'🐌 Slow loading: 30-60 seconds on first use',
'⏰ Timeouts: Network requests fail after timeout',
'🌐 Network dependency: Requires internet connection',
'💥 Complete failures: TensorFlow Hub unavailable',
'🔄 Inconsistent performance: Variable load times',
'📡 Offline issues: Cannot work without internet'
]
for (const problem of problems) {
console.log(` ${problem}`)
await new Promise((resolve) => setTimeout(resolve, 500)) // Simulate delay
}
console.log()
console.log(
'💡 These issues make Brainy unreliable when used by other libraries!'
)
console.log()
}
/**
* Demonstrate the solution with bundled models
*/
async function demonstrateBundledModelSolution() {
console.log('✅ SOLUTION: Optional Model Bundling Package')
console.log('─'.repeat(40))
const solutions = [
'📦 Package: @soulcraft/brainy-models',
'🔒 Maximum reliability: 100% offline operation',
'⚡ Fast loading: < 1 second startup time',
'🌐 No network dependency: Works completely offline',
'📊 Consistent performance: Predictable load times',
'🗜️ Multiple variants: Original, Float16, Int8 compressed',
'💾 Local storage: ~25MB for complete model',
'🛠️ Easy integration: Drop-in replacement'
]
for (const solution of solutions) {
console.log(` ${solution}`)
await new Promise((resolve) => setTimeout(resolve, 300))
}
console.log()
}
/**
* Show package structure and features
*/
function showPackageStructure() {
console.log('📁 Package Structure')
console.log('─'.repeat(20))
const packagePath = path.join(__dirname, 'brainy-models-package')
if (fs.existsSync(packagePath)) {
console.log(' ✅ @soulcraft/brainy-models/')
console.log(' ├── 📄 package.json (Package configuration)')
console.log(' ├── 📖 README.md (Comprehensive documentation)')
console.log(' ├── 🔧 tsconfig.json (TypeScript configuration)')
console.log(' ├── 📂 src/')
console.log(' │ └── 📄 index.ts (Main API)')
console.log(' ├── 📂 scripts/')
console.log(' │ ├── 📄 download-full-models.js (Model downloader)')
console.log(' │ └── 📄 compress-models.js (Model compression)')
console.log(' ├── 📂 test/')
console.log(' │ └── 📄 test-models.js (Comprehensive tests)')
console.log(' └── 📂 models/')
console.log(' └── 📂 universal-sentence-encoder/')
console.log(' ├── 📄 model.json (Model configuration)')
console.log(' ├── 📄 metadata.json (Model metadata)')
console.log(' ├── 📄 *.bin (Model weights)')
console.log(' └── 📂 compressed/ (Optimized variants)')
console.log()
} else {
console.log(' ⚠️ Package directory not found at expected location')
console.log()
}
}
/**
* Show installation and usage examples
*/
function showUsageExamples() {
console.log('💻 Installation & Usage')
console.log('─'.repeat(25))
console.log('📥 Installation:')
console.log(' npm install @soulcraft/brainy-models')
console.log()
console.log('🔧 Basic Usage:')
console.log(` import { BundledUniversalSentenceEncoder } from '@soulcraft/brainy-models'
const encoder = new BundledUniversalSentenceEncoder({
verbose: true,
preferCompressed: false
})
await encoder.load() // < 1 second, no network required!
const embeddings = await encoder.embedToArrays([
'Hello world',
'Machine learning is amazing'
])
console.log('Generated embeddings:', embeddings.length)
encoder.dispose()`)
console.log()
console.log('🔗 Integration with Brainy:')
console.log(` import Brainy from '@soulcraft/brainy'
import { BundledUniversalSentenceEncoder } from '@soulcraft/brainy-models'
const bundledEncoder = new BundledUniversalSentenceEncoder()
await bundledEncoder.load()
const brainy = new Brainy({
customEmbedding: async (texts) => {
return await bundledEncoder.embedToArrays(texts)
}
})
// Now Brainy uses bundled models - maximum reliability!`)
console.log()
}
/**
* Show model compression features
*/
function showCompressionFeatures() {
console.log('🗜️ Model Compression & Optimization')
console.log('─'.repeat(35))
const variants = [
{
name: 'Original (Float32)',
size: '~25MB',
accuracy: 'Maximum',
memory: 'High',
useCase: 'Production applications'
},
{
name: 'Float16 Compressed',
size: '~12-15MB',
accuracy: 'Very High',
memory: 'Medium',
useCase: 'Balanced performance'
},
{
name: 'Int8 Quantized',
size: '~6-8MB',
accuracy: 'High',
memory: 'Low',
useCase: 'Memory-constrained'
}
]
for (const variant of variants) {
console.log(` 📊 ${variant.name}`)
console.log(` Size: ${variant.size}`)
console.log(` Accuracy: ${variant.accuracy}`)
console.log(` Memory: ${variant.memory}`)
console.log(` Use case: ${variant.useCase}`)
console.log()
}
console.log('🎯 Optimization Scripts:')
console.log(' npm run download-models # Download full models')
console.log(' npm run compress-models # Create optimized variants')
console.log(' npm test # Verify functionality')
console.log()
}
/**
* Show reliability comparison
*/
function showReliabilityComparison() {
console.log('📊 Reliability Comparison')
console.log('─'.repeat(25))
const comparison = [
['Feature', 'Online Loading', 'Bundled Models'],
['─'.repeat(15), '─'.repeat(15), '─'.repeat(15)],
['Reliability', 'Network dependent', '100% offline ✅'],
['First load time', '30-60 seconds', '< 1 second ✅'],
['Subsequent loads', 'Cached (~1s)', '< 1 second ✅'],
['Package size', '~3KB ✅', '~25MB'],
['Network required', 'Yes (first time)', 'No ✅'],
['Offline support', 'Limited', 'Complete ✅'],
['Startup time', 'Variable', 'Consistent ✅'],
['Memory usage', 'Standard', 'Configurable ✅']
]
for (const row of comparison) {
console.log(` ${row[0].padEnd(17)} ${row[1].padEnd(17)} ${row[2]}`)
}
console.log()
}
/**
* Show when to use each approach
*/
function showWhenToUse() {
console.log('🎯 When to Use Each Approach')
console.log('─'.repeat(30))
console.log('✅ Use Bundled Models When:')
const bundledUseCases = [
'Production applications requiring maximum reliability',
'Offline or air-gapped environments',
'Applications with strict SLA requirements',
'Edge computing and IoT devices',
'Development environments with unreliable internet'
]
for (const useCase of bundledUseCases) {
console.log(`${useCase}`)
}
console.log()
console.log('✅ Use Online Loading When:')
const onlineUseCases = [
'Development and prototyping',
'Applications where package size matters',
'Environments with reliable internet connectivity',
'Applications that rarely use embeddings'
]
for (const useCase of onlineUseCases) {
console.log(`${useCase}`)
}
console.log()
}
/**
* Main demonstration
*/
async function runDemo() {
try {
await simulateOnlineModelLoadingProblems()
await demonstrateBundledModelSolution()
showPackageStructure()
showUsageExamples()
showCompressionFeatures()
showReliabilityComparison()
showWhenToUse()
console.log('🎉 Summary')
console.log('─'.repeat(10))
console.log(
'The @soulcraft/brainy-models package solves the original reliability'
)
console.log('issues by providing:')
console.log()
console.log(' ✅ Complete offline operation (no network dependencies)')
console.log(' ✅ Fast, consistent loading times (< 1 second)')
console.log(' ✅ Multiple optimized variants for different use cases')
console.log(' ✅ Easy integration with existing Brainy applications')
console.log(' ✅ Comprehensive documentation and examples')
console.log()
console.log('🚀 Ready for production use with maximum reliability!')
} catch (error) {
console.error('❌ Demo failed:', error)
process.exit(1)
}
}
// Run the demonstration
runDemo().catch(console.error)