Skip to main content
Glama
auto-fix-pipeline.shโ€ข4.3 kB
#!/bin/bash # Auto-fix common CI/CD pipeline issues set -euo pipefail echo "๐Ÿ”ง Auto-fixing pipeline issues..." # Function to add missing npm script add_missing_script() { local script_name=$1 local script_content=$2 echo "โž• Adding missing script: $script_name" # Use jq to add the script to package.json tmp=$(mktemp) jq --arg name "$script_name" --arg content "$script_content" \ '.scripts[$name] = $content' package.json > "$tmp" mv "$tmp" package.json echo "โœ… Added script: $script_name" } # Function to fix memory-related issues fix_memory_issues() { echo "๐Ÿง  Fixing memory allocation in test scripts..." # Check if test scripts have proper memory allocation local scripts_to_fix=( "test:performance:ci" "test:compatibility" ) for script in "${scripts_to_fix[@]}"; do if grep -q "\"$script\"" package.json; then # Update script to include proper memory allocation if missing if ! grep -A1 "\"$script\"" package.json | grep -q "NODE_OPTIONS"; then echo "โš ๏ธ Script $script missing memory allocation" fi fi done } # Function to fix missing scripts fix_missing_scripts() { echo "๐Ÿ”ง Checking and fixing missing scripts..." # Add test:performance:ci if missing if ! npm run-script test:performance:ci --silent 2>/dev/null; then add_missing_script "test:performance:ci" \ "npm run build && NODE_OPTIONS=\"--max-old-space-size=4096\" vitest run tests/performance/ --reporter=json --outputFile=performance-results.json" fi # Add test:compatibility if missing if ! npm run-script test:compatibility --silent 2>/dev/null; then add_missing_script "test:compatibility" \ "npm run build && vitest run tests/compatibility/ || echo 'No compatibility tests found'" fi } # Function to fix dependency issues fix_dependencies() { echo "๐Ÿ“ฆ Checking dependencies..." # Check for high/critical vulnerabilities if ! npm audit --audit-level=high; then echo "๐Ÿ”’ Fixing security vulnerabilities..." npm audit fix --force || true fi # Clean and reinstall if package-lock.json is corrupted if [ -f package-lock.json ] && ! npm ci --dry-run &>/dev/null; then echo "๐Ÿงน Cleaning and reinstalling dependencies..." rm -rf node_modules package-lock.json npm install fi } # Function to verify fixes verify_fixes() { echo "โœ… Verifying fixes..." # Check that scripts now exist npm run test:performance:ci --help >/dev/null 2>&1 || { echo "โŒ test:performance:ci still not working" return 1 } npm run test:compatibility --help >/dev/null 2>&1 || { echo "โŒ test:compatibility still not working" return 1 } echo "โœ… All fixes verified successfully" } # Main execution main() { echo "๐Ÿš€ Starting auto-fix process..." # Backup current package.json cp package.json package.json.backup echo "๐Ÿ’พ Backed up package.json" fix_missing_scripts fix_memory_issues fix_dependencies verify_fixes # Check if any changes were made if ! diff -q package.json package.json.backup >/dev/null; then echo "๐Ÿ“ Changes made to package.json:" diff package.json package.json.backup || true # Offer to commit changes if [ -z "${CI:-}" ]; then read -p "Commit these changes? (y/n): " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then git add package.json git commit -m "fix(ci): Auto-fix pipeline configuration - Added missing npm scripts for CI/CD compatibility - Fixed memory allocation settings - Resolved dependency issues ๐Ÿค– Generated by pipeline auto-fix script" echo "โœ… Changes committed" fi else echo "๐Ÿค– Running in CI - changes will be handled by workflow" fi else echo "โ„น๏ธ No changes needed" fi rm -f package.json.backup echo "๐ŸŽ‰ Auto-fix completed successfully!" } # Error handling trap 'echo "โŒ Auto-fix failed on line $LINENO"; mv package.json.backup package.json 2>/dev/null || true' ERR # Run main function main "$@"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/docdyhr/mcp-wordpress'

If you have feedback or need assistance with the MCP directory API, please join our Discord server