#!/usr/bin/env luash -- Development Workflow Demo: Git, building, and deployment tasks print("=== Development Workflow with Luash ===\n") -- Check if we're in a git repository print("1. Git Repository Check:") git_status = `git status 2>/dev/null || echo "not_a_repo"` if git_status ~= "not_a_repo" then current_branch = `git branch --show-current` print(" ✓ Git repository detected") print(" Current branch: " .. current_branch) -- Check for uncommitted changes changes = `git status --porcelain` if changes ~= "" then print(" ⚠ Uncommitted changes detected") else print(" ✓ Working directory clean") end else print(" ✗ Not a git repository") end -- Project setup and dependency management print("\n2. Project Dependencies:") project_files = {"package.json", "requirements.txt", "Cargo.toml", "go.mod"} for i = 1, #project_files do local file = project_files[i] local exists = `test -f ` .. file .. ` && echo "yes" || echo "no"` if exists == "yes" then print(" Found " .. file) -- Run appropriate install command if file == "package.json" then print(" Installing npm dependencies...") !npm install elseif file == "requirements.txt" then print(" Python project detected") !pip install -r requirements.txt elseif file == "Cargo.toml" then print(" Rust project detected") !cargo build elseif file == "go.mod" then print(" Go project detected") !go mod tidy end break end end -- Build and test automation print("\n3. Build and Test:") $BUILD_START = `date` print(" Build started at: " .. $BUILD_START) -- Simple build logic based on project type if `test -f Makefile && echo "yes"` == "yes" then print(" Running make...") build_result = `make 2>&1` if string.find(build_result, "error") or string.find(build_result, "Error") then print(" ✗ Build failed") print(" " .. build_result) else print(" ✓ Build successful") end elseif `test -f package.json && echo "yes"` == "yes" then print(" Running npm build...") !npm run build 2>/dev/null || echo " No build script found" else print(" No build system detected") end -- Code quality checks print("\n4. Code Quality:") code_files = `find . -name "*.lua" -o -name "*.js" -o -name "*.py" | head -10` if code_files ~= "" then line_count = `find . -name "*.lua" -o -name "*.js" -o -name "*.py" | xargs wc -l 2>/dev/null | tail -1 | awk '{print $1}'` print(" Total lines of code: " .. line_count) file_count = `find . -name "*.lua" -o -name "*.js" -o -name "*.py" | wc -l` print(" Code files: " .. file_count) end -- Deployment preparation print("\n5. Deployment Preparation:") $VERSION = `git describe --tags 2>/dev/null || echo "v1.0.0"` print(" Version: " .. $VERSION) -- Create deployment package print(" Creating deployment package...") package_name = "deploy_" .. string.gsub($VERSION, "%.", "_") .. ".tar.gz" -- Use Lua string manipulation instead of shell interpolation !tar --exclude='.git' --exclude='node_modules' --exclude='*.log' -czf deploy_package.tar.gz . if `test -f deploy_package.tar.gz && echo "yes"` == "yes" then package_size = `du -h deploy_package.tar.gz | cut -f1` print(" ✓ Package created: deploy_package.tar.gz (" .. package_size .. ")") else print(" ✗ Package creation failed") end -- Environment-specific deployment print("\n6. Environment Deployment:") $DEPLOY_ENV = "staging" -- Could be passed as argument print(" Target environment: " .. $DEPLOY_ENV) -- Simulate deployment steps deployment_steps = { "Validating package integrity", "Backing up current version", "Uploading new version", "Running database migrations", "Restarting services", "Running health checks" } for i = 1, #deployment_steps do print(" " .. i .. ". " .. deployment_steps[i] .. "...") -- In real deployment, these would be actual commands `sleep 0.5` -- Simulate work print(" ✓ Complete") end print("\n 🚀 Deployment to " .. $DEPLOY_ENV .. " completed successfully!")