**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:
parent
d8de4083f5
commit
4e5d747a8a
5 changed files with 5619 additions and 318 deletions
107
brainy-models-package/scripts/create-github-release.js
Normal file
107
brainy-models-package/scripts/create-github-release.js
Normal 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)
|
||||
}
|
||||
}
|
||||
152
brainy-models-package/scripts/release-workflow.js
Normal file
152
brainy-models-package/scripts/release-workflow.js
Normal 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)
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue