Files
homelab/.gitea/workflows/update-readme.yaml
AB 860f83445a
All checks were successful
Update Kubernetes Services Wiki / Generate and Update K8s Wiki (push) Successful in 11s
Readme CI
2025-11-07 15:34:22 +02:00

165 lines
5.8 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: 'Auto-update README'
on:
push:
branches: [ "main" ]
paths:
- 'k8s/**'
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
update-readme:
name: 'Generate README and Create MR'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Configure Git
run: |
git config --global user.name "Gitea Actions Bot"
git config --global user.email "actions@gitea.local"
- name: Generate README
run: |
echo "📋 Starting README generation..."
python3 .gitea/scripts/generate-readme.py k8s/ README.md
if [ -f "README.md" ]; then
echo "✅ README generated successfully"
echo "📄 File size: $(wc -c < README.md) bytes"
echo "📄 Lines: $(wc -l < README.md)"
else
echo "❌ README not generated"
exit 1
fi
- name: Check for changes
id: check_changes
run: |
if git diff --quiet README.md; then
echo "No changes detected in README.md"
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "Changes detected in README.md"
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
- name: Create Pull Request
if: steps.check_changes.outputs.has_changes == 'true'
run: |
# Set variables
GITEA_URL="${{ secrets.GT_URL }}"
GITEA_TOKEN="${{ secrets.GT_TOKEN }}"
GITEA_OWNER="${{ secrets.GT_OWNER }}"
GITEA_REPO="${{ secrets.GT_REPO }}"
BRANCH_NAME="auto-update-readme-$(date +%Y%m%d-%H%M%S)"
echo "🔍 Configuration:"
echo "GITEA_URL: ${GITEA_URL:-NOT SET}"
echo "GITEA_OWNER: ${GITEA_OWNER:-NOT SET}"
echo "GITEA_REPO: ${GITEA_REPO:-NOT SET}"
echo "BRANCH_NAME: $BRANCH_NAME"
# Create and push new branch
echo "🌿 Creating branch: $BRANCH_NAME"
git checkout -b "$BRANCH_NAME"
git add README.md
git commit -m "Auto-update README with current k8s applications" \
-m "Generated by CI/CD workflow on $(date +%Y-%m-%d\ %H:%M:%S)" \
-m "This PR updates the README.md file with the current list of applications found in the k8s/ directory structure."
# Push branch to remote
echo "📤 Pushing branch to remote..."
git push origin "$BRANCH_NAME"
# Create Pull Request using Gitea API
echo "🔀 Creating Pull Request..."
PR_TITLE="Auto-update README with k8s applications"
# Create PR body
cat > /tmp/pr_body.json <<EOF
{
"title": "$PR_TITLE",
"body": "This PR automatically updates README.md based on the current k8s/ directory structure.\n\n## Changes\n- Updated application list in README.md\n- Applications are now synced with k8s/ folders\n\n## Review\nPlease review and merge if everything looks correct.\n\n---\n🤖 This PR was automatically generated by CI/CD workflow\n⏰ Generated at: $(date '+%Y-%m-%d %H:%M:%S')",
"head": "$BRANCH_NAME",
"base": "main"
}
EOF
# Create PR via API
echo "Making API request to: $GITEA_URL/api/v1/repos/$GITEA_OWNER/$GITEA_REPO/pulls"
echo "Request body:"
cat /tmp/pr_body.json
RESPONSE=$(curl -s -w "\nHTTP_CODE:%{http_code}" -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d @/tmp/pr_body.json \
"$GITEA_URL/api/v1/repos/$GITEA_OWNER/$GITEA_REPO/pulls")
# Extract HTTP code and response body
HTTP_CODE=$(echo "$RESPONSE" | grep "HTTP_CODE:" | cut -d':' -f2)
RESPONSE_BODY=$(echo "$RESPONSE" | sed '/HTTP_CODE:/d')
echo "API Response (HTTP $HTTP_CODE):"
echo "$RESPONSE_BODY"
# Extract PR number and URL from response
PR_NUMBER=$(echo "$RESPONSE_BODY" | grep -o '"number":[0-9]*' | head -1 | cut -d':' -f2)
if [ -n "$PR_NUMBER" ] && [ "$HTTP_CODE" = "201" ]; then
echo "✅ Pull Request created successfully!"
echo "📝 PR #$PR_NUMBER"
echo "🔗 URL: $GITEA_URL/$GITEA_OWNER/$GITEA_REPO/pulls/$PR_NUMBER"
# Save PR info for summary
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
echo "pr_url=$GITEA_URL/$GITEA_OWNER/$GITEA_REPO/pulls/$PR_NUMBER" >> $GITHUB_OUTPUT
else
echo "⚠️ Failed to create Pull Request (HTTP $HTTP_CODE)"
echo "Response: $RESPONSE_BODY"
# Check if PR already exists
if echo "$RESPONSE_BODY" | grep -q "already exists"; then
echo " PR already exists for this branch"
exit 0
fi
exit 1
fi
- name: Summary
if: always()
run: |
echo "## 📊 README Update Summary" >> $GITHUB_STEP_SUMMARY
if [ -f "README.md" ]; then
echo "- ✅ README generated successfully" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.check_changes.outputs.has_changes }}" = "true" ]; then
echo "- ✅ Changes detected" >> $GITHUB_STEP_SUMMARY
echo "- ✅ Pull Request created" >> $GITHUB_STEP_SUMMARY
if [ -n "${{ steps.create_pr.outputs.pr_number }}" ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "**PR:** [#${{ steps.create_pr.outputs.pr_number }}](${{ steps.create_pr.outputs.pr_url }})" >> $GITHUB_STEP_SUMMARY
fi
else
echo "- No changes detected - README already up to date" >> $GITHUB_STEP_SUMMARY
fi
else
echo "- ❌ README generation failed" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Generated at:** $(date)" >> $GITHUB_STEP_SUMMARY