From eb3b5183b03a35181f954a7adb9d6f965288766f Mon Sep 17 00:00:00 2001 From: "AB from home.homenet" Date: Tue, 16 Sep 2025 16:11:28 +0300 Subject: [PATCH] Added wiki generator --- .gitea/workflows/authentik-apps.yaml | 80 ++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 11 deletions(-) diff --git a/.gitea/workflows/authentik-apps.yaml b/.gitea/workflows/authentik-apps.yaml index 9460435..e218032 100644 --- a/.gitea/workflows/authentik-apps.yaml +++ b/.gitea/workflows/authentik-apps.yaml @@ -50,20 +50,78 @@ jobs: # Generate terraform output echo "🔍 Generating Terraform output..." - # Method 1: Try to get clean JSON output - if terraform output -json > terraform-output.json 2>/dev/null; then - echo "✅ Direct JSON output successful" + # 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 - echo "⚠️ Direct JSON failed, trying alternative method..." - # Method 2: Get specific output - terraform output -json applications_for_wiki > terraform-output.json 2>&1 + cp terraform-raw-output.json terraform-output.json fi - # Clean up the output if needed - if grep -q '^\[command\]' terraform-output.json; then - echo "⚠️ Detected command prefix in output, cleaning..." - tail -n +2 terraform-output.json > terraform-output-clean.json - mv terraform-output-clean.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) + 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 # Debug output