|
| 1 | +name: PR Validation |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + |
| 7 | +jobs: |
| 8 | + validate-contribution: |
| 9 | + name: Validate Contribution |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout PR |
| 14 | + uses: actions/checkout@v4 |
| 15 | + with: |
| 16 | + fetch-depth: 0 |
| 17 | + |
| 18 | + - name: Setup Node.js |
| 19 | + uses: actions/setup-node@v4 |
| 20 | + with: |
| 21 | + node-version: '22' |
| 22 | + cache: 'npm' |
| 23 | + |
| 24 | + - name: Install Dependencies |
| 25 | + run: npm ci |
| 26 | + |
| 27 | + - name: TypeScript Check |
| 28 | + run: npm run typecheck |
| 29 | + |
| 30 | + - name: ESLint Check |
| 31 | + run: npm run lint |
| 32 | + |
| 33 | + - name: Run Tests |
| 34 | + run: npm test |
| 35 | + |
| 36 | + - name: Check for Conflicts |
| 37 | + run: | |
| 38 | + # Check if PR has conflicts with other open PRs |
| 39 | + gh pr list --state open --json number,files -q '.[] | select(.number != ${{ github.event.pull_request.number }})' > other_prs.json |
| 40 | +
|
| 41 | + # Get files changed in this PR |
| 42 | + gh pr view ${{ github.event.pull_request.number }} --json files -q '.files[].path' > this_pr_files.txt |
| 43 | +
|
| 44 | + # Check for overlapping files |
| 45 | + node -e " |
| 46 | + const fs = require('fs'); |
| 47 | + const otherPRs = JSON.parse(fs.readFileSync('other_prs.json', 'utf8') || '[]'); |
| 48 | + const thisPRFiles = fs.readFileSync('this_pr_files.txt', 'utf8').split('\n').filter(Boolean); |
| 49 | +
|
| 50 | + const conflicts = []; |
| 51 | + for (const pr of otherPRs) { |
| 52 | + const prFiles = (pr.files || []).map(f => f.path); |
| 53 | + const overlapping = thisPRFiles.filter(f => prFiles.includes(f)); |
| 54 | + if (overlapping.length > 0) { |
| 55 | + conflicts.push({ pr: pr.number, files: overlapping }); |
| 56 | + } |
| 57 | + } |
| 58 | +
|
| 59 | + if (conflicts.length > 0) { |
| 60 | + console.log('⚠️ Potential conflicts detected:'); |
| 61 | + conflicts.forEach(c => { |
| 62 | + console.log(\` PR #\${c.pr}: \${c.files.join(', ')}\`); |
| 63 | + }); |
| 64 | + process.exit(1); |
| 65 | + } |
| 66 | + " |
| 67 | + env: |
| 68 | + GH_TOKEN: ${{ github.token }} |
| 69 | + continue-on-error: true |
| 70 | + |
| 71 | + - name: Check Architecture Compliance |
| 72 | + run: | |
| 73 | + # Check for platform-specific imports in core modules |
| 74 | + echo "Checking for platform-specific imports..." |
| 75 | +
|
| 76 | + # Look for direct platform imports in src/core |
| 77 | + if grep -r "from 'grammy'" src/core/ 2>/dev/null || \ |
| 78 | + grep -r "from 'discord.js'" src/core/ 2>/dev/null || \ |
| 79 | + grep -r "from '@slack/'" src/core/ 2>/dev/null; then |
| 80 | + echo "❌ Found platform-specific imports in core modules!" |
| 81 | + echo "Please use connector pattern instead." |
| 82 | + exit 1 |
| 83 | + fi |
| 84 | +
|
| 85 | + echo "✅ No platform-specific imports in core modules" |
| 86 | +
|
| 87 | + - name: Check for Any Types |
| 88 | + run: | |
| 89 | + # Check for 'any' types in TypeScript files |
| 90 | + echo "Checking for 'any' types..." |
| 91 | +
|
| 92 | + # Exclude test files and node_modules |
| 93 | + if grep -r ": any" src/ --include="*.ts" --include="*.tsx" \ |
| 94 | + --exclude-dir="__tests__" --exclude-dir="node_modules" | \ |
| 95 | + grep -v "eslint-disable" | \ |
| 96 | + grep -v "@typescript-eslint/no-explicit-any"; then |
| 97 | + echo "❌ Found 'any' types without proper justification!" |
| 98 | + echo "Please use proper types or add eslint-disable with explanation." |
| 99 | + exit 1 |
| 100 | + fi |
| 101 | +
|
| 102 | + echo "✅ No unjustified 'any' types found" |
| 103 | +
|
| 104 | + - name: Generate Contribution Report |
| 105 | + if: always() |
| 106 | + run: | |
| 107 | + echo "## 📊 Contribution Analysis" >> $GITHUB_STEP_SUMMARY |
| 108 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 109 | +
|
| 110 | + # Count changes |
| 111 | + ADDED=$(git diff --numstat origin/main..HEAD | awk '{sum+=$1} END {print sum}') |
| 112 | + DELETED=$(git diff --numstat origin/main..HEAD | awk '{sum+=$2} END {print sum}') |
| 113 | + FILES_CHANGED=$(git diff --name-only origin/main..HEAD | wc -l) |
| 114 | +
|
| 115 | + echo "### Changes Summary" >> $GITHUB_STEP_SUMMARY |
| 116 | + echo "- Files changed: $FILES_CHANGED" >> $GITHUB_STEP_SUMMARY |
| 117 | + echo "- Lines added: $ADDED" >> $GITHUB_STEP_SUMMARY |
| 118 | + echo "- Lines deleted: $DELETED" >> $GITHUB_STEP_SUMMARY |
| 119 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 120 | +
|
| 121 | + # Detect contribution type |
| 122 | + if git log --oneline origin/main..HEAD | grep -i "perf:"; then |
| 123 | + echo "🚀 **Type**: Performance Optimization" >> $GITHUB_STEP_SUMMARY |
| 124 | + elif git log --oneline origin/main..HEAD | grep -i "fix:"; then |
| 125 | + echo "🐛 **Type**: Bug Fix" >> $GITHUB_STEP_SUMMARY |
| 126 | + elif git log --oneline origin/main..HEAD | grep -i "feat:"; then |
| 127 | + echo "✨ **Type**: New Feature" >> $GITHUB_STEP_SUMMARY |
| 128 | + else |
| 129 | + echo "📝 **Type**: Other" >> $GITHUB_STEP_SUMMARY |
| 130 | + fi |
| 131 | +
|
| 132 | + - name: Comment on PR |
| 133 | + if: failure() |
| 134 | + uses: actions/github-script@v7 |
| 135 | + with: |
| 136 | + script: | |
| 137 | + const message = `## ❌ Validation Failed |
| 138 | +
|
| 139 | + Please check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details. |
| 140 | +
|
| 141 | + Common issues: |
| 142 | + - TypeScript errors or warnings |
| 143 | + - ESLint violations |
| 144 | + - Failing tests |
| 145 | + - Platform-specific imports in core modules |
| 146 | + - Unjustified \`any\` types |
| 147 | +
|
| 148 | + Need help? Check our [Contributing Guide](https://github.com/${{ github.repository }}/blob/main/CONTRIBUTING.md).`; |
| 149 | +
|
| 150 | + github.rest.issues.createComment({ |
| 151 | + issue_number: context.issue.number, |
| 152 | + owner: context.repo.owner, |
| 153 | + repo: context.repo.repo, |
| 154 | + body: message |
| 155 | + }); |
| 156 | +
|
| 157 | + label-pr: |
| 158 | + name: Auto-label PR |
| 159 | + runs-on: ubuntu-latest |
| 160 | + if: success() |
| 161 | + |
| 162 | + steps: |
| 163 | + - name: Label based on files |
| 164 | + uses: actions/labeler@v5 |
| 165 | + with: |
| 166 | + repo-token: '${{ secrets.GITHUB_TOKEN }}' |
| 167 | + configuration-path: .github/labeler.yml |
| 168 | + |
| 169 | + - name: Label based on title |
| 170 | + uses: actions/github-script@v7 |
| 171 | + with: |
| 172 | + script: | |
| 173 | + const title = context.payload.pull_request.title.toLowerCase(); |
| 174 | + const labels = []; |
| 175 | +
|
| 176 | + if (title.includes('perf:')) labels.push('performance'); |
| 177 | + if (title.includes('fix:')) labels.push('bug'); |
| 178 | + if (title.includes('feat:')) labels.push('enhancement'); |
| 179 | + if (title.includes('docs:')) labels.push('documentation'); |
| 180 | + if (title.includes('test:')) labels.push('testing'); |
| 181 | +
|
| 182 | + if (labels.length > 0) { |
| 183 | + await github.rest.issues.addLabels({ |
| 184 | + issue_number: context.issue.number, |
| 185 | + owner: context.repo.owner, |
| 186 | + repo: context.repo.repo, |
| 187 | + labels: labels |
| 188 | + }); |
| 189 | + } |
0 commit comments