452 lines
15 KiB
Plaintext
452 lines
15 KiB
Plaintext
|
|
#!/usr/bin/env nu
|
||
|
|
|
||
|
|
# Create Full Distribution - Complete Packaging Workflow
|
||
|
|
# Creates both full distributions (nushell + plugins) and bin archives (plugins only)
|
||
|
|
#
|
||
|
|
# Usage:
|
||
|
|
# create_full_distribution.nu # Current platform
|
||
|
|
# create_full_distribution.nu --all-platforms # All platforms
|
||
|
|
# create_full_distribution.nu --bin-only # Only create bin archives
|
||
|
|
|
||
|
|
use lib/common_lib.nu *
|
||
|
|
|
||
|
|
# Main entry point
|
||
|
|
def main [
|
||
|
|
--all-platforms # Create packages for all platforms
|
||
|
|
--bin-only # Only create bin archives
|
||
|
|
--checksums # Generate SHA256 checksums
|
||
|
|
--verify # Verify packages after creation
|
||
|
|
] {
|
||
|
|
print_banner
|
||
|
|
|
||
|
|
if not $bin_only {
|
||
|
|
# Phase 1: Collect binaries
|
||
|
|
log_info "\n╔══════════════════════════════════════════════════════════╗"
|
||
|
|
log_info "║ Phase 1: Collect Binaries ║"
|
||
|
|
log_info "╚══════════════════════════════════════════════════════════╝"
|
||
|
|
|
||
|
|
collect_binaries $all_platforms
|
||
|
|
}
|
||
|
|
|
||
|
|
# Phase 2: Create full distribution packages
|
||
|
|
if not $bin_only {
|
||
|
|
log_info "\n╔══════════════════════════════════════════════════════════╗"
|
||
|
|
log_info "║ Phase 2: Create Full Distribution Packages ║"
|
||
|
|
log_info "╚══════════════════════════════════════════════════════════╝"
|
||
|
|
|
||
|
|
create_distribution_packages $all_platforms $checksums
|
||
|
|
}
|
||
|
|
|
||
|
|
# Phase 3: Create bin archives
|
||
|
|
log_info "\n╔══════════════════════════════════════════════════════════╗"
|
||
|
|
log_info "║ Phase 3: Create Bin Archives ║"
|
||
|
|
log_info "╚══════════════════════════════════════════════════════════╝"
|
||
|
|
|
||
|
|
create_bin_archives
|
||
|
|
|
||
|
|
# Phase 4: Verification
|
||
|
|
if $verify {
|
||
|
|
log_info "\n╔══════════════════════════════════════════════════════════╗"
|
||
|
|
log_info "║ Phase 4: Verify Packages ║"
|
||
|
|
log_info "╚══════════════════════════════════════════════════════════╝"
|
||
|
|
|
||
|
|
verify_packages
|
||
|
|
}
|
||
|
|
|
||
|
|
# Final summary
|
||
|
|
generate_distribution_summary $all_platforms $bin_only
|
||
|
|
}
|
||
|
|
|
||
|
|
# Print banner
|
||
|
|
def print_banner [] {
|
||
|
|
print $"
|
||
|
|
(ansi blue)╔════════════════════════════════════════════════════════════╗
|
||
|
|
║ ║
|
||
|
|
║ 📦 Complete Distribution Creator 📦 ║
|
||
|
|
║ ║
|
||
|
|
║ Creates: ║
|
||
|
|
║ • Full distribution packages (nu + plugins) ║
|
||
|
|
║ • Bin archives (plugins only) ║
|
||
|
|
║ • Checksums and manifests ║
|
||
|
|
║ ║
|
||
|
|
╚════════════════════════════════════════════════════════════╝(ansi reset)
|
||
|
|
"
|
||
|
|
}
|
||
|
|
|
||
|
|
# Collect binaries for distribution
|
||
|
|
def collect_binaries [all_platforms: bool] {
|
||
|
|
log_info "📥 Collecting binaries..."
|
||
|
|
|
||
|
|
if ("./scripts/collect_full_binaries.nu" | path exists) {
|
||
|
|
let result = (do {
|
||
|
|
if $all_platforms {
|
||
|
|
^./scripts/collect_full_binaries.nu --all-platforms
|
||
|
|
} else {
|
||
|
|
^./scripts/collect_full_binaries.nu
|
||
|
|
}
|
||
|
|
} | complete)
|
||
|
|
|
||
|
|
print $result.stdout
|
||
|
|
|
||
|
|
if $result.exit_code == 0 {
|
||
|
|
log_success "Binaries collected successfully"
|
||
|
|
} else {
|
||
|
|
log_error "Failed to collect binaries"
|
||
|
|
exit 1
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
log_warn "collect_full_binaries.nu not found, using fallback..."
|
||
|
|
collect_binaries_fallback
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Fallback binary collection
|
||
|
|
def collect_binaries_fallback [] {
|
||
|
|
let platform = detect_platform
|
||
|
|
|
||
|
|
log_info $"Collecting for platform: ($platform)"
|
||
|
|
|
||
|
|
# Create distribution directory
|
||
|
|
let dist_dir = $"./distribution/($platform)"
|
||
|
|
ensure_dir $dist_dir
|
||
|
|
|
||
|
|
# Copy nushell binary
|
||
|
|
if ("./nushell/target/release/nu" | path exists) {
|
||
|
|
cp ./nushell/target/release/nu $dist_dir
|
||
|
|
log_success "Copied nushell binary"
|
||
|
|
} else {
|
||
|
|
log_error "Nushell binary not found. Build it first with: just build-nushell"
|
||
|
|
exit 1
|
||
|
|
}
|
||
|
|
|
||
|
|
# Copy system plugins
|
||
|
|
let system_plugins = (try { ls ./nushell/target/release/nu_plugin_* } catch { [] } | where type == file)
|
||
|
|
for plugin in $system_plugins {
|
||
|
|
cp $plugin.name $dist_dir
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($system_plugins | length) > 0 {
|
||
|
|
log_success $"Copied ($system_plugins | length) system plugins"
|
||
|
|
}
|
||
|
|
|
||
|
|
# Copy custom plugins
|
||
|
|
let custom_plugins = (try { ls nu_plugin_*/target/release/nu_plugin_* } catch { [] } | where type == file)
|
||
|
|
for plugin in $custom_plugins {
|
||
|
|
cp $plugin.name $dist_dir
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($custom_plugins | length) > 0 {
|
||
|
|
log_success $"Copied ($custom_plugins | length) custom plugins"
|
||
|
|
}
|
||
|
|
|
||
|
|
let total = 1 + ($system_plugins | length) + ($custom_plugins | length)
|
||
|
|
log_success $"Total binaries collected: ($total)"
|
||
|
|
}
|
||
|
|
|
||
|
|
# Create distribution packages
|
||
|
|
def create_distribution_packages [
|
||
|
|
all_platforms: bool
|
||
|
|
checksums: bool
|
||
|
|
] {
|
||
|
|
log_info "📦 Creating distribution packages..."
|
||
|
|
|
||
|
|
if ("./scripts/create_distribution_packages.nu" | path exists) {
|
||
|
|
let result = (do {
|
||
|
|
if $all_platforms and $checksums {
|
||
|
|
^./scripts/create_distribution_packages.nu --all-platforms --checksums
|
||
|
|
} else if $all_platforms {
|
||
|
|
^./scripts/create_distribution_packages.nu --all-platforms
|
||
|
|
} else if $checksums {
|
||
|
|
^./scripts/create_distribution_packages.nu --checksums
|
||
|
|
} else {
|
||
|
|
^./scripts/create_distribution_packages.nu
|
||
|
|
}
|
||
|
|
} | complete)
|
||
|
|
|
||
|
|
print $result.stdout
|
||
|
|
|
||
|
|
if $result.exit_code == 0 {
|
||
|
|
log_success "Distribution packages created"
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
log_warn "create_distribution_packages.nu not found, using justfile..."
|
||
|
|
|
||
|
|
let pack_result = (do {
|
||
|
|
if $all_platforms {
|
||
|
|
just pack-full-all
|
||
|
|
} else {
|
||
|
|
just pack-full
|
||
|
|
}
|
||
|
|
} | complete)
|
||
|
|
|
||
|
|
if $pack_result.exit_code == 0 {
|
||
|
|
log_success "Packages created via justfile"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Create bin archives (plugin-only)
|
||
|
|
def create_bin_archives [] {
|
||
|
|
log_info "📦 Creating bin archives (plugin-only)..."
|
||
|
|
|
||
|
|
let pack_result = (do {
|
||
|
|
just pack
|
||
|
|
} | complete)
|
||
|
|
|
||
|
|
if $pack_result.exit_code == 0 {
|
||
|
|
log_success "Bin archives created"
|
||
|
|
|
||
|
|
# List created archives
|
||
|
|
if ("./bin_archives" | path exists) {
|
||
|
|
let archives = (try { ls ./bin_archives/*.tar.gz } catch { [] })
|
||
|
|
if ($archives | length) > 0 {
|
||
|
|
log_info $"Created ($archives | length) plugin archives:"
|
||
|
|
for archive in $archives {
|
||
|
|
let size = $archive.size | into string | str substring 0..10
|
||
|
|
log_info $" • ($archive.name | path basename): ($size)"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
log_warn "Bin archive creation had warnings"
|
||
|
|
print $pack_result.stdout
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Verify packages
|
||
|
|
def verify_packages [] {
|
||
|
|
log_info "✅ Verifying packages..."
|
||
|
|
|
||
|
|
# Check distribution packages
|
||
|
|
if ("./distribution/packages" | path exists) {
|
||
|
|
let packages = (try { ls ./distribution/packages/*.tar.gz ./distribution/packages/*.zip } catch { [] })
|
||
|
|
|
||
|
|
if ($packages | length) > 0 {
|
||
|
|
log_success $"Found ($packages | length) distribution packages"
|
||
|
|
|
||
|
|
for pkg in $packages {
|
||
|
|
let name = $pkg.name | path basename
|
||
|
|
let size = $pkg.size / 1024 / 1024
|
||
|
|
|
||
|
|
if $size < 1 {
|
||
|
|
log_error $" ✗ ($name): Too small (($size | into int)MB)"
|
||
|
|
} else if $size > 500 {
|
||
|
|
log_warn $" ⚠ ($name): Very large (($size | into int)MB)"
|
||
|
|
} else {
|
||
|
|
log_success $" ✓ ($name): (($size | into int)MB)"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
log_warn "No distribution packages found"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Check bin archives
|
||
|
|
if ("./bin_archives" | path exists) {
|
||
|
|
let archives = (try { ls ./bin_archives/*.tar.gz } catch { [] })
|
||
|
|
|
||
|
|
if ($archives | length) > 0 {
|
||
|
|
log_success $"Found ($archives | length) bin archives"
|
||
|
|
} else {
|
||
|
|
log_warn "No bin archives found"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Verify checksums if present
|
||
|
|
if ("./distribution/packages/checksums.txt" | path exists) {
|
||
|
|
log_info "Verifying checksums..."
|
||
|
|
|
||
|
|
let check_result = (do {
|
||
|
|
cd distribution/packages
|
||
|
|
shasum -c checksums.txt
|
||
|
|
} | complete)
|
||
|
|
|
||
|
|
if $check_result.exit_code == 0 {
|
||
|
|
log_success "All checksums verified"
|
||
|
|
} else {
|
||
|
|
log_error "Checksum verification failed"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Generate distribution summary
|
||
|
|
def generate_distribution_summary [
|
||
|
|
all_platforms: bool
|
||
|
|
bin_only: bool
|
||
|
|
] {
|
||
|
|
log_info "\n📊 Distribution Summary\n"
|
||
|
|
|
||
|
|
# Get nushell version
|
||
|
|
let version = if ("./nushell/Cargo.toml" | path exists) {
|
||
|
|
open ./nushell/Cargo.toml | get package.version
|
||
|
|
} else {
|
||
|
|
"unknown"
|
||
|
|
}
|
||
|
|
|
||
|
|
log_success $"Nushell version: ($version)"
|
||
|
|
|
||
|
|
# Count distribution packages
|
||
|
|
if not $bin_only and ("./distribution/packages" | path exists) {
|
||
|
|
let packages = (try { ls ./distribution/packages/*.tar.gz ./distribution/packages/*.zip } catch { [] })
|
||
|
|
|
||
|
|
if ($packages | length) > 0 {
|
||
|
|
log_success $"Distribution packages: ($packages | length)"
|
||
|
|
|
||
|
|
let total_size = ($packages | get size | math sum) / 1024 / 1024
|
||
|
|
log_info $"Total size: (($total_size | into int))MB"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Count bin archives
|
||
|
|
if ("./bin_archives" | path exists) {
|
||
|
|
let archives = (try { ls ./bin_archives/*.tar.gz } catch { [] })
|
||
|
|
|
||
|
|
if ($archives | length) > 0 {
|
||
|
|
log_success $"Bin archives: ($archives | length)"
|
||
|
|
|
||
|
|
let total_size = ($archives | get size | math sum) / 1024 / 1024
|
||
|
|
log_info $"Total size: (($total_size | into int))MB"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# List platforms
|
||
|
|
if not $bin_only and ("./distribution" | path exists) {
|
||
|
|
let platforms = (try { ls ./distribution/*/nu } catch { [] } | each {|p| $p.name | path dirname | path basename})
|
||
|
|
|
||
|
|
if ($platforms | length) > 0 {
|
||
|
|
log_info $"\nPlatforms built: ($platforms | str join ', ')"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Next steps
|
||
|
|
log_info "\n📝 Next Steps:"
|
||
|
|
|
||
|
|
if not $bin_only {
|
||
|
|
log_info " 1. Test installation:"
|
||
|
|
let platform = detect_platform
|
||
|
|
log_info $" cd distribution/($platform) && ./install.nu --verify"
|
||
|
|
}
|
||
|
|
|
||
|
|
log_info " 2. Upload to release:"
|
||
|
|
log_info " gh release create v($version) distribution/packages/*"
|
||
|
|
|
||
|
|
log_info " 3. Update documentation:"
|
||
|
|
log_info " Update README.md with new version"
|
||
|
|
}
|
||
|
|
|
||
|
|
# Detect current platform
|
||
|
|
def detect_platform []: nothing -> string {
|
||
|
|
let os = (sys | get host.name)
|
||
|
|
let arch = (sys | get host.arch)
|
||
|
|
|
||
|
|
if $os == "Darwin" {
|
||
|
|
if $arch == "aarch64" {
|
||
|
|
"darwin-arm64"
|
||
|
|
} else {
|
||
|
|
"darwin-x86_64"
|
||
|
|
}
|
||
|
|
} else if $os == "Linux" {
|
||
|
|
if $arch == "aarch64" {
|
||
|
|
"linux-arm64"
|
||
|
|
} else {
|
||
|
|
"linux-x86_64"
|
||
|
|
}
|
||
|
|
} else if $os == "Windows" {
|
||
|
|
"windows-x86_64"
|
||
|
|
} else {
|
||
|
|
$"($os | str downcase)-($arch)"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Ensure directory exists
|
||
|
|
def ensure_dir [dir: string] {
|
||
|
|
if not ($dir | path exists) {
|
||
|
|
mkdir $dir
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Quick command to rebuild and redistribute
|
||
|
|
def "main rebuild" [] {
|
||
|
|
log_info "🔄 Rebuild and redistribute workflow\n"
|
||
|
|
|
||
|
|
# Build nushell
|
||
|
|
log_info "Building nushell..."
|
||
|
|
let build_result = (do {
|
||
|
|
just build-nushell
|
||
|
|
} | complete)
|
||
|
|
|
||
|
|
if $build_result.exit_code != 0 {
|
||
|
|
log_error "Nushell build failed"
|
||
|
|
exit 1
|
||
|
|
}
|
||
|
|
|
||
|
|
# Build plugins
|
||
|
|
log_info "Building plugins..."
|
||
|
|
let plugins_result = (do {
|
||
|
|
just build
|
||
|
|
} | complete)
|
||
|
|
|
||
|
|
if $plugins_result.exit_code != 0 {
|
||
|
|
log_warn "Some plugins failed to build"
|
||
|
|
}
|
||
|
|
|
||
|
|
# Create distributions
|
||
|
|
main --checksums
|
||
|
|
}
|
||
|
|
|
||
|
|
# Show distribution status
|
||
|
|
def "main status" [] {
|
||
|
|
log_info "📊 Distribution Status\n"
|
||
|
|
|
||
|
|
# Check if nushell is built
|
||
|
|
if ("./nushell/target/release/nu" | path exists) {
|
||
|
|
let version_result = (do {
|
||
|
|
./nushell/target/release/nu -c "version | get version"
|
||
|
|
} | complete)
|
||
|
|
|
||
|
|
log_success $"Nushell binary: (str trim $version_result.stdout)"
|
||
|
|
} else {
|
||
|
|
log_warn "Nushell binary: Not built"
|
||
|
|
}
|
||
|
|
|
||
|
|
# Check distribution directory
|
||
|
|
if ("./distribution" | path exists) {
|
||
|
|
let platforms = (try { ls ./distribution/*/nu } catch { [] })
|
||
|
|
|
||
|
|
if ($platforms | length) > 0 {
|
||
|
|
log_success $"Distribution platforms: ($platforms | length)"
|
||
|
|
|
||
|
|
for p in $platforms {
|
||
|
|
let platform = $p.name | path dirname | path basename
|
||
|
|
print $" • ($platform)"
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
log_warn "Distribution: No binaries collected"
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
log_warn "Distribution: Not created"
|
||
|
|
}
|
||
|
|
|
||
|
|
# Check packages
|
||
|
|
if ("./distribution/packages" | path exists) {
|
||
|
|
let packages = (try { ls ./distribution/packages/*.tar.gz ./distribution/packages/*.zip } catch { [] })
|
||
|
|
|
||
|
|
if ($packages | length) > 0 {
|
||
|
|
log_success $"Packages: ($packages | length) created"
|
||
|
|
} else {
|
||
|
|
log_warn "Packages: None created"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Check bin archives
|
||
|
|
if ("./bin_archives" | path exists) {
|
||
|
|
let archives = (try { ls ./bin_archives/*.tar.gz } catch { [] })
|
||
|
|
|
||
|
|
if ($archives | length) > 0 {
|
||
|
|
log_success $"Bin archives: ($archives | length) created"
|
||
|
|
} else {
|
||
|
|
log_warn "Bin archives: None created"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|