|
| 1 | +name: Pull Request Automation |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: [ opened, edited, synchronize, reopened, ready_for_review, labeled, unlabeled ] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + issues: write |
| 10 | + pull-requests: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + assign-author: |
| 14 | + if: github.event.action == 'opened' || github.event.action == 'ready_for_review' |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Assign PR author |
| 19 | + uses: kentaro-m/auto-assign-action@v2.0.0 |
| 20 | + with: |
| 21 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + configuration-path: .github/config/auto-assign.yml |
| 23 | + |
| 24 | + title-check: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Check PR title |
| 29 | + uses: thehanimo/pr-title-checker@v1.4.3 |
| 30 | + with: |
| 31 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 32 | + pass_on_octokit_error: false |
| 33 | + configuration_path: .github/config/pr-title-checker.json |
| 34 | + |
| 35 | + labeler: |
| 36 | + runs-on: ubuntu-latest |
| 37 | + |
| 38 | + steps: |
| 39 | + - name: Label changed files |
| 40 | + uses: actions/labeler@v6 |
| 41 | + with: |
| 42 | + configuration-path: .github/config/labeler.yml |
| 43 | + sync-labels: true |
| 44 | + |
| 45 | + performance-labeler: |
| 46 | + runs-on: ubuntu-latest |
| 47 | + |
| 48 | + steps: |
| 49 | + - name: Apply Performance label from issues or PR text |
| 50 | + uses: actions/github-script@v7 |
| 51 | + with: |
| 52 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + script: | |
| 54 | + const { owner, repo } = context.repo; |
| 55 | + const pr = context.payload.pull_request; |
| 56 | + const text = `${pr.title}\n${pr.body || ''}`.toLowerCase(); |
| 57 | + const keywordMatch = /(perf|performance|benchmark|optimiz|allocation|memory pressure|throughput|latency)/i.test(text); |
| 58 | + const issueNumbers = new Set(); |
| 59 | +
|
| 60 | + for (const match of text.matchAll(/(?:closes|fixes|related to)\s+#(\d+)/gi)) { |
| 61 | + issueNumbers.add(Number(match[1])); |
| 62 | + } |
| 63 | +
|
| 64 | + for (const match of text.matchAll(/#(\d+)/g)) { |
| 65 | + issueNumbers.add(Number(match[1])); |
| 66 | + } |
| 67 | +
|
| 68 | + let issueMatch = false; |
| 69 | +
|
| 70 | + for (const number of issueNumbers) { |
| 71 | + const issue = await github.rest.issues.get({ owner, repo, issue_number: number }); |
| 72 | + const labels = issue.data.labels.map(label => label.name); |
| 73 | +
|
| 74 | + if (labels.includes('performance')) { |
| 75 | + issueMatch = true; |
| 76 | + break; |
| 77 | + } |
| 78 | + } |
| 79 | +
|
| 80 | + if (!keywordMatch && !issueMatch) { |
| 81 | + core.info('Performance label not applicable for this PR.'); |
| 82 | + return; |
| 83 | + } |
| 84 | +
|
| 85 | + const currentLabels = pr.labels.map(label => label.name); |
| 86 | + if (currentLabels.includes('performance')) { |
| 87 | + core.info('Performance label already present.'); |
| 88 | + return; |
| 89 | + } |
| 90 | +
|
| 91 | + await github.rest.issues.addLabels({ |
| 92 | + owner, |
| 93 | + repo, |
| 94 | + issue_number: pr.number, |
| 95 | + labels: ['performance'] |
| 96 | + }); |
| 97 | + core.info('Performance label added.'); |
0 commit comments