73 lines
2.6 KiB
Bash
Executable File
73 lines
2.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Convert existing .drone.yml to modular Jsonnet structure
|
|
# This script helps migrate from YAML to factorized Jsonnet configuration
|
|
|
|
echo "🔄 Converting Drone configuration to modular Jsonnet..."
|
|
|
|
# Generate the final configuration from Jsonnet
|
|
echo "📝 Generating .drone.yml from Jsonnet..."
|
|
if command -v jsonnet >/dev/null 2>&1; then
|
|
jsonnet .drone.jsonnet > .drone.yml.generated
|
|
echo "✅ Generated .drone.yml.generated from Jsonnet"
|
|
echo ""
|
|
echo "📋 To use the new configuration:"
|
|
echo "1. Review: cat .drone.yml.generated"
|
|
echo "2. Test: python3 -c \"import yaml; yaml.safe_load(open('.drone.yml.generated'))\""
|
|
echo "3. Replace: mv .drone.yml.generated .drone.yml"
|
|
echo "4. Commit: git add .drone.jsonnet common.libsonnet build-steps.libsonnet .drone.yml"
|
|
else
|
|
echo "⚠️ jsonnet not installed. Installing..."
|
|
|
|
# Try to install jsonnet
|
|
if command -v apt-get >/dev/null 2>&1; then
|
|
sudo apt-get update && sudo apt-get install -y jsonnet
|
|
elif command -v apk >/dev/null 2>&1; then
|
|
apk add --no-cache jsonnet
|
|
elif command -v yum >/dev/null 2>&1; then
|
|
sudo yum install -y jsonnet
|
|
else
|
|
echo "❌ Cannot install jsonnet automatically"
|
|
echo "📖 Please install jsonnet manually:"
|
|
echo " - Ubuntu/Debian: sudo apt-get install jsonnet"
|
|
echo " - Alpine: apk add jsonnet"
|
|
echo " - CentOS/RHEL: sudo yum install jsonnet"
|
|
echo " - Or download from: https://github.com/google/jsonnet"
|
|
exit 1
|
|
fi
|
|
|
|
# Try generating again
|
|
if command -v jsonnet >/dev/null 2>&1; then
|
|
jsonnet .drone.jsonnet > .drone.yml.generated
|
|
echo "✅ Generated .drone.yml.generated from Jsonnet"
|
|
else
|
|
echo "❌ Failed to install jsonnet"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
echo ""
|
|
echo "🎯 Benefits of Jsonnet configuration:"
|
|
echo " ✅ Reusable components (common.libsonnet, build-steps.libsonnet)"
|
|
echo " ✅ Variables and functions"
|
|
echo " ✅ Conditional logic"
|
|
echo " ✅ Better maintainability"
|
|
echo " ✅ DRY principle"
|
|
echo ""
|
|
echo "📚 Files created:"
|
|
echo " - .drone.jsonnet (main configuration)"
|
|
echo " - common.libsonnet (shared steps and config)"
|
|
echo " - build-steps.libsonnet (build-specific logic)"
|
|
echo " - .drone.yml.generated (generated YAML)"
|
|
|
|
# Validate the generated YAML
|
|
if [ -f ".drone.yml.generated" ]; then
|
|
echo ""
|
|
echo "🔍 Validating generated YAML..."
|
|
if python3 -c "import yaml; yaml.safe_load(open('.drone.yml.generated'))" 2>/dev/null; then
|
|
echo "✅ Generated YAML is valid"
|
|
else
|
|
echo "❌ Generated YAML has syntax errors"
|
|
exit 1
|
|
fi
|
|
fi |