brainy/brainy-models-package/scripts/release-workflow.js
David Snelling 699dc4f4a5 **feat(brainy-models): enhance workflows, update README, and improve model compatibility**
- **Scripts**:
  - Refactored logging within `release-workflow.js` for improved readability and maintainability.
  - Added a fallback mechanism in `download-full-models.js` to inject the "format" field into `model.json` for TensorFlow.js compatibility.

- **Documentation**:
  - Updated `README.md` with a redesigned structure:
    - Enhanced readability using emojis and a cleaner presentation.
    - Expanded `Overview`, `Features`, and `Quick Start` sections.
    - Refined "Use Cases" and added better explanations for bundled model benefits.

- **Models**:
  - Adjusted `model.json` to include the "format" field for compatibility with TensorFlow.js.
  - Updated `metadata.json` with a recent download timestamp.

**Purpose
2025-08-01 17:33:13 -07:00

171 lines
5.3 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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)
})