name: 'Update Authentik Applications Wiki' on: push: branches: [ "main" ] # paths: # - 'terraform/authentik/**' workflow_dispatch: permissions: contents: read jobs: update-wiki: name: 'Generate and Update Wiki' runs-on: ubuntu-latest environment: production defaults: run: shell: bash working-directory: ./terraform/authentik steps: - name: Checkout uses: actions/checkout@v3 - name: Setup Terraform uses: hashicorp/setup-terraform@v2 with: cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} - name: Terraform Init run: terraform init - name: Generate Terraform Output run: | echo "🔍 Generating Terraform output..." # Use terraform-bin directly to avoid wrapper output terraform output -json applications_for_wiki > terraform-output-raw.json # Extract just the value field jq '.value' terraform-output-raw.json > terraform-output.json # Debug output file echo "📄 Output file size: $(wc -c < terraform-output.json) bytes" echo "🔍 First 200 chars of output:" head -c 200 terraform-output.json echo "" echo "✅ Terraform output generated" - name: Generate Wiki Content run: | echo "🔍 Checking output file..." if [ ! -f "terraform-output.json" ]; then echo "❌ terraform-output.json not found" exit 1 fi echo "📊 Running wiki generation script..." python3 ../../.gitea/scripts/generate-apps-wiki.py terraform-output.json echo "✅ Wiki content generated" - name: Upload Wiki to Gitea run: | # Set variables GITEA_URL="${{ secrets.GT_WIKI_URL }}" GITEA_TOKEN="${{ secrets.GT_WIKI_TOKEN }}" GITEA_OWNER="${{ secrets.GT_WIKI_OWNER }}" GITEA_REPO="${{ secrets.GT_WIKI_REPO }}" # Check if file was created if [ ! -f "Applications.md" ]; then echo "❌ Applications.md not found" exit 1 fi echo "📤 Uploading to Gitea Wiki..." # Encode content to base64 CONTENT=$(base64 -w 0 Applications.md) # Check if wiki page exists WIKI_PAGE_EXISTS=$(curl -s -o /dev/null -w "%{http_code}" \ -H "Authorization: token $GITEA_TOKEN" \ "$GITEA_URL/api/v1/repos/$GITEA_OWNER/$GITEA_REPO/wiki/page/Applications") if [ "$WIKI_PAGE_EXISTS" = "200" ]; then echo "📝 Updating existing wiki page..." # Update existing page curl -X PATCH \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ -d "{ \"title\": \"Applications\", \"content_base64\": \"$CONTENT\", \"message\": \"Update applications list from CI/CD [$(date)]\" }" \ "$GITEA_URL/api/v1/repos/$GITEA_OWNER/$GITEA_REPO/wiki/page/Applications" else echo "📄 Creating new wiki page..." # Create new page curl -X POST \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ -d "{ \"title\": \"Applications\", \"content_base64\": \"$CONTENT\", \"message\": \"Create applications list from CI/CD [$(date)]\" }" \ "$GITEA_URL/api/v1/repos/$GITEA_OWNER/$GITEA_REPO/wiki/new" fi echo "✅ Wiki updated successfully!" echo "🔗 Wiki URL: $GITEA_URL/$GITEA_OWNER/$GITEA_REPO/wiki/Applications" - name: Summary run: | echo "## 📊 Wiki Update Summary" >> $GITHUB_STEP_SUMMARY echo "- ✅ Terraform output extracted" >> $GITHUB_STEP_SUMMARY echo "- ✅ Applications table generated" >> $GITHUB_STEP_SUMMARY echo "- ✅ Wiki page updated in Gitea" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "**Applications count:** $(grep -c '|.*|.*|.*|.*|.*|' Applications.md || echo 0)" >> $GITHUB_STEP_SUMMARY echo "**Generated at:** $(date)" >> $GITHUB_STEP_SUMMARY