This commit is contained in:
@@ -47,101 +47,26 @@ jobs:
|
||||
echo "📋 Starting Wiki generation..."
|
||||
cd ./terraform/authentik
|
||||
|
||||
# Generate terraform output
|
||||
# Get terraform output
|
||||
echo "🔍 Generating Terraform output..."
|
||||
|
||||
# Get only the specific output we need
|
||||
echo "📤 Extracting applications_for_wiki output..."
|
||||
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
|
||||
cp terraform-raw-output.json terraform-output.json
|
||||
fi
|
||||
# Process output to extract clean JSON
|
||||
echo "📤 Processing Terraform output..."
|
||||
python3 ../../.gitea/scripts/process-terraform-output.py terraform-raw-output.json terraform-output.json
|
||||
|
||||
# Validate JSON and extract value
|
||||
echo "🔍 Validating and extracting JSON..."
|
||||
if python3 -c "import json; f=open('terraform-output.json'); data=json.load(f); f.close(); print('✅ Valid JSON')" 2>/dev/null; then
|
||||
# Extract just the value field using Python (more reliable than jq)
|
||||
cat > extract_value.py << 'EOF'
|
||||
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)
|
||||
EOF
|
||||
python3 extract_value.py
|
||||
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
|
||||
cat > fix_json.py << 'EOF'
|
||||
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}')
|
||||
EOF
|
||||
python3 fix_json.py
|
||||
fi
|
||||
|
||||
# Debug output
|
||||
echo "📄 Output file size: $(wc -c < terraform-output.json) bytes"
|
||||
echo "🔍 Content preview:"
|
||||
head -c 500 terraform-output.json
|
||||
echo ""
|
||||
|
||||
# Run wiki generation with debug if first attempt fails
|
||||
# Run wiki generation
|
||||
echo "📊 Running wiki generation script..."
|
||||
if ! python3 ../../.gitea/scripts/generate-apps-wiki.py terraform-output.json; then
|
||||
echo "⚠️ First attempt failed, retrying with debug..."
|
||||
if python3 ../../.gitea/scripts/generate-apps-wiki.py terraform-output.json; then
|
||||
echo "✅ Wiki content generated successfully"
|
||||
else
|
||||
echo "⚠️ Wiki generation failed, retrying with debug..."
|
||||
python3 ../../.gitea/scripts/generate-apps-wiki.py terraform-output.json --debug || echo "⚠️ Wiki generation failed"
|
||||
fi
|
||||
|
||||
# Check if wiki file was created
|
||||
# Check results
|
||||
if [ -f "Applications.md" ]; then
|
||||
echo "✅ Wiki content generated successfully"
|
||||
echo "✅ Wiki file created: $(wc -l < Applications.md) lines"
|
||||
else
|
||||
echo "⚠️ Wiki content not generated"
|
||||
exit 0
|
||||
|
Reference in New Issue
Block a user