Merge pull request #2 from prepguides/docs/development-workflow #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PR Automation | ||
|
Check failure on line 1 in .github/workflows/pr-automation.yml
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, review_requested] | ||
| pull_request_review: | ||
| types: [submitted] | ||
| issue_comment: | ||
| types: [created] | ||
| jobs: | ||
| # Job 1: Check PR requirements | ||
| pr-checks: | ||
| if: github.event_name == 'pull_request' | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| ready-to-merge: ${{ steps.check.outputs.ready }} | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Check PR requirements | ||
| id: check | ||
| run: | | ||
| # Check if PR has required labels | ||
| LABELS="${{ join(github.event.pull_request.labels.*.name, ' ') }" | ||
| echo "PR Labels: $LABELS" | ||
| # Check if PR is not a draft | ||
| if [ "${{ github.event.pull_request.draft }}" == "true" ]; then | ||
| echo "❌ PR is still in draft mode" | ||
| echo "ready=false" >> $GITHUB_OUTPUT | ||
| exit 0 | ||
| fi | ||
| # Check if PR has description | ||
| if [ -z "${{ github.event.pull_request.body }}" ]; then | ||
| echo "❌ PR missing description" | ||
| echo "ready=false" >> $GITHUB_OUTPUT | ||
| exit 0 | ||
| fi | ||
| # Check if PR is from feature/fix/docs branch | ||
| BRANCH="${{ github.head_ref }}" | ||
| if [[ $BRANCH == feature/* ]] || [[ $BRANCH == fix/* ]] || [[ $BRANCH == docs/* ]] || [[ $BRANCH == improve/* ]]; then | ||
| echo "✅ PR branch follows naming convention: $BRANCH" | ||
| echo "ready=true" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "❌ PR branch doesn't follow naming convention: $BRANCH" | ||
| echo "ready=false" >> $GITHUB_OUTPUT | ||
| fi | ||
| - name: Comment PR status | ||
| if: steps.check.outputs.ready == 'false' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| github.rest.issues.createComment({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: `🤖 **PR Requirements Check** | ||
| ❌ This PR is not ready for auto-merge: | ||
| **Requirements:** | ||
| - [ ] PR must not be in draft mode | ||
| - [ ] PR must have a description | ||
| - [ ] Branch must follow naming convention: \`feature/*\`, \`fix/*\`, \`docs/*\`, or \`improve/*\` | ||
| **Current Status:** | ||
| - Draft: ${{ github.event.pull_request.draft }} | ||
| - Description: ${{ github.event.pull_request.body != '' }} | ||
| - Branch: \`${{ github.head_ref }}\` | ||
| Please update the PR to meet all requirements for auto-merge.` | ||
| }) | ||
| # Job 2: Auto-merge on approval (including self-approval) | ||
| auto-merge: | ||
| if: | | ||
| github.event_name == 'pull_request_review' && | ||
| github.event.review.state == 'approved' && | ||
| needs.pr-checks.outputs.ready-to-merge == 'true' | ||
| needs: pr-checks | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| fetch-depth: 0 | ||
| - name: Wait for status checks | ||
| uses: lewagon/wait-on-check-action@v1.3.1 | ||
| with: | ||
| ref: ${{ github.event.pull_request.head.sha }} | ||
| check-name: 'PR Automation' | ||
| repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
| wait-interval: 10 | ||
| - name: Auto merge PR | ||
| uses: fastify/github-action-merge-dependabot@v3 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| target: main | ||
| merge-method: merge | ||
| delete-branch: true | ||
| merge-commit-message: | | ||
| Auto-merge: ${{ github.event.pull_request.title }} | ||
| Approved by: ${{ github.event.review.user.login }} | ||
| PR: #${{ github.event.pull_request.number }} | ||
| ${{ github.event.pull_request.body }} | ||
| - name: Success notification | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| github.rest.issues.createComment({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: `🚀 **Auto-merged Successfully!** | ||
| This PR has been automatically merged to main after receiving approval from @${{ github.event.review.user.login }}. | ||
| ✅ **Status**: Merged and deployed | ||
| 🔗 **Commit**: \`${{ github.sha }}\` | ||
| 📅 **Merged at**: ${new Date().toISOString()} | ||
| 🌿 **Branch**: \`${{ github.head_ref }}\` (deleted) | ||
| **What happens next:** | ||
| - Changes are automatically deployed to Vercel | ||
| - New algorithm/feature is now live | ||
| - Ready for the next development cycle | ||
| Thank you for your contribution! 🎉` | ||
| }) | ||
| # Job 3: Self-approval via comment | ||
| self-approval: | ||
| if: | | ||
| github.event_name == 'issue_comment' && | ||
| github.event.issue.pull_request && | ||
| contains(github.event.comment.body, '/approve') && | ||
| github.event.comment.user.login == github.event.issue.user.login | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| fetch-depth: 0 | ||
| - name: Check PR requirements for self-approval | ||
| id: check-self | ||
| run: | | ||
| # Get PR details | ||
| PR_NUMBER="${{ github.event.issue.number }}" | ||
| BRANCH="${{ github.head_ref }}" | ||
| # Check if PR follows naming convention | ||
| if [[ $BRANCH == feature/* ]] || [[ $BRANCH == fix/* ]] || [[ $BRANCH == docs/* ]] || [[ $BRANCH == improve/* ]]; then | ||
| echo "✅ PR branch follows naming convention: $BRANCH" | ||
| echo "ready=true" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "❌ PR branch doesn't follow naming convention: $BRANCH" | ||
| echo "ready=false" >> $GITHUB_OUTPUT | ||
| fi | ||
| - name: Self-approve and merge | ||
| if: steps.check-self.outputs.ready == 'true' | ||
| uses: fastify/github-action-merge-dependabot@v3 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| target: main | ||
| merge-method: merge | ||
| delete-branch: true | ||
| merge-commit-message: | | ||
| Self-approved merge: ${{ github.event.issue.title }} | ||
| Approved by: ${{ github.event.comment.user.login }} (author) | ||
| PR: #${{ github.event.issue.number }} | ||
| ${{ github.event.issue.body }} | ||
| - name: Self-approval success notification | ||
| if: steps.check-self.outputs.ready == 'true' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| github.rest.issues.createComment({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: `🚀 **Self-Approved and Auto-Merged!** | ||
| This PR has been automatically merged to main after self-approval by @${{ github.event.comment.user.login }}. | ||
| ✅ **Status**: Merged and deployed | ||
| 🔗 **Commit**: \`${{ github.sha }}\` | ||
| 📅 **Merged at**: ${new Date().toISOString()} | ||
| 🌿 **Branch**: \`${{ github.head_ref }}\` (deleted) | ||
| **What happens next:** | ||
| - Changes are automatically deployed to Vercel | ||
| - New algorithm/feature is now live | ||
| - Ready for the next development cycle | ||
| Thank you for your contribution! 🎉` | ||
| }) | ||
| - name: Self-approval rejection notification | ||
| if: steps.check-self.outputs.ready == 'false' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| github.rest.issues.createComment({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: `❌ **Self-Approval Rejected** | ||
| This PR cannot be self-approved because it doesn't meet the requirements: | ||
| **Requirements:** | ||
| - [ ] Branch must follow naming convention: \`feature/*\`, \`fix/*\`, \`docs/*\`, or \`improve/*\` | ||
| **Current Status:** | ||
| - Branch: \`${{ github.head_ref }}\` | ||
| Please ensure your PR meets all requirements before self-approving.` | ||
| }) | ||
| # Job 4: Deployment notification | ||
| notify-deployment: | ||
| if: github.event_name == 'pull_request_review' && github.event.review.state == 'approved' | ||
| needs: [pr-checks, auto-merge] | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Deployment notification | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| // Wait a moment for Vercel deployment to start | ||
| await new Promise(resolve => setTimeout(resolve, 5000)); | ||
| github.rest.issues.createComment({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: `🚀 **Deployment Status** | ||
| Your changes are being deployed to Vercel: | ||
| **Live URLs:** | ||
| - Main site: https://prepguides.dev | ||
| - Algorithm pages: https://prepguides.dev/algorithms.html | ||
| **Deployment typically takes 1-2 minutes.** | ||
| You can monitor the deployment status in your Vercel dashboard.` | ||
| }) | ||