157 lines
5.0 KiB
YAML
157 lines
5.0 KiB
YAML
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
|
||
|
||
Generated by CI/CD workflow on $(date +%Y-%m-%d\ %H:%M:%S)
|
||
|
||
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"
|
||
PR_BODY="This PR automatically updates README.md based on the current k8s/ directory structure.
|
||
|
||
## Changes
|
||
- Updated application list in README.md
|
||
- Applications are now synced with k8s/ folders
|
||
|
||
## Review
|
||
Please review and merge if everything looks correct.
|
||
|
||
---
|
||
🤖 This PR was automatically generated by CI/CD workflow
|
||
⏰ Generated at: $(date +%Y-%m-%d\ %H:%M:%S)"
|
||
|
||
# Create PR via API
|
||
RESPONSE=$(curl -s -X POST \
|
||
-H "Authorization: token $GITEA_TOKEN" \
|
||
-H "Content-Type: application/json" \
|
||
-d "{
|
||
\"title\": \"$PR_TITLE\",
|
||
\"body\": \"$PR_BODY\",
|
||
\"head\": \"$BRANCH_NAME\",
|
||
\"base\": \"main\"
|
||
}" \
|
||
"$GITEA_URL/api/v1/repos/$GITEA_OWNER/$GITEA_REPO/pulls")
|
||
|
||
# Extract PR number and URL from response
|
||
PR_NUMBER=$(echo "$RESPONSE" | grep -o '"number":[0-9]*' | head -1 | cut -d':' -f2)
|
||
|
||
if [ -n "$PR_NUMBER" ]; 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"
|
||
echo "Response: $RESPONSE"
|
||
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
|