Added wiki generator
This commit is contained in:
@@ -50,20 +50,78 @@ jobs:
|
|||||||
# Generate terraform output
|
# Generate terraform output
|
||||||
echo "🔍 Generating Terraform output..."
|
echo "🔍 Generating Terraform output..."
|
||||||
|
|
||||||
# Method 1: Try to get clean JSON output
|
# Get only the specific output we need
|
||||||
if terraform output -json > terraform-output.json 2>/dev/null; then
|
echo "📤 Extracting applications_for_wiki output..."
|
||||||
echo "✅ Direct JSON output successful"
|
terraform output -json applications_for_wiki > terraform-raw-output.json 2>&1
|
||||||
|
|
||||||
|
# Check if output has command prefix
|
||||||
|
if grep -q '^\[command\]' terraform-raw-output.json; then
|
||||||
|
echo "⚠️ Detected command prefix, removing first line..."
|
||||||
|
tail -n +2 terraform-raw-output.json > terraform-output.json
|
||||||
else
|
else
|
||||||
echo "⚠️ Direct JSON failed, trying alternative method..."
|
cp terraform-raw-output.json terraform-output.json
|
||||||
# Method 2: Get specific output
|
|
||||||
terraform output -json applications_for_wiki > terraform-output.json 2>&1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clean up the output if needed
|
# Validate JSON and extract value
|
||||||
if grep -q '^\[command\]' terraform-output.json; then
|
echo "🔍 Validating and extracting JSON..."
|
||||||
echo "⚠️ Detected command prefix in output, cleaning..."
|
if python3 -c "import json; f=open('terraform-output.json'); data=json.load(f); f.close(); print('✅ Valid JSON')" 2>/dev/null; then
|
||||||
tail -n +2 terraform-output.json > terraform-output-clean.json
|
# Extract just the value field using Python (more reliable than jq)
|
||||||
mv terraform-output-clean.json terraform-output.json
|
python3 -c "
|
||||||
|
import json
|
||||||
|
with open('terraform-output.json', 'r') as f:
|
||||||
|
data = json.load(f)
|
||||||
|
# Handle both full output format and direct value
|
||||||
|
if isinstance(data, dict) and 'value' in data:
|
||||||
|
value = data['value']
|
||||||
|
else:
|
||||||
|
value = data
|
||||||
|
with open('terraform-output-value.json', 'w') as out:
|
||||||
|
json.dump(value, out, indent=2)
|
||||||
|
"
|
||||||
|
mv terraform-output-value.json terraform-output.json
|
||||||
|
echo "✅ JSON extracted successfully"
|
||||||
|
else
|
||||||
|
echo "❌ Invalid JSON detected, trying to fix..."
|
||||||
|
# Try to extract valid JSON part
|
||||||
|
python3 -c "
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
|
||||||
|
with open('terraform-output.json', 'r') as f:
|
||||||
|
content = f.read()
|
||||||
|
|
||||||
|
# Try to find and extract valid JSON
|
||||||
|
try:
|
||||||
|
# Find first { and last matching }
|
||||||
|
start = content.find('{')
|
||||||
|
if start >= 0:
|
||||||
|
# Count brackets to find matching close
|
||||||
|
count = 0
|
||||||
|
end = start
|
||||||
|
for i in range(start, len(content)):
|
||||||
|
if content[i] == '{':
|
||||||
|
count += 1
|
||||||
|
elif content[i] == '}':
|
||||||
|
count -= 1
|
||||||
|
if count == 0:
|
||||||
|
end = i + 1
|
||||||
|
break
|
||||||
|
|
||||||
|
if end > start:
|
||||||
|
json_str = content[start:end]
|
||||||
|
data = json.loads(json_str)
|
||||||
|
if 'value' in data:
|
||||||
|
data = data['value']
|
||||||
|
with open('terraform-output.json', 'w') as out:
|
||||||
|
json.dump(data, out, indent=2)
|
||||||
|
print('✅ Fixed JSON by extracting valid portion')
|
||||||
|
else:
|
||||||
|
print('❌ Could not find matching brackets')
|
||||||
|
else:
|
||||||
|
print('❌ No JSON found in output')
|
||||||
|
except Exception as e:
|
||||||
|
print(f'❌ Failed to fix JSON: {e}')
|
||||||
|
"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Debug output
|
# Debug output
|
||||||
|
Reference in New Issue
Block a user