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 <> $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