|
| 1 | +name: PR Quality Check |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + |
| 7 | +jobs: |
| 8 | + pr-quality: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + |
| 11 | + steps: |
| 12 | + - name: Checkout code |
| 13 | + uses: actions/checkout@v4 |
| 14 | + with: |
| 15 | + fetch-depth: 0 |
| 16 | + |
| 17 | + - name: Setup Node.js |
| 18 | + uses: actions/setup-node@v4 |
| 19 | + with: |
| 20 | + node-version: "20.x" |
| 21 | + cache: "npm" |
| 22 | + |
| 23 | + - name: Install dependencies |
| 24 | + run: npm ci |
| 25 | + |
| 26 | + - name: Check PR title format |
| 27 | + run: | |
| 28 | + PR_TITLE="${{ github.event.pull_request.title }}" |
| 29 | + if [[ ! "$PR_TITLE" =~ ^(feat|fix|docs|style|refactor|test|chore|perf|ci)(\(.+\))?: .+ ]]; then |
| 30 | + echo "::error::PR title must follow conventional commits format: type(scope): description" |
| 31 | + exit 1 |
| 32 | + fi |
| 33 | + |
| 34 | + - name: Check for large files |
| 35 | + run: | |
| 36 | + find . -type f -size +1M -not -path "./node_modules/*" -not -path "./.git/*" | while read file; do |
| 37 | + echo "::warning::Large file detected: $file ($(du -h "$file" | cut -f1))" |
| 38 | + done |
| 39 | + |
| 40 | + - name: Lint commit messages |
| 41 | + run: | |
| 42 | + if git rev-parse --verify HEAD~1 >/dev/null 2>&1; then |
| 43 | + git log --oneline HEAD~1..HEAD | while read line; do |
| 44 | + if [[ ! "$line" =~ ^[a-f0-9]+\ (feat|fix|docs|style|refactor|test|chore|perf|ci)(\(.+\))?: ]]; then |
| 45 | + echo "::warning::Commit message should follow conventional commits: $line" |
| 46 | + fi |
| 47 | + done |
| 48 | + fi |
| 49 | + |
| 50 | + - name: Check code coverage impact |
| 51 | + run: | |
| 52 | + npm run test:coverage |
| 53 | + echo "Coverage report generated - review coverage/lcov-report/index.html" |
| 54 | + |
| 55 | + - name: Comment PR with coverage |
| 56 | + uses: actions/github-script@v6 |
| 57 | + with: |
| 58 | + script: | |
| 59 | + const fs = require("fs"); |
| 60 | + if (fs.existsSync("coverage/coverage-summary.json")) { |
| 61 | + const coverage = JSON.parse(fs.readFileSync("coverage/coverage-summary.json")); |
| 62 | + const total = coverage.total; |
| 63 | + |
| 64 | + const comment = `## Test Coverage Report |
| 65 | + |
| 66 | + | Metric | Percentage | Covered/Total | |
| 67 | + |--------|------------|---------------| |
| 68 | + | Lines | ${total.lines.pct}% | ${total.lines.covered}/${total.lines.total} | |
| 69 | + | Functions | ${total.functions.pct}% | ${total.functions.covered}/${total.functions.total} | |
| 70 | + | Branches | ${total.branches.pct}% | ${total.branches.covered}/${total.branches.total} | |
| 71 | + | Statements | ${total.statements.pct}% | ${total.statements.covered}/${total.statements.total} | |
| 72 | + |
| 73 | + Coverage thresholds: 70% minimum for all metrics.`; |
| 74 | + |
| 75 | + github.rest.issues.createComment({ |
| 76 | + issue_number: context.issue.number, |
| 77 | + owner: context.repo.owner, |
| 78 | + repo: context.repo.repo, |
| 79 | + body: comment |
| 80 | + }); |
| 81 | + } |
| 82 | +
|
0 commit comments